Skip to content

Commit

Permalink
Merge commit 'b7603cae635a097a1f60b5e5acc53b81ff834a27' into 2021_upd…
Browse files Browse the repository at this point in the history
…ate-leveldb
  • Loading branch information
Fuzzbawls committed Aug 4, 2021
2 parents 04d6139 + b7603ca commit 59ffc7b
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/leveldb/db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, bool last_log,
while (reader.ReadRecord(&record, &scratch) && status.ok()) {
if (record.size() < 12) {
reporter.Corruption(record.size(),
Status::Corruption("log record too small"));
Status::Corruption("log record too small", fname));
continue;
}
WriteBatchInternal::SetContents(&batch, record);
Expand Down
3 changes: 3 additions & 0 deletions src/leveldb/db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class SpecialEnv : public EnvWrapper {
}
return base_->Sync();
}
std::string GetName() const override { return ""; }
};
class ManifestFile : public WritableFile {
private:
Expand All @@ -183,6 +184,7 @@ class SpecialEnv : public EnvWrapper {
return base_->Sync();
}
}
std::string GetName() const override { return ""; }
};

if (non_writable_.load(std::memory_order_acquire)) {
Expand Down Expand Up @@ -216,6 +218,7 @@ class SpecialEnv : public EnvWrapper {
counter_->Increment();
return target_->Read(offset, n, result, scratch);
}
std::string GetName() const override { return ""; }
};

Status s = target()->NewRandomAccessFile(f, r);
Expand Down
1 change: 1 addition & 0 deletions src/leveldb/db/fault_injection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class TestWritableFile : public WritableFile {
Status Close() override;
Status Flush() override;
Status Sync() override;
std::string GetName() const override { return ""; }

private:
FileState state_;
Expand Down
1 change: 1 addition & 0 deletions src/leveldb/db/leveldbutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class StdoutPrinter : public WritableFile {
Status Close() override { return Status::OK(); }
Status Flush() override { return Status::OK(); }
Status Sync() override { return Status::OK(); }
std::string GetName() const override { return "[stdout]"; }
};

bool HandleDumpCommand(Env* env, char** files, int num) {
Expand Down
2 changes: 1 addition & 1 deletion src/leveldb/db/log_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) {
uint64_t Reader::LastRecordOffset() { return last_record_offset_; }

void Reader::ReportCorruption(uint64_t bytes, const char* reason) {
ReportDrop(bytes, Status::Corruption(reason));
ReportDrop(bytes, Status::Corruption(reason, file_->GetName()));
}

void Reader::ReportDrop(uint64_t bytes, const Status& reason) {
Expand Down
2 changes: 2 additions & 0 deletions src/leveldb/db/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class LogTest {
contents_.append(slice.data(), slice.size());
return Status::OK();
}
std::string GetName() const override { return ""; }

std::string contents_;
};
Expand Down Expand Up @@ -204,6 +205,7 @@ class LogTest {

return Status::OK();
}
std::string GetName() const { return ""; }

Slice contents_;
bool force_error_;
Expand Down
2 changes: 1 addition & 1 deletion src/leveldb/db/repair.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Repairer {
while (reader.ReadRecord(&record, &scratch)) {
if (record.size() < 12) {
reporter.Corruption(record.size(),
Status::Corruption("log record too small"));
Status::Corruption("log record too small", logname));
continue;
}
WriteBatchInternal::SetContents(&batch, record);
Expand Down
3 changes: 3 additions & 0 deletions src/leveldb/helpers/memenv/memenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class SequentialFileImpl : public SequentialFile {
return Status::OK();
}

virtual std::string GetName() const override { return "[memenv]"; }
private:
FileState* file_;
uint64_t pos_;
Expand All @@ -194,6 +195,7 @@ class RandomAccessFileImpl : public RandomAccessFile {
return file_->Read(offset, n, result, scratch);
}

virtual std::string GetName() const override { return "[memenv]"; }
private:
FileState* file_;
};
Expand All @@ -210,6 +212,7 @@ class WritableFileImpl : public WritableFile {
Status Flush() override { return Status::OK(); }
Status Sync() override { return Status::OK(); }

virtual std::string GetName() const override { return "[memenv]"; }
private:
FileState* file_;
};
Expand Down
9 changes: 9 additions & 0 deletions src/leveldb/include/leveldb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class LEVELDB_EXPORT SequentialFile {
//
// REQUIRES: External synchronization
virtual Status Skip(uint64_t n) = 0;

// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
};

// A file abstraction for randomly reading the contents of a file.
Expand All @@ -240,6 +243,9 @@ class LEVELDB_EXPORT RandomAccessFile {
// Safe for concurrent use by multiple threads.
virtual Status Read(uint64_t offset, size_t n, Slice* result,
char* scratch) const = 0;

// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
};

// A file abstraction for sequential writing. The implementation
Expand All @@ -258,6 +264,9 @@ class LEVELDB_EXPORT WritableFile {
virtual Status Close() = 0;
virtual Status Flush() = 0;
virtual Status Sync() = 0;

// Get a name for the file, only for error reporting
virtual std::string GetName() const = 0;
};

// An interface for writing log messages.
Expand Down
10 changes: 5 additions & 5 deletions src/leveldb/table/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
}
if (contents.size() != n + kBlockTrailerSize) {
delete[] buf;
return Status::Corruption("truncated block read");
return Status::Corruption("truncated block read", file->GetName());
}

// Check the crc of the type and the block contents
Expand All @@ -89,7 +89,7 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
const uint32_t actual = crc32c::Value(data, n + 1);
if (actual != crc) {
delete[] buf;
s = Status::Corruption("block checksum mismatch");
s = Status::Corruption("block checksum mismatch", file->GetName());
return s;
}
}
Expand All @@ -116,13 +116,13 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
size_t ulength = 0;
if (!port::Snappy_GetUncompressedLength(data, n, &ulength)) {
delete[] buf;
return Status::Corruption("corrupted compressed block contents");
return Status::Corruption("corrupted compressed block contents", file->GetName());
}
char* ubuf = new char[ulength];
if (!port::Snappy_Uncompress(data, n, ubuf)) {
delete[] buf;
delete[] ubuf;
return Status::Corruption("corrupted compressed block contents");
return Status::Corruption("corrupted compressed block contents", file->GetName());
}
delete[] buf;
result->data = Slice(ubuf, ulength);
Expand All @@ -132,7 +132,7 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
}
default:
delete[] buf;
return Status::Corruption("bad block type");
return Status::Corruption("bad block type", file->GetName());
}

return Status::OK();
Expand Down
2 changes: 2 additions & 0 deletions src/leveldb/table/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class StringSink : public WritableFile {
return Status::OK();
}

std::string GetName() const override { return ""; }
private:
std::string contents_;
};
Expand All @@ -128,6 +129,7 @@ class StringSource : public RandomAccessFile {
return Status::OK();
}

std::string GetName() const { return ""; }
private:
std::string contents_;
};
Expand Down
23 changes: 18 additions & 5 deletions src/leveldb/util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace {
// Set by EnvPosixTestHelper::SetReadOnlyMMapLimit() and MaxOpenFiles().
int g_open_read_only_file_limit = -1;

// Up to 1000 mmap regions for 64-bit binaries; none for 32-bit.
constexpr const int kDefaultMmapLimit = (sizeof(void*) >= 8) ? 1000 : 0;
// Up to 4096 mmap regions for 64-bit binaries; none for 32-bit.
constexpr const int kDefaultMmapLimit = (sizeof(void*) >= 8) ? 4096 : 0;

// Can be set using EnvPosixTestHelper::SetReadOnlyMMapLimit().
int g_mmap_limit = kDefaultMmapLimit;
Expand Down Expand Up @@ -135,6 +135,8 @@ class PosixSequentialFile final : public SequentialFile {
return Status::OK();
}

virtual std::string GetName() const override { return filename_; }

private:
const int fd_;
const std::string filename_;
Expand Down Expand Up @@ -195,6 +197,8 @@ class PosixRandomAccessFile final : public RandomAccessFile {
return status;
}

virtual std::string GetName() const override { return filename_; }

private:
const bool has_permanent_fd_; // If false, the file is opened on every read.
const int fd_; // -1 if has_permanent_fd_ is false.
Expand Down Expand Up @@ -239,6 +243,8 @@ class PosixMmapReadableFile final : public RandomAccessFile {
return Status::OK();
}

virtual std::string GetName() const override { return filename_; }

private:
char* const mmap_base_;
const size_t length_;
Expand Down Expand Up @@ -319,7 +325,7 @@ class PosixWritableFile final : public WritableFile {
return status;
}

return SyncFd(fd_, filename_);
return SyncFd(fd_, filename_, false);
}

private:
Expand Down Expand Up @@ -354,7 +360,7 @@ class PosixWritableFile final : public WritableFile {
if (fd < 0) {
status = PosixError(dirname_, errno);
} else {
status = SyncFd(fd, dirname_);
status = SyncFd(fd, dirname_, true);
::close(fd);
}
return status;
Expand All @@ -366,7 +372,7 @@ class PosixWritableFile final : public WritableFile {
//
// The path argument is only used to populate the description string in the
// returned Status if an error occurs.
static Status SyncFd(int fd, const std::string& fd_path) {
static Status SyncFd(int fd, const std::string& fd_path, bool syncing_dir) {
#if HAVE_FULLFSYNC
// On macOS and iOS, fsync() doesn't guarantee durability past power
// failures. fcntl(F_FULLFSYNC) is required for that purpose. Some
Expand All @@ -386,6 +392,11 @@ class PosixWritableFile final : public WritableFile {
if (sync_success) {
return Status::OK();
}
// Do not crash if filesystem can't fsync directories
// (see https://github.com/bitcoin/bitcoin/pull/10000)
if (syncing_dir && errno == EINVAL) {
return Status::OK();
}
return PosixError(fd_path, errno);
}

Expand Down Expand Up @@ -426,6 +437,8 @@ class PosixWritableFile final : public WritableFile {
return Basename(filename).starts_with("MANIFEST");
}

virtual std::string GetName() const override { return filename_; }

// buf_[0, pos_ - 1] contains data to be written to fd_.
char buf_[kWritableFileBufferSize];
size_t pos_;
Expand Down
Loading

0 comments on commit 59ffc7b

Please sign in to comment.