mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 20:43:57 +00:00
1104eaa35e
Summary: This PR adds support for `TimedPut` API. We introduced a new type `kTypeValuePreferredSeqno` for entries added to the DB via the `TimedPut` API. The life cycle of such an entry on the write/flush/compaction paths are: 1) It is initially added to memtable as: `<user_key, seq, kTypeValuePreferredSeqno>: {value, write_unix_time}` 2) When it's flushed to L0 sst files, it's converted to: `<user_key, seq, kTypeValuePreferredSeqno>: {value, preferred_seqno}` when we have easy access to the seqno to time mapping. 3) During compaction, if certain conditions are met, we swap in the `preferred_seqno` and the entry will become: `<user_key, preferred_seqno, kTypeValue>: value`. This step helps fast track these entries to the cold tier if they are eligible after the sequence number swap. On the read path: A `kTypeValuePreferredSeqno` entry acts the same as a `kTypeValue` entry, the unix_write_time/preferred seqno part packed in value is completely ignored. Needed follow ups: 1) The seqno to time mapping accessible in flush needs to be extended to cover the `write_unix_time` for possible `kTypeValuePreferredSeqno` entries. This also means we need to track these `write_unix_time` in memtable. 2) Compaction filter support for the new `kTypeValuePreferredSeqno` type for feature parity with other `kTypeValue` and equivalent types. 3) Stress test coverage for the feature Pull Request resolved: https://github.com/facebook/rocksdb/pull/12419 Test Plan: Added unit tests Reviewed By: pdillinger Differential Revision: D54920296 Pulled By: jowlyzhang fbshipit-source-id: c8b43f7a7c465e569141770e93c748371ff1da9e
86 lines
2.6 KiB
C++
86 lines
2.6 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 <unordered_set>
|
|
#include <vector>
|
|
|
|
#include "rocksdb/slice.h"
|
|
#include "rocksdb/status.h"
|
|
#include "rocksdb/write_batch.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
// ColumnFamilyCollector is a write batch handler which does nothing
|
|
// except recording unique column family IDs
|
|
class ColumnFamilyCollector : public WriteBatch::Handler {
|
|
std::unordered_set<uint32_t> column_family_ids_;
|
|
|
|
Status AddColumnFamilyId(uint32_t column_family_id) {
|
|
column_family_ids_.insert(column_family_id);
|
|
return Status::OK();
|
|
}
|
|
|
|
public:
|
|
explicit ColumnFamilyCollector() {}
|
|
|
|
~ColumnFamilyCollector() override {}
|
|
|
|
Status PutCF(uint32_t column_family_id, const Slice&, const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status TimedPutCF(uint32_t column_family_id, const Slice&, const Slice&,
|
|
uint64_t) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status DeleteCF(uint32_t column_family_id, const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status SingleDeleteCF(uint32_t column_family_id, const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status DeleteRangeCF(uint32_t column_family_id, const Slice&,
|
|
const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status MergeCF(uint32_t column_family_id, const Slice&,
|
|
const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status PutBlobIndexCF(uint32_t column_family_id, const Slice&,
|
|
const Slice&) override {
|
|
return AddColumnFamilyId(column_family_id);
|
|
}
|
|
|
|
Status MarkBeginPrepare(bool) override { return Status::OK(); }
|
|
|
|
Status MarkEndPrepare(const Slice&) override { return Status::OK(); }
|
|
|
|
Status MarkRollback(const Slice&) override { return Status::OK(); }
|
|
|
|
Status MarkCommit(const Slice&) override { return Status::OK(); }
|
|
|
|
Status MarkCommitWithTimestamp(const Slice&, const Slice&) override {
|
|
return Status::OK();
|
|
}
|
|
|
|
Status MarkNoop(bool) override { return Status::OK(); }
|
|
|
|
const std::unordered_set<uint32_t>& column_families() const {
|
|
return column_family_ids_;
|
|
}
|
|
};
|
|
|
|
Status CollectColumnFamilyIdsFromWriteBatch(
|
|
const WriteBatch& batch, std::vector<uint32_t>* column_family_ids);
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|