github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/getter.h (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  #pragma once
    12  
    13  #include <libroach.h>
    14  #include <rocksdb/db.h>
    15  #include <rocksdb/iterator.h>
    16  
    17  namespace cockroach {
    18  
    19  // Getter defines an interface for retrieving a value from either an
    20  // iterator or an engine. It is used by ProcessDeltaKey to abstract
    21  // whether the "base" layer is an iterator or an engine.
    22  struct Getter {
    23    virtual DBStatus Get(DBString* value) = 0;
    24  };
    25  
    26  // IteratorGetter is an implementation of the Getter interface which
    27  // retrieves the value currently pointed to by the supplied
    28  // iterator. It is ok for the supplied iterator to be NULL in which
    29  // case no value will be retrieved.
    30  struct IteratorGetter : public Getter {
    31    rocksdb::Iterator* const base;
    32  
    33    IteratorGetter(rocksdb::Iterator* iter) : base(iter) {}
    34  
    35    virtual DBStatus Get(DBString* value);
    36  };
    37  
    38  // DBGetter is an implementation of the Getter interface which
    39  // retrieves the value for the supplied key from a rocksdb::DB.
    40  struct DBGetter : public Getter {
    41    rocksdb::DB* const rep;
    42    rocksdb::ReadOptions const options;
    43    std::string const key;
    44  
    45    DBGetter(rocksdb::DB* const r, rocksdb::ReadOptions opts, std::string&& k)
    46        : rep(r), options(opts), key(std::move(k)) {}
    47  
    48    virtual DBStatus Get(DBString* value);
    49  };
    50  
    51  }  // namespace cockroach