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/15086 Why: An application built on top of RocksDB could use cache population reads through explicit snapshots and needs to know when the returned value has already been superseded, without a second point read. Previous behavior: Get and MultiGet returned the snapshot-visible value and optional timestamp but could not report a newer point update or covering range deletion. New behavior: experimental C++, C, and Java metadata-read APIs report newer committed puts, deletes, merges, and covering range tombstones; ordinary primary-DB writes completed before the read are guaranteed to be reported, racing writes remain best-effort, and true has no false positives. Implementation: metadata reads widen lookup behind read-callback hooks while keeping metadata-only state off passive common object layouts; per-key state stays in KeyContext/GetContext, ordinary MultiGet row-cache replay semantics are preserved, BlobDB/TTL use shared output helpers, dead single-CF plumbing and an invalid cross-key stress assertion are removed, and the range-tombstone ordering invariant is documented without changing behavior. Safety and unsupported cases: tracking is opt-in and requires an explicit snapshot; persisted-tier reads, custom transactional visibility callbacks, secondary DBs, and unsupported subclasses return NotSupported, while read-only/compacted DBs return false because their in-process views are static. Tests and limitations: 1,265 Buck tests plus focused metadata, 100x coerced-context-switch row-cache, write-committed/write-prepared crash tests, builds, and lint passed. Current-parent release db_bench found no material passive regression: readrandom +0.65%, MultiGet batch 4 -1.40%, and batch 32 +0.48%. Reviewed By: pdillinger Differential Revision: D104182397 fbshipit-source-id: 36f7be1cd50fe2383689adaae31a6bb7d7e462dc
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
// 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).
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "rocksdb/db.h"
|
|
#include "table/multiget_context.h"
|
|
#include "util/autovector.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
inline std::string* GetOutputTimestamp(OutputMetadata* output_metadata) {
|
|
return output_metadata != nullptr && output_metadata->timestamp.has_value()
|
|
? &*output_metadata->timestamp
|
|
: nullptr;
|
|
}
|
|
|
|
inline std::vector<std::string>* GetOutputTimestamps(
|
|
MultiGetOutputMetadata* output_metadata) {
|
|
return output_metadata != nullptr && output_metadata->timestamps.has_value()
|
|
? &*output_metadata->timestamps
|
|
: nullptr;
|
|
}
|
|
|
|
inline bool* GetOutputNewerVersionPresent(OutputMetadata* output_metadata) {
|
|
return output_metadata != nullptr &&
|
|
output_metadata->newer_version_present.has_value()
|
|
? &*output_metadata->newer_version_present
|
|
: nullptr;
|
|
}
|
|
|
|
inline std::vector<uint8_t>* GetOutputNewerVersionPresent(
|
|
MultiGetOutputMetadata* output_metadata) {
|
|
return output_metadata != nullptr &&
|
|
output_metadata->newer_version_present.has_value()
|
|
? &*output_metadata->newer_version_present
|
|
: nullptr;
|
|
}
|
|
|
|
inline ColumnFamilyHandle** MakeMutableCfHandles(
|
|
ColumnFamilyHandle* const* column_families, size_t num_keys,
|
|
autovector<ColumnFamilyHandle*, MultiGetContext::MAX_BATCH_SIZE>*
|
|
stack_column_families,
|
|
std::vector<ColumnFamilyHandle*>* heap_column_families) {
|
|
ColumnFamilyHandle** mutable_column_families;
|
|
if (num_keys <= MultiGetContext::MAX_BATCH_SIZE) {
|
|
stack_column_families->resize(num_keys);
|
|
mutable_column_families =
|
|
num_keys == 0 ? nullptr : &(*stack_column_families)[0];
|
|
} else {
|
|
heap_column_families->resize(num_keys);
|
|
mutable_column_families = heap_column_families->data();
|
|
}
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
|
mutable_column_families[i] = column_families[i];
|
|
}
|
|
return mutable_column_families;
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|