Skip to content

Commit

Permalink
Prevent Titan panicing
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar committed Sep 30, 2024
1 parent f30b571 commit 9b45473
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 3 additions & 1 deletion db/blob/blob_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class BlobIndex {

Status DecodeFrom(Slice slice) {
const char* kErrorMessage = "Error while decoding blob index";
assert(slice.size() > 0);
if (slice.empty()) {
return Status::Corruption(kErrorMessage, "Empty blob index");
}
type_ = static_cast<Type>(*slice.data());
if (type_ >= Type::kUnknown) {
return Status::Corruption(kErrorMessage,
Expand Down
44 changes: 23 additions & 21 deletions db/version_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,29 @@ uint64_t PackFileNumberAndPathId(uint64_t number, uint64_t path_id) {
return number | (path_id * (kFileNumberMask + 1));
}

Status FileMetaData::UpdateBoundaries(const Slice& key, const Slice& value,
SequenceNumber seqno,
ValueType value_type) {
if (value_type == kTypeBlobIndex) {
BlobIndex blob_index;
const Status s = blob_index.DecodeFrom(value);
if (!s.ok()) {
return s;
}

if (!blob_index.IsInlined() && !blob_index.HasTTL()) {
if (blob_index.file_number() == kInvalidBlobFileNumber) {
return Status::Corruption("Invalid blob file number");
}

if (oldest_blob_file_number == kInvalidBlobFileNumber ||
oldest_blob_file_number > blob_index.file_number()) {
oldest_blob_file_number = blob_index.file_number();
}
}
}
Status FileMetaData::UpdateBoundaries(const Slice& key, const Slice&,
SequenceNumber seqno, ValueType) {
// Do not check the validity of the blob value here, since Titan blob index
// encoding is different from the RocksDB blob index encoding.

// if (value_type == kTypeBlobIndex) {
// BlobIndex blob_index;
// const Status s = blob_index.DecodeFrom(value);
// if (!s.ok()) {
// return s;
// }

// if (!blob_index.IsInlined() && !blob_index.HasTTL()) {
// if (blob_index.file_number() == kInvalidBlobFileNumber) {
// return Status::Corruption("Invalid blob file number");
// }

// if (oldest_blob_file_number == kInvalidBlobFileNumber ||
// oldest_blob_file_number > blob_index.file_number()) {
// oldest_blob_file_number = blob_index.file_number();
// }
// }
// }

if (smallest.size() == 0) {
smallest.DecodeFrom(key);
Expand Down

0 comments on commit 9b45473

Please sign in to comment.