-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from cockroachdb/spencerkimball/local-keyspace
Reorganized all local keys into two sections/range: by ID & by Key.
- Loading branch information
Showing
20 changed files
with
462 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
# Author: Andrew Bonventre ([email protected]) | ||
|
||
ROACH_LIB := libroach.a | ||
SOURCES := db.cc | ||
SOURCES := db.cc encoding.cc | ||
OBJECTS := $(SOURCES:.cc=.o) | ||
|
||
CXXFLAGS += -std=c++11 -I../proto/lib -I../_vendor/rocksdb/include | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2014 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. See the AUTHORS file | ||
// for names of contributors. | ||
// | ||
// Author: Spencer Kimball ([email protected]) | ||
|
||
#include "rocksdb/slice.h" | ||
|
||
namespace { | ||
|
||
const unsigned char kOrderedEncodingBinary = 0x25; | ||
const unsigned char kOrderedEncodingTerminator = 0x00; | ||
|
||
} | ||
|
||
bool DecodeBinary(const rocksdb::Slice& buf, std::string* decoded, std::string* remainder) { | ||
if (buf[0] != kOrderedEncodingBinary) { | ||
fprintf(stderr, "%s doesn't begin with binary encoding byte\n", buf.ToString().c_str()); | ||
return false; | ||
} | ||
decoded->clear(); | ||
int s = 6; | ||
int i = 1; | ||
if (buf[i] == kOrderedEncodingTerminator) { | ||
if (remainder != NULL) { | ||
rocksdb::Slice remSlice(buf); | ||
remSlice.remove_prefix(2); | ||
*remainder = remSlice.ToString(); | ||
} | ||
return true; | ||
} | ||
|
||
int t = (buf[i] << 1) & 0xff; | ||
for (i = 2; buf[i] != kOrderedEncodingTerminator; i++) { | ||
if (s == 7) { | ||
decoded->push_back(t | (buf[i] & 0x7f)); | ||
i++; | ||
} else { | ||
decoded->push_back(t | ((buf[i] & 0x7f) >> s)); | ||
} | ||
|
||
t = (buf[i] << (8 - s)) & 0xff; | ||
|
||
if (buf[i] == kOrderedEncodingTerminator) { | ||
break; | ||
} | ||
|
||
if (s == 1) { | ||
s = 7; | ||
} else { | ||
s--; | ||
} | ||
} | ||
if (t != 0) { | ||
fprintf(stderr, "%s doesn't begin with binary encoding byte\n", buf.ToString().c_str()); | ||
return false; | ||
} | ||
if (remainder != NULL) { | ||
rocksdb::Slice remSlice(buf); | ||
remSlice.remove_prefix(i+1); | ||
*remainder = remSlice.ToString(); | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2015 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. See the AUTHORS file | ||
// for names of contributors. | ||
// | ||
// Author: Spencer Kimball ([email protected]) | ||
|
||
#ifndef ROACHLIB_ENCODING_H | ||
#define ROACHLIB_ENCODING_H | ||
|
||
#include <stdint.h> | ||
|
||
// DecodeBinary decodes the given key-encoded buf slice, returning | ||
// true on a successful decode. The the unencoded bytes are returned | ||
// in *decoded, and if not NULL, any remaining bytes are returned in | ||
// *remainder. | ||
bool DecodeBinary(const rocksdb::Slice& buf, std::string* decoded, std::string* remainder); | ||
|
||
#endif // ROACHLIB_ENCODING_H | ||
|
||
// local variables: | ||
// mode: c++ | ||
// end: |
Oops, something went wrong.