/src/rocksdb/util/dirty_tracked.h
Line | Count | Source |
1 | | // Copyright (c) Meta Platforms, Inc. and affiliates. |
2 | | // This source code is licensed under both the GPLv2 (found in the |
3 | | // COPYING file in the root directory) and Apache 2.0 License |
4 | | // (found in the LICENSE.Apache file in the root directory). |
5 | | |
6 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
7 | | // This source code is licensed under both the GPLv2 (found in the |
8 | | // COPYING file in the root directory) and Apache 2.0 License |
9 | | // (found in the LICENSE.Apache file in the root directory). |
10 | | #pragma once |
11 | | |
12 | | #include <utility> |
13 | | |
14 | | #include "rocksdb/rocksdb_namespace.h" |
15 | | |
16 | | namespace ROCKSDB_NAMESPACE { |
17 | | |
18 | | // Wraps a value of type T and tracks whether it has been mutated since the |
19 | | // last Reset(). Reset() short-circuits when the value is not dirty -- useful |
20 | | // when T::Reset() is non-trivial (allocations, container clears) and the |
21 | | // value is rarely populated on a hot path. |
22 | | // |
23 | | // Requirements on T: |
24 | | // - exposes a `void Reset()` method that returns it to a clean state. |
25 | | // |
26 | | // Read access via operator-> / operator* always returns a const view, so |
27 | | // reads are free of dirty bookkeeping regardless of whether the wrapper |
28 | | // itself is const. Mutation must go through mut(), which marks dirty and |
29 | | // returns a mutable pointer. |
30 | | // |
31 | | // Thread safety: not thread safe. The owning object is responsible for |
32 | | // synchronization. |
33 | | template <typename T> |
34 | | class DirtyTracked { |
35 | | public: |
36 | | // Forwards constructor arguments to T. |
37 | | template <typename... Args> |
38 | 25.0k | explicit DirtyTracked(Args&&... args) : value_{std::forward<Args>(args)...} {}rocksdb::DirtyTracked<rocksdb::DBIter::BlobState>::DirtyTracked<rocksdb::Version const*&, rocksdb::ReadOptions const&, rocksdb::BlobFileCache*, bool>(rocksdb::Version const*&, rocksdb::ReadOptions const&, rocksdb::BlobFileCache*&&, bool&&) Line | Count | Source | 38 | 12.5k | explicit DirtyTracked(Args&&... args) : value_{std::forward<Args>(args)...} {} |
rocksdb::DirtyTracked<rocksdb::DBIter::ValueColumnsState>::DirtyTracked<rocksdb::Version const*&, rocksdb::ReadOptions const&, rocksdb::ColumnFamilyData*&>(rocksdb::Version const*&, rocksdb::ReadOptions const&, rocksdb::ColumnFamilyData*&) Line | Count | Source | 38 | 12.5k | explicit DirtyTracked(Args&&... args) : value_{std::forward<Args>(args)...} {} |
|
39 | | |
40 | | // Read-only access. |
41 | 34.5k | const T* operator->() const { return &value_; }rocksdb::DirtyTracked<rocksdb::DBIter::ValueColumnsState>::operator->() const Line | Count | Source | 41 | 34.5k | const T* operator->() const { return &value_; } |
Unexecuted instantiation: rocksdb::DirtyTracked<rocksdb::DBIter::BlobState>::operator->() const |
42 | 0 | const T& operator*() const { return value_; } |
43 | | |
44 | | // Explicit mutating access -- marks dirty, returns a mutable pointer. |
45 | 80.4k | T* mut() { |
46 | 80.4k | dirty_ = true; |
47 | 80.4k | return &value_; |
48 | 80.4k | } rocksdb::DirtyTracked<rocksdb::DBIter::ValueColumnsState>::mut() Line | Count | Source | 45 | 80.4k | T* mut() { | 46 | 80.4k | dirty_ = true; | 47 | 80.4k | return &value_; | 48 | 80.4k | } |
Unexecuted instantiation: rocksdb::DirtyTracked<rocksdb::DBIter::BlobState>::mut() |
49 | | |
50 | 93.5k | void Reset() { |
51 | 93.5k | if (dirty_) { |
52 | 36.9k | value_.Reset(); |
53 | 36.9k | dirty_ = false; |
54 | 36.9k | } |
55 | 93.5k | } rocksdb::DirtyTracked<rocksdb::DBIter::ValueColumnsState>::Reset() Line | Count | Source | 50 | 46.7k | void Reset() { | 51 | 46.7k | if (dirty_) { | 52 | 36.9k | value_.Reset(); | 53 | 36.9k | dirty_ = false; | 54 | 36.9k | } | 55 | 46.7k | } |
rocksdb::DirtyTracked<rocksdb::DBIter::BlobState>::Reset() Line | Count | Source | 50 | 46.7k | void Reset() { | 51 | 46.7k | if (dirty_) { | 52 | 0 | value_.Reset(); | 53 | 0 | dirty_ = false; | 54 | 0 | } | 55 | 46.7k | } |
|
56 | | |
57 | | private: |
58 | | T value_; |
59 | | bool dirty_ = false; |
60 | | }; |
61 | | |
62 | | } // namespace ROCKSDB_NAMESPACE |