mirror of
https://github.com/facebook/rocksdb.git
synced 2026-10-23 08:09:02 +03:00
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/15344 Add the internal TableBuilder::TryAdd() contract so RocksDB-owned table builders can distinguish accepted rows, real builder errors, and clean requests to cut the current output table and retry the same row. Add diagnostic reason codes for retryable table boundaries; existing internal table builders inherit a default TryAdd() implementation that forwards to Add(). Translate the public ExternalTableBuilderBase::TryAdd() result in ExternalTableBuilderAdapter so external table implementations can request a file cut while RocksDB compaction uses the internal TableBuilder contract. Teach compaction output writing to honor kRequiresNewTable by closing the current output file, opening a new one through the existing callbacks, and retrying the same key without advancing the input iterator. Split OutputValidator validation into CanAdd() and AddValidated() so validator state is not updated until the key is actually accepted by a table builder. Add a DB compaction test with a custom TableFactory that wraps block-based tables and requests one mid-compaction file cut. The test verifies the cut produces two readable output files and preserves all key/value results. Reviewed By: jaykorean, xingbowang Differential Revision: D123932406 fbshipit-source-id: 9ed82c3782787de192bca15e40bfbf014ef28c15
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
//
|
|
#include "db/output_validator.h"
|
|
|
|
#include "test_util/sync_point.h"
|
|
#include "util/hash.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
Status OutputValidator::CanAdd(const Slice& key) const {
|
|
if (key.size() < kNumInternalBytes) {
|
|
return Status::Corruption(
|
|
"Compaction tries to write a key without internal bytes.");
|
|
}
|
|
// prev_key_ starts with empty.
|
|
if (!prev_key_.empty() && icmp_.Compare(key, prev_key_) < 0) {
|
|
return Status::Corruption("Compaction sees out-of-order keys.");
|
|
}
|
|
return Status::OK();
|
|
}
|
|
|
|
Status OutputValidator::Add(const Slice& key, const Slice& value) {
|
|
Status s = CanAdd(key);
|
|
if (!s.ok()) {
|
|
return s;
|
|
}
|
|
AddValidated(key, value);
|
|
return Status::OK();
|
|
}
|
|
|
|
void OutputValidator::AddValidated(const Slice& key, const Slice& value) {
|
|
if (enable_hash_) {
|
|
// Generate a rolling 64-bit hash of the key and values.
|
|
paranoid_hash_ = NPHash64(key.data(), key.size(), paranoid_hash_);
|
|
paranoid_hash_ = NPHash64(value.data(), value.size(), paranoid_hash_);
|
|
}
|
|
prev_key_.assign(key.data(), key.size());
|
|
}
|
|
} // namespace ROCKSDB_NAMESPACE
|