mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 11:43:49 +00:00
161ab42a8a
Summary: We are going to expose properties of all tables to end users through "some" db interface. However, current design doesn't naturally fit for this need, which is because: 1. If a table presents in table cache, we cannot simply return the reference to its table properties, because the table may be destroy after compaction (and we don't want to hold the ref of the version). 2. Copy table properties is OK, but it's slow. Thus in this diff, I change the table reader's interface to return a shared pointer (for const table properties), instead a const refernce. Test Plan: `make check` passed Reviewers: haobo, sdong, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D15999
73 lines
3 KiB
C++
73 lines
3 KiB
C++
// 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
|
|
#include <memory>
|
|
|
|
namespace rocksdb {
|
|
|
|
class Iterator;
|
|
struct ParsedInternalKey;
|
|
class Slice;
|
|
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() {}
|
|
|
|
// Determine whether there is a chance that the current table file
|
|
// contains the key a key starting with iternal_prefix. The specific
|
|
// table implementation can use bloom filter and/or other heuristic
|
|
// to filter out this table as a whole.
|
|
virtual bool PrefixMayMatch(const Slice& internal_prefix) = 0;
|
|
|
|
// 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).
|
|
virtual Iterator* NewIterator(const ReadOptions&) = 0;
|
|
|
|
// 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;
|
|
|
|
virtual std::shared_ptr<const TableProperties> GetTableProperties() const = 0;
|
|
|
|
// 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
|
|
// value of the key. didIO is true if I/O is involved in the operation. May
|
|
// not make such a call if filter policy says that key is not present.
|
|
//
|
|
// 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,
|
|
bool (*result_handler)(void* arg, const ParsedInternalKey& k,
|
|
const Slice& v, bool didIO),
|
|
void (*mark_key_may_exist_handler)(void* handle_context) = nullptr) = 0;
|
|
};
|
|
|
|
} // namespace rocksdb
|