Squashed 'src/leveldb/' changes from 9094c7f..7924331
42dcc7e Merge upstream LevelDB 1.17. e353fbc Release LevelDB 1.17 269fc6c Release LevelDB 1.16 REVERT: 9094c7f Temporarily revert to writing .sst files instead of .ldb git-subtree-dir: src/leveldb git-subtree-split: 79243314e40ac31d79c68e5658a1d6a64800d50b
This commit is contained in:
parent
060fdb41fc
commit
938b689846
9 changed files with 60 additions and 43 deletions
11
Makefile
11
Makefile
|
@ -72,7 +72,7 @@ SHARED = $(SHARED1)
|
||||||
else
|
else
|
||||||
# Update db.h if you change these.
|
# Update db.h if you change these.
|
||||||
SHARED_MAJOR = 1
|
SHARED_MAJOR = 1
|
||||||
SHARED_MINOR = 15
|
SHARED_MINOR = 17
|
||||||
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
|
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
|
||||||
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
|
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
|
||||||
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
|
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
|
||||||
|
@ -190,19 +190,20 @@ PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
|
||||||
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
|
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
|
||||||
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
|
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
|
||||||
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
|
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
|
||||||
|
IOSARCH=-arch armv6 -arch armv7 -arch armv7s -arch arm64
|
||||||
|
|
||||||
.cc.o:
|
.cc.o:
|
||||||
mkdir -p ios-x86/$(dir $@)
|
mkdir -p ios-x86/$(dir $@)
|
||||||
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
|
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
|
||||||
mkdir -p ios-arm/$(dir $@)
|
mkdir -p ios-arm/$(dir $@)
|
||||||
xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
|
xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
|
||||||
lipo ios-x86/$@ ios-arm/$@ -create -output $@
|
lipo ios-x86/$@ ios-arm/$@ -create -output $@
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
mkdir -p ios-x86/$(dir $@)
|
mkdir -p ios-x86/$(dir $@)
|
||||||
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
|
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
|
||||||
mkdir -p ios-arm/$(dir $@)
|
mkdir -p ios-arm/$(dir $@)
|
||||||
xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
|
xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
|
||||||
lipo ios-x86/$@ ios-arm/$@ -create -output $@
|
lipo ios-x86/$@ ios-arm/$@ -create -output $@
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,19 +29,14 @@ std::string LogFileName(const std::string& name, uint64_t number) {
|
||||||
return MakeFileName(name, number, "log");
|
return MakeFileName(name, number, "log");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableFileName returns the filenames we usually write to, while
|
|
||||||
// SSTTableFileName returns the alternative filenames we also try to read from
|
|
||||||
// for backward compatibility. For now, swap them around.
|
|
||||||
// TODO: when compatibility is no longer necessary, swap them back
|
|
||||||
// (TableFileName to use "ldb" and SSTTableFileName to use "sst").
|
|
||||||
std::string TableFileName(const std::string& name, uint64_t number) {
|
std::string TableFileName(const std::string& name, uint64_t number) {
|
||||||
assert(number > 0);
|
assert(number > 0);
|
||||||
return MakeFileName(name, number, "sst");
|
return MakeFileName(name, number, "ldb");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SSTTableFileName(const std::string& name, uint64_t number) {
|
std::string SSTTableFileName(const std::string& name, uint64_t number) {
|
||||||
assert(number > 0);
|
assert(number > 0);
|
||||||
return MakeFileName(name, number, "ldb");
|
return MakeFileName(name, number, "sst");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DescriptorFileName(const std::string& dbname, uint64_t number) {
|
std::string DescriptorFileName(const std::string& dbname, uint64_t number) {
|
||||||
|
|
|
@ -133,7 +133,9 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) {
|
||||||
|
|
||||||
case kEof:
|
case kEof:
|
||||||
if (in_fragmented_record) {
|
if (in_fragmented_record) {
|
||||||
ReportCorruption(scratch->size(), "partial record without end(3)");
|
// This can be caused by the writer dying immediately after
|
||||||
|
// writing a physical record but before completing the next; don't
|
||||||
|
// treat it as a corruption, just ignore the entire logical record.
|
||||||
scratch->clear();
|
scratch->clear();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -193,13 +195,12 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) {
|
||||||
eof_ = true;
|
eof_ = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (buffer_.size() == 0) {
|
|
||||||
// End of file
|
|
||||||
return kEof;
|
|
||||||
} else {
|
} else {
|
||||||
size_t drop_size = buffer_.size();
|
// Note that if buffer_ is non-empty, we have a truncated header at the
|
||||||
|
// end of the file, which can be caused by the writer crashing in the
|
||||||
|
// middle of writing the header. Instead of considering this an error,
|
||||||
|
// just report EOF.
|
||||||
buffer_.clear();
|
buffer_.clear();
|
||||||
ReportCorruption(drop_size, "truncated record at end of file");
|
|
||||||
return kEof;
|
return kEof;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,9 +214,15 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) {
|
||||||
if (kHeaderSize + length > buffer_.size()) {
|
if (kHeaderSize + length > buffer_.size()) {
|
||||||
size_t drop_size = buffer_.size();
|
size_t drop_size = buffer_.size();
|
||||||
buffer_.clear();
|
buffer_.clear();
|
||||||
|
if (!eof_) {
|
||||||
ReportCorruption(drop_size, "bad record length");
|
ReportCorruption(drop_size, "bad record length");
|
||||||
return kBadRecord;
|
return kBadRecord;
|
||||||
}
|
}
|
||||||
|
// If the end of the file has been reached without reading |length| bytes
|
||||||
|
// of payload, assume the writer died in the middle of writing the record.
|
||||||
|
// Don't report a corruption.
|
||||||
|
return kEof;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == kZeroType && length == 0) {
|
if (type == kZeroType && length == 0) {
|
||||||
// Skip zero length record without reporting any drops since
|
// Skip zero length record without reporting any drops since
|
||||||
|
|
|
@ -351,20 +351,32 @@ TEST(LogTest, BadRecordType) {
|
||||||
ASSERT_EQ("OK", MatchError("unknown record type"));
|
ASSERT_EQ("OK", MatchError("unknown record type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LogTest, TruncatedTrailingRecord) {
|
TEST(LogTest, TruncatedTrailingRecordIsIgnored) {
|
||||||
Write("foo");
|
Write("foo");
|
||||||
ShrinkSize(4); // Drop all payload as well as a header byte
|
ShrinkSize(4); // Drop all payload as well as a header byte
|
||||||
ASSERT_EQ("EOF", Read());
|
ASSERT_EQ("EOF", Read());
|
||||||
ASSERT_EQ(kHeaderSize - 1, DroppedBytes());
|
// Truncated last record is ignored, not treated as an error.
|
||||||
ASSERT_EQ("OK", MatchError("truncated record at end of file"));
|
ASSERT_EQ(0, DroppedBytes());
|
||||||
|
ASSERT_EQ("", ReportMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LogTest, BadLength) {
|
TEST(LogTest, BadLength) {
|
||||||
|
const int kPayloadSize = kBlockSize - kHeaderSize;
|
||||||
|
Write(BigString("bar", kPayloadSize));
|
||||||
|
Write("foo");
|
||||||
|
// Least significant size byte is stored in header[4].
|
||||||
|
IncrementByte(4, 1);
|
||||||
|
ASSERT_EQ("foo", Read());
|
||||||
|
ASSERT_EQ(kBlockSize, DroppedBytes());
|
||||||
|
ASSERT_EQ("OK", MatchError("bad record length"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LogTest, BadLengthAtEndIsIgnored) {
|
||||||
Write("foo");
|
Write("foo");
|
||||||
ShrinkSize(1);
|
ShrinkSize(1);
|
||||||
ASSERT_EQ("EOF", Read());
|
ASSERT_EQ("EOF", Read());
|
||||||
ASSERT_EQ(kHeaderSize + 2, DroppedBytes());
|
ASSERT_EQ(0, DroppedBytes());
|
||||||
ASSERT_EQ("OK", MatchError("bad record length"));
|
ASSERT_EQ("", ReportMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LogTest, ChecksumMismatch) {
|
TEST(LogTest, ChecksumMismatch) {
|
||||||
|
@ -415,6 +427,24 @@ TEST(LogTest, UnexpectedFirstType) {
|
||||||
ASSERT_EQ("OK", MatchError("partial record without end"));
|
ASSERT_EQ("OK", MatchError("partial record without end"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LogTest, MissingLastIsIgnored) {
|
||||||
|
Write(BigString("bar", kBlockSize));
|
||||||
|
// Remove the LAST block, including header.
|
||||||
|
ShrinkSize(14);
|
||||||
|
ASSERT_EQ("EOF", Read());
|
||||||
|
ASSERT_EQ("", ReportMessage());
|
||||||
|
ASSERT_EQ(0, DroppedBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LogTest, PartialLastIsIgnored) {
|
||||||
|
Write(BigString("bar", kBlockSize));
|
||||||
|
// Cause a bad record length in the LAST block.
|
||||||
|
ShrinkSize(1);
|
||||||
|
ASSERT_EQ("EOF", Read());
|
||||||
|
ASSERT_EQ("", ReportMessage());
|
||||||
|
ASSERT_EQ(0, DroppedBytes());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LogTest, ErrorJoinsRecords) {
|
TEST(LogTest, ErrorJoinsRecords) {
|
||||||
// Consider two fragmented records:
|
// Consider two fragmented records:
|
||||||
// first(R1) last(R1) first(R2) last(R2)
|
// first(R1) last(R1) first(R2) last(R2)
|
||||||
|
|
|
@ -242,7 +242,6 @@ class Repairer {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractMetaData() {
|
void ExtractMetaData() {
|
||||||
std::vector<TableInfo> kept;
|
|
||||||
for (size_t i = 0; i < table_numbers_.size(); i++) {
|
for (size_t i = 0; i < table_numbers_.size(); i++) {
|
||||||
ScanTable(table_numbers_[i]);
|
ScanTable(table_numbers_[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,20 +54,6 @@ static int64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
std::string IntSetToString(const std::set<uint64_t>& s) {
|
|
||||||
std::string result = "{";
|
|
||||||
for (std::set<uint64_t>::const_iterator it = s.begin();
|
|
||||||
it != s.end();
|
|
||||||
++it) {
|
|
||||||
result += (result.size() > 1) ? "," : "";
|
|
||||||
result += NumberToString(*it);
|
|
||||||
}
|
|
||||||
result += "}";
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Version::~Version() {
|
Version::~Version() {
|
||||||
assert(refs_ == 0);
|
assert(refs_ == 0);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
Does not support:
|
Does not support:
|
||||||
. getters for the option types
|
. getters for the option types
|
||||||
. custom comparators that implement key shortening
|
. custom comparators that implement key shortening
|
||||||
. capturing post-write-snapshot
|
|
||||||
. custom iter, db, env, cache implementations using just the C bindings
|
. custom iter, db, env, cache implementations using just the C bindings
|
||||||
|
|
||||||
Some conventions:
|
Some conventions:
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace leveldb {
|
||||||
|
|
||||||
// Update Makefile if you change these
|
// Update Makefile if you change these
|
||||||
static const int kMajorVersion = 1;
|
static const int kMajorVersion = 1;
|
||||||
static const int kMinorVersion = 15;
|
static const int kMinorVersion = 17;
|
||||||
|
|
||||||
struct Options;
|
struct Options;
|
||||||
struct ReadOptions;
|
struct ReadOptions;
|
||||||
|
|
|
@ -94,7 +94,7 @@ inline bool operator!=(const Slice& x, const Slice& y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Slice::compare(const Slice& b) const {
|
inline int Slice::compare(const Slice& b) const {
|
||||||
const int min_len = (size_ < b.size_) ? size_ : b.size_;
|
const size_t min_len = (size_ < b.size_) ? size_ : b.size_;
|
||||||
int r = memcmp(data_, b.data_, min_len);
|
int r = memcmp(data_, b.data_, min_len);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
if (size_ < b.size_) r = -1;
|
if (size_ < b.size_) r = -1;
|
||||||
|
|
Loading…
Reference in a new issue