]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/blob_db/blob_db_iterator.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
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).
9 #include "db/arena_wrapped_db_iter.h"
10 #include "rocksdb/iterator.h"
11 #include "util/stop_watch.h"
12 #include "utilities/blob_db/blob_db_impl.h"
14 namespace ROCKSDB_NAMESPACE
{
20 using ROCKSDB_NAMESPACE::ManagedSnapshot
;
22 class BlobDBIterator
: public Iterator
{
24 BlobDBIterator(ManagedSnapshot
* snapshot
, ArenaWrappedDBIter
* iter
,
25 BlobDBImpl
* blob_db
, SystemClock
* clock
,
26 Statistics
* statistics
)
27 : snapshot_(snapshot
),
31 statistics_(statistics
) {}
33 virtual ~BlobDBIterator() = default;
35 bool Valid() const override
{
36 if (!iter_
->Valid()) {
42 Status
status() const override
{
43 if (!iter_
->status().ok()) {
44 return iter_
->status();
49 void SeekToFirst() override
{
50 StopWatch
seek_sw(clock_
, statistics_
, BLOB_DB_SEEK_MICROS
);
51 RecordTick(statistics_
, BLOB_DB_NUM_SEEK
);
53 while (UpdateBlobValue()) {
58 void SeekToLast() override
{
59 StopWatch
seek_sw(clock_
, statistics_
, BLOB_DB_SEEK_MICROS
);
60 RecordTick(statistics_
, BLOB_DB_NUM_SEEK
);
62 while (UpdateBlobValue()) {
67 void Seek(const Slice
& target
) override
{
68 StopWatch
seek_sw(clock_
, statistics_
, BLOB_DB_SEEK_MICROS
);
69 RecordTick(statistics_
, BLOB_DB_NUM_SEEK
);
71 while (UpdateBlobValue()) {
76 void SeekForPrev(const Slice
& target
) override
{
77 StopWatch
seek_sw(clock_
, statistics_
, BLOB_DB_SEEK_MICROS
);
78 RecordTick(statistics_
, BLOB_DB_NUM_SEEK
);
79 iter_
->SeekForPrev(target
);
80 while (UpdateBlobValue()) {
85 void Next() override
{
87 StopWatch
next_sw(clock_
, statistics_
, BLOB_DB_NEXT_MICROS
);
88 RecordTick(statistics_
, BLOB_DB_NUM_NEXT
);
90 while (UpdateBlobValue()) {
95 void Prev() override
{
97 StopWatch
prev_sw(clock_
, statistics_
, BLOB_DB_PREV_MICROS
);
98 RecordTick(statistics_
, BLOB_DB_NUM_PREV
);
100 while (UpdateBlobValue()) {
105 Slice
key() const override
{
110 Slice
value() const override
{
112 if (!iter_
->IsBlob()) {
113 return iter_
->value();
118 // Iterator::Refresh() not supported.
121 // Return true if caller should continue to next value.
122 bool UpdateBlobValue() {
124 status_
= Status::OK();
125 if (iter_
->Valid() && iter_
->status().ok() && iter_
->IsBlob()) {
126 Status s
= blob_db_
->GetBlobValue(iter_
->key(), iter_
->value(), &value_
);
127 if (s
.IsNotFound()) {
140 std::unique_ptr
<ManagedSnapshot
> snapshot_
;
141 std::unique_ptr
<ArenaWrappedDBIter
> iter_
;
142 BlobDBImpl
* blob_db_
;
144 Statistics
* statistics_
;
146 PinnableSlice value_
;
148 } // namespace blob_db
149 } // namespace ROCKSDB_NAMESPACE
150 #endif // !ROCKSDB_LITE