Skip to content

Add filename to corruption errors #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,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 db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class SpecialEnv : public EnvWrapper {
}
return base_->Sync();
}
std::string GetName() const override { return ""; }
};
class ManifestFile : public WritableFile {
private:
Expand All @@ -215,6 +216,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 @@ -247,6 +249,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 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 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 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 db/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class LogTest : public testing::Test {
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 : public testing::Test {

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

Slice contents_;
bool force_error_;
Expand Down
2 changes: 1 addition & 1 deletion 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 helpers/memenv/memenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class SequentialFileImpl : public SequentialFile {
return Status::OK();
}

virtual std::string GetName() const override { return "[memenv]"; }
private:
FileState* file_;
uint64_t pos_;
Expand All @@ -193,6 +194,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 @@ -209,6 +211,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 include/leveldb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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 @@ -269,6 +272,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 @@ -287,6 +293,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 table/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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 @@ -94,7 +94,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 @@ -121,7 +121,7 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
size_t ulength = 0;
if (!port::Snappy_GetUncompressedLength(data, n, &ulength)) {
delete[] buf;
return Status::Corruption("corrupted snappy compressed block length");
return Status::Corruption("corrupted snappy compressed block length", file->GetName());
}
char* ubuf = new char[ulength];
if (!port::Snappy_Uncompress(data, n, ubuf)) {
Expand All @@ -145,7 +145,7 @@ Status ReadBlock(RandomAccessFile* file, const ReadOptions& options,
if (!port::Zstd_Uncompress(data, n, ubuf)) {
delete[] buf;
delete[] ubuf;
return Status::Corruption("corrupted zstd compressed block contents");
return Status::Corruption("corrupted zstd compressed block contents", file->GetName());
}
delete[] buf;
result->data = Slice(ubuf, ulength);
Expand All @@ -155,7 +155,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 table/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class StringSink : public WritableFile {
return Status::OK();
}

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

std::string GetName() const { return ""; }
private:
std::string contents_;
};
Expand Down
8 changes: 8 additions & 0 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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 @@ -223,6 +225,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 @@ -267,6 +271,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 @@ -454,6 +460,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
8 changes: 8 additions & 0 deletions util/env_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class WindowsSequentialFile : public SequentialFile {
return Status::OK();
}

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

private:
const ScopedHandle handle_;
const std::string filename_;
Expand Down Expand Up @@ -225,6 +227,8 @@ class WindowsRandomAccessFile : public RandomAccessFile {
return Status::OK();
}

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

private:
const ScopedHandle handle_;
const std::string filename_;
Expand Down Expand Up @@ -256,6 +260,8 @@ class WindowsMmapReadableFile : public RandomAccessFile {
return Status::OK();
}

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

private:
char* const mmap_base_;
const size_t length_;
Expand Down Expand Up @@ -325,6 +331,8 @@ class WindowsWritableFile : public WritableFile {
return Status::OK();
}

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

private:
Status FlushBuffer() {
Status status = WriteUnbuffered(buf_, pos_);
Expand Down