YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/table_reader.h
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#ifndef YB_ROCKSDB_TABLE_TABLE_READER_H
25
#define YB_ROCKSDB_TABLE_TABLE_READER_H
26
27
#include <memory>
28
29
#include "yb/rocksdb/status.h"
30
31
#include "yb/util/result.h"
32
33
namespace rocksdb {
34
35
class Iterator;
36
struct ParsedInternalKey;
37
class Arena;
38
struct ReadOptions;
39
struct TableProperties;
40
class GetContext;
41
class InternalIterator;
42
class RandomAccessFileReader;
43
class WritableFile;
44
45
// A Table is a sorted map from strings to strings.  Tables are
46
// immutable and persistent.  A Table may be safely accessed from
47
// multiple threads without external synchronization.
48
class TableReader {
49
 public:
50
74.6k
  virtual ~TableReader() {}
51
52
  // Returns whether SST is split into data and metadata files.
53
  virtual bool IsSplitSst() const = 0;
54
55
  // Set data file reader for SST split into data and metadata files.
56
  virtual void SetDataFileReader(std::unique_ptr<RandomAccessFileReader>&& data_file) = 0;
57
58
  // Returns a new iterator over the table contents.
59
  // The result of NewIterator() is initially invalid (caller must
60
  // call one of the Seek methods on the iterator before using it).
61
  // arena: If not null, the arena needs to be used to allocate the Iterator.
62
  //        When destroying the iterator, the caller will not call "delete"
63
  //        but Iterator::~Iterator() directly. The destructor needs to destroy
64
  //        all the states but those allocated in arena.
65
  // skip_filters: disables checking the bloom filters even if they exist. This
66
  //               option is effective only for block-based table format.
67
  virtual InternalIterator* NewIterator(const ReadOptions&,
68
                                        Arena* arena = nullptr,
69
                                        bool skip_filters = false) = 0;
70
71
  // Given a key, return an approximate byte offset in the file where
72
  // the data for that key begins (or would begin if the key were
73
  // present in the file).  The returned value is in terms of file
74
  // bytes, and so includes effects like compression of the underlying data.
75
  // E.g., the approximate offset of the last key in the table will
76
  // be close to the file length.
77
  virtual uint64_t ApproximateOffsetOf(const Slice& key) = 0;
78
79
  // Set up the table for Compaction. Might change some parameters with
80
  // posix_fadvise
81
  virtual void SetupForCompaction() = 0;
82
83
  virtual std::shared_ptr<const TableProperties> GetTableProperties() const = 0;
84
85
  // Prepare work that can be done before the real Get()
86
101k
  virtual void Prepare(const Slice& target) {}
87
88
  // Report an approximation of how much memory has been used.
89
  virtual size_t ApproximateMemoryUsage() const = 0;
90
91
  // Calls get_context->SaveValue() repeatedly, starting with
92
  // the entry found after a call to Seek(key), until it returns false.
93
  // May not make such a call if filter policy says that key is not present.
94
  //
95
  // get_context->MarkKeyMayExist needs to be called when it is configured to be
96
  // memory only and the key is not found in the block cache.
97
  //
98
  // readOptions is the options for the read
99
  // internal_key is the internal key (encoded representation of InternalKey) to search for
100
  // skip_filters: disables checking the bloom filters even if they exist. This
101
  //               option is effective only for block-based table format.
102
  virtual Status Get(const ReadOptions& readOptions, const Slice& internal_key,
103
                     GetContext* get_context, bool skip_filters = false) = 0;
104
105
  // Prefetch data corresponding to a give range of keys
106
  // Typically this functionality is required for table implementations that
107
  // persists the data on a non volatile storage medium like disk/SSD
108
  virtual Status Prefetch(const Slice* begin = nullptr,
109
0
                          const Slice* end = nullptr) {
110
0
    (void) begin;
111
0
    (void) end;
112
0
    // Default implementation is NOOP.
113
0
    // The child class should implement functionality when applicable
114
0
    return Status::OK();
115
0
  }
116
117
  // convert db file to a human readable form
118
0
  virtual Status DumpTable(WritableFile* out_file) {
119
0
    return STATUS(NotSupported, "DumpTable() not supported");
120
0
  }
Unexecuted instantiation: _ZN7rocksdb11TableReader9DumpTableEPNS_12WritableFileE
Unexecuted instantiation: _ZN7rocksdb11TableReader9DumpTableEPNS_12WritableFileE
121
122
  // Returns approximate middle key which divides SST file into two parts containing roughly the
123
  // same amount of keys.
124
0
  virtual yb::Result<std::string> GetMiddleKey() {
125
0
    return STATUS(NotSupported, "GetMiddleKey() not supported");
126
0
  }
Unexecuted instantiation: _ZN7rocksdb11TableReader12GetMiddleKeyEv
Unexecuted instantiation: _ZN7rocksdb11TableReader12GetMiddleKeyEv
127
};
128
129
}  // namespace rocksdb
130
131
#endif  // YB_ROCKSDB_TABLE_TABLE_READER_H