YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/slice_transform.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
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
6
// Use of this source code is governed by a BSD-style license that can be
7
// found in the LICENSE file. See the AUTHORS file for names of contributors.
8
//
9
// The following only applies to changes made to this file as part of YugaByte development.
10
//
11
// Portions Copyright (c) YugaByte, Inc.
12
//
13
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
14
// in compliance with the License.  You may obtain a copy of the License at
15
//
16
// http://www.apache.org/licenses/LICENSE-2.0
17
//
18
// Unless required by applicable law or agreed to in writing, software distributed under the License
19
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
20
// or implied.  See the License for the specific language governing permissions and limitations
21
// under the License.
22
//
23
// Class for specifying user-defined functions which perform a
24
// transformation on a slice.  It is not required that every slice
25
// belong to the domain and/or range of a function.  Subclasses should
26
// define InDomain and InRange to determine which slices are in either
27
// of these sets respectively.
28
29
#ifndef ROCKSDB_INCLUDE_ROCKSDB_SLICE_TRANSFORM_H
30
#define ROCKSDB_INCLUDE_ROCKSDB_SLICE_TRANSFORM_H
31
32
#include <string>
33
34
#include "yb/util/slice.h"
35
36
namespace rocksdb {
37
38
class SliceTransform {
39
 public:
40
66.5k
  virtual ~SliceTransform() {}
41
42
  // Return the name of this transformation.
43
  virtual const char* Name() const = 0;
44
45
  // transform a src in domain to a dst in the range
46
  virtual Slice Transform(const Slice& src) const = 0;
47
48
  // determine whether this is a valid src upon the function applies
49
  virtual bool InDomain(const Slice& src) const = 0;
50
51
  // determine whether dst=Transform(src) for some src
52
  virtual bool InRange(const Slice& dst) const = 0;
53
54
  // Transform(s)=Transform(`prefix`) for any s with `prefix` as a prefix.
55
  //
56
  // This function is not used by RocksDB, but for users. If users pass
57
  // Options by string to RocksDB, they might not know what prefix extractor
58
  // they are using. This function is to help users can determine:
59
  //   if they want to iterate all keys prefixing `prefix`, whetherit is
60
  //   safe to use prefix bloom filter and seek to key `prefix`.
61
  // If this function returns true, this means a user can Seek() to a prefix
62
  // using the bloom filter. Otherwise, user needs to skip the bloom filter
63
  // by setting ReadOptions.total_order_seek = true.
64
  //
65
  // Here is an example: Suppose we implement a slice transform that returns
66
  // the first part of the string after spliting it using deimiter ",":
67
  // 1. SameResultWhenAppended("abc,") should return true. If aplying prefix
68
  //    bloom filter using it, all slices matching "abc:.*" will be extracted
69
  //    to "abc,", so any SST file or memtable containing any of those key
70
  //    will not be filtered out.
71
  // 2. SameResultWhenAppended("abc") should return false. A user will not
72
  //    guaranteed to see all the keys matching "abc.*" if a user seek to "abc"
73
  //    against a DB with the same setting. If one SST file only contains
74
  //    "abcd,e", the file can be filtered out and the key will be invisible.
75
  //
76
  // i.e., an implementation always returning false is safe.
77
0
  virtual bool SameResultWhenAppended(const Slice& prefix) const {
78
0
    return false;
79
0
  }
80
};
81
82
extern const SliceTransform* NewFixedPrefixTransform(size_t prefix_len);
83
84
extern const SliceTransform* NewCappedPrefixTransform(size_t cap_len);
85
86
extern const SliceTransform* NewNoopTransform();
87
88
} // namespace rocksdb
89
90
#endif // ROCKSDB_INCLUDE_ROCKSDB_SLICE_TRANSFORM_H