Skip to content

Commit 42dcc7e

Browse files
committed
Merge upstream LevelDB 1.17.
2 parents e991315 + e353fbc commit 42dcc7e

File tree

8 files changed

+58
-36
lines changed

8 files changed

+58
-36
lines changed

Makefile

+6-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ SHARED = $(SHARED1)
7272
else
7373
# Update db.h if you change these.
7474
SHARED_MAJOR = 1
75-
SHARED_MINOR = 15
75+
SHARED_MINOR = 17
7676
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
7777
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
7878
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
@@ -190,19 +190,20 @@ PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
190190
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
191191
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
192192
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
193+
IOSARCH=-arch armv6 -arch armv7 -arch armv7s -arch arm64
193194

194195
.cc.o:
195196
mkdir -p ios-x86/$(dir $@)
196-
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
197+
$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
197198
mkdir -p ios-arm/$(dir $@)
198-
xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
199+
xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
199200
lipo ios-x86/$@ ios-arm/$@ -create -output $@
200201

201202
.c.o:
202203
mkdir -p ios-x86/$(dir $@)
203-
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
204+
$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
204205
mkdir -p ios-arm/$(dir $@)
205-
xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
206+
xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk $(IOSARCH) -c $< -o ios-arm/$@
206207
lipo ios-x86/$@ ios-arm/$@ -create -output $@
207208

208209
else

db/log_reader.cc

+15-8
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) {
133133

134134
case kEof:
135135
if (in_fragmented_record) {
136-
ReportCorruption(scratch->size(), "partial record without end(3)");
136+
// This can be caused by the writer dying immediately after
137+
// writing a physical record but before completing the next; don't
138+
// treat it as a corruption, just ignore the entire logical record.
137139
scratch->clear();
138140
}
139141
return false;
@@ -193,13 +195,12 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) {
193195
eof_ = true;
194196
}
195197
continue;
196-
} else if (buffer_.size() == 0) {
197-
// End of file
198-
return kEof;
199198
} else {
200-
size_t drop_size = buffer_.size();
199+
// Note that if buffer_ is non-empty, we have a truncated header at the
200+
// end of the file, which can be caused by the writer crashing in the
201+
// middle of writing the header. Instead of considering this an error,
202+
// just report EOF.
201203
buffer_.clear();
202-
ReportCorruption(drop_size, "truncated record at end of file");
203204
return kEof;
204205
}
205206
}
@@ -213,8 +214,14 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) {
213214
if (kHeaderSize + length > buffer_.size()) {
214215
size_t drop_size = buffer_.size();
215216
buffer_.clear();
216-
ReportCorruption(drop_size, "bad record length");
217-
return kBadRecord;
217+
if (!eof_) {
218+
ReportCorruption(drop_size, "bad record length");
219+
return kBadRecord;
220+
}
221+
// If the end of the file has been reached without reading |length| bytes
222+
// of payload, assume the writer died in the middle of writing the record.
223+
// Don't report a corruption.
224+
return kEof;
218225
}
219226

220227
if (type == kZeroType && length == 0) {

db/log_test.cc

+35-5
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,32 @@ TEST(LogTest, BadRecordType) {
351351
ASSERT_EQ("OK", MatchError("unknown record type"));
352352
}
353353

354-
TEST(LogTest, TruncatedTrailingRecord) {
354+
TEST(LogTest, TruncatedTrailingRecordIsIgnored) {
355355
Write("foo");
356356
ShrinkSize(4); // Drop all payload as well as a header byte
357357
ASSERT_EQ("EOF", Read());
358-
ASSERT_EQ(kHeaderSize - 1, DroppedBytes());
359-
ASSERT_EQ("OK", MatchError("truncated record at end of file"));
358+
// Truncated last record is ignored, not treated as an error.
359+
ASSERT_EQ(0, DroppedBytes());
360+
ASSERT_EQ("", ReportMessage());
360361
}
361362

362363
TEST(LogTest, BadLength) {
364+
const int kPayloadSize = kBlockSize - kHeaderSize;
365+
Write(BigString("bar", kPayloadSize));
366+
Write("foo");
367+
// Least significant size byte is stored in header[4].
368+
IncrementByte(4, 1);
369+
ASSERT_EQ("foo", Read());
370+
ASSERT_EQ(kBlockSize, DroppedBytes());
371+
ASSERT_EQ("OK", MatchError("bad record length"));
372+
}
373+
374+
TEST(LogTest, BadLengthAtEndIsIgnored) {
363375
Write("foo");
364376
ShrinkSize(1);
365377
ASSERT_EQ("EOF", Read());
366-
ASSERT_EQ(kHeaderSize + 2, DroppedBytes());
367-
ASSERT_EQ("OK", MatchError("bad record length"));
378+
ASSERT_EQ(0, DroppedBytes());
379+
ASSERT_EQ("", ReportMessage());
368380
}
369381

370382
TEST(LogTest, ChecksumMismatch) {
@@ -415,6 +427,24 @@ TEST(LogTest, UnexpectedFirstType) {
415427
ASSERT_EQ("OK", MatchError("partial record without end"));
416428
}
417429

430+
TEST(LogTest, MissingLastIsIgnored) {
431+
Write(BigString("bar", kBlockSize));
432+
// Remove the LAST block, including header.
433+
ShrinkSize(14);
434+
ASSERT_EQ("EOF", Read());
435+
ASSERT_EQ("", ReportMessage());
436+
ASSERT_EQ(0, DroppedBytes());
437+
}
438+
439+
TEST(LogTest, PartialLastIsIgnored) {
440+
Write(BigString("bar", kBlockSize));
441+
// Cause a bad record length in the LAST block.
442+
ShrinkSize(1);
443+
ASSERT_EQ("EOF", Read());
444+
ASSERT_EQ("", ReportMessage());
445+
ASSERT_EQ(0, DroppedBytes());
446+
}
447+
418448
TEST(LogTest, ErrorJoinsRecords) {
419449
// Consider two fragmented records:
420450
// first(R1) last(R1) first(R2) last(R2)

db/repair.cc

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ class Repairer {
242242
}
243243

244244
void ExtractMetaData() {
245-
std::vector<TableInfo> kept;
246245
for (size_t i = 0; i < table_numbers_.size(); i++) {
247246
ScanTable(table_numbers_[i]);
248247
}

db/version_set.cc

-14
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ static int64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
5454
return sum;
5555
}
5656

57-
namespace {
58-
std::string IntSetToString(const std::set<uint64_t>& s) {
59-
std::string result = "{";
60-
for (std::set<uint64_t>::const_iterator it = s.begin();
61-
it != s.end();
62-
++it) {
63-
result += (result.size() > 1) ? "," : "";
64-
result += NumberToString(*it);
65-
}
66-
result += "}";
67-
return result;
68-
}
69-
} // namespace
70-
7157
Version::~Version() {
7258
assert(refs_ == 0);
7359

include/leveldb/c.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Does not support:
1010
. getters for the option types
1111
. custom comparators that implement key shortening
12-
. capturing post-write-snapshot
1312
. custom iter, db, env, cache implementations using just the C bindings
1413
1514
Some conventions:

include/leveldb/db.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace leveldb {
1414

1515
// Update Makefile if you change these
1616
static const int kMajorVersion = 1;
17-
static const int kMinorVersion = 15;
17+
static const int kMinorVersion = 17;
1818

1919
struct Options;
2020
struct ReadOptions;

include/leveldb/slice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ inline bool operator!=(const Slice& x, const Slice& y) {
9494
}
9595

9696
inline int Slice::compare(const Slice& b) const {
97-
const int min_len = (size_ < b.size_) ? size_ : b.size_;
97+
const size_t min_len = (size_ < b.size_) ? size_ : b.size_;
9898
int r = memcmp(data_, b.data_, min_len);
9999
if (r == 0) {
100100
if (size_ < b.size_) r = -1;

0 commit comments

Comments
 (0)