db_iter.h 3.0 KB
Newer Older
1 2 3 4 5
//  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.
//
J
jorlow@chromium.org 已提交
6 7 8 9
// 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.

10
#pragma once
J
jorlow@chromium.org 已提交
11
#include <stdint.h>
12
#include "rocksdb/db.h"
S
sdong 已提交
13
#include "rocksdb/iterator.h"
J
jorlow@chromium.org 已提交
14
#include "db/dbformat.h"
15 16
#include "util/arena.h"
#include "util/autovector.h"
J
jorlow@chromium.org 已提交
17

18
namespace rocksdb {
J
jorlow@chromium.org 已提交
19

20 21
class Arena;
class DBIter;
S
sdong 已提交
22
class InternalIterator;
23

J
jorlow@chromium.org 已提交
24 25 26
// Return a new iterator that converts internal keys (yielded by
// "*internal_iter") that were live at the specified "sequence" number
// into appropriate user keys.
S
sdong 已提交
27 28 29 30 31
extern Iterator* NewDBIterator(Env* env, const ImmutableCFOptions& options,
                               const Comparator* user_key_comparator,
                               InternalIterator* internal_iter,
                               const SequenceNumber& sequence,
                               uint64_t max_sequential_skip_in_iterations,
32 33
                               const Slice* iterate_upper_bound = nullptr,
                               bool prefix_same_as_start = false);
J
jorlow@chromium.org 已提交
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
// A wrapper iterator which wraps DB Iterator and the arena, with which the DB
// iterator is supposed be allocated. This class is used as an entry point of
// a iterator hierarchy whose memory can be allocated inline. In that way,
// accessing the iterator tree can be more cache friendly. It is also faster
// to allocate.
class ArenaWrappedDBIter : public Iterator {
 public:
  virtual ~ArenaWrappedDBIter();

  // Get the arena to be used to allocate memory for DBIter to be wrapped,
  // as well as child iterators in it.
  virtual Arena* GetArena() { return &arena_; }

  // Set the DB Iterator to be wrapped

  virtual void SetDBIter(DBIter* iter);

  // Set the internal iterator wrapped inside the DB Iterator. Usually it is
  // a merging iterator.
S
sdong 已提交
54
  virtual void SetIterUnderDBIter(InternalIterator* iter);
55 56 57 58 59 60 61 62 63
  virtual bool Valid() const override;
  virtual void SeekToFirst() override;
  virtual void SeekToLast() override;
  virtual void Seek(const Slice& target) override;
  virtual void Next() override;
  virtual void Prev() override;
  virtual Slice key() const override;
  virtual Slice value() const override;
  virtual Status status() const override;
S
sdong 已提交
64

65 66 67 68 69 70 71 72 73
  void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2);

 private:
  DBIter* db_iter_;
  Arena arena_;
};

// Generate the arena wrapped iterator class.
extern ArenaWrappedDBIter* NewArenaWrappedDbIterator(
74
    Env* env, const ImmutableCFOptions& options,
75 76 77 78
    const Comparator* user_key_comparator, const SequenceNumber& sequence,
    uint64_t max_sequential_skip_in_iterations,
    const Slice* iterate_upper_bound = nullptr,
    bool prefix_same_as_start = false);
79

80
}  // namespace rocksdb