table_reader.h 3.2 KB
Newer Older
K
kailiu 已提交
1 2 3 4 5 6 7 8 9 10
//  Copyright (c) 2013, Facebook, Inc.  All rights reserved.
//  This source code is licensed under the BSD-style license found in the
//  LICENSE file in the root directory of this source tree. An additional grant
//  of patent rights can be found in the PATENTS file in the same directory.
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#pragma once
K
kailiu 已提交
11
#include <memory>
K
kailiu 已提交
12 13 14 15

namespace rocksdb {

class Iterator;
K
kailiu 已提交
16
struct ParsedInternalKey;
K
kailiu 已提交
17
class Slice;
18
class Arena;
K
kailiu 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31
struct ReadOptions;
struct TableProperties;

// A Table is a sorted map from strings to strings.  Tables are
// immutable and persistent.  A Table may be safely accessed from
// multiple threads without external synchronization.
class TableReader {
 public:
  virtual ~TableReader() {}

  // Returns a new iterator over the table contents.
  // The result of NewIterator() is initially invalid (caller must
  // call one of the Seek methods on the iterator before using it).
32 33 34 35 36
  // arena: If not null, the arena needs to be used to allocate the Iterator.
  //        When destroying the iterator, the caller will not call "delete"
  //        but Iterator::~Iterator() directly. The destructor needs to destroy
  //        all the states but those allocated in arena.
  virtual Iterator* NewIterator(const ReadOptions&, Arena* arena = nullptr) = 0;
K
kailiu 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49

  // Given a key, return an approximate byte offset in the file where
  // the data for that key begins (or would begin if the key were
  // present in the file).  The returned value is in terms of file
  // bytes, and so includes effects like compression of the underlying data.
  // E.g., the approximate offset of the last key in the table will
  // be close to the file length.
  virtual uint64_t ApproximateOffsetOf(const Slice& key) = 0;

  // Set up the table for Compaction. Might change some parameters with
  // posix_fadvise
  virtual void SetupForCompaction() = 0;

K
kailiu 已提交
50
  virtual std::shared_ptr<const TableProperties> GetTableProperties() const = 0;
K
kailiu 已提交
51

52 53 54
  // Prepare work that can be done before the real Get()
  virtual void Prepare(const Slice& target) {}

55 56 57
  // Report an approximation of how much memory has been used.
  virtual size_t ApproximateMemoryUsage() const = 0;

K
kailiu 已提交
58 59 60
  // Calls (*result_handler)(handle_context, ...) repeatedly, starting with
  // the entry found after a call to Seek(key), until result_handler returns
  // false, where k is the actual internal key for a row found and v as the
I
Igor Canadi 已提交
61 62
  // value of the key. May not make such a call if filter policy says that key
  // is not present.
K
kailiu 已提交
63 64 65 66 67 68 69 70 71
  //
  // mark_key_may_exist_handler needs to be called when it is configured to be
  // memory only and the key is not found in the block cache, with
  // the parameter to be handle_context.
  //
  // readOptions is the options for the read
  // key is the key to search for
  virtual Status Get(
      const ReadOptions& readOptions, const Slice& key, void* handle_context,
72
      bool (*result_handler)(void* arg, const ParsedInternalKey& k,
I
Igor Canadi 已提交
73
                             const Slice& v),
K
kailiu 已提交
74 75 76 77
      void (*mark_key_may_exist_handler)(void* handle_context) = nullptr) = 0;
};

}  // namespace rocksdb