YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/wal_filter.h
Line
Count
Source
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
21
#pragma once
22
23
namespace rocksdb {
24
25
class WriteBatch;
26
27
// WALFilter allows an application to inspect write-ahead-log (WAL)
28
// records or modify their processing on recovery.
29
// Please see the details below.
30
class WalFilter {
31
 public:
32
  enum class WalProcessingOption {
33
    // Continue processing as usual
34
    kContinueProcessing = 0,
35
    // Ignore the current record but continue processing of log(s)
36
    kIgnoreCurrentRecord = 1,
37
    // Stop replay of logs and discard logs
38
    // Logs won't be replayed on subsequent recovery
39
    kStopReplay = 2,
40
    // Corrupted record detected by filter
41
    kCorruptedRecord = 3,
42
    // Marker for enum count
43
    kWalProcessingOptionMax = 4
44
  };
45
46
6
  virtual ~WalFilter() {}
47
48
  // LogRecord is invoked for each log record encountered for all the logs
49
  // during replay on logs on recovery. This method can be used to:
50
  //  * inspect the record (using the batch parameter)
51
  //  * ignoring current record
52
  //    (by returning WalProcessingOption::kIgnoreCurrentRecord)
53
  //  * reporting corrupted record
54
  //    (by returning WalProcessingOption::kCorruptedRecord)
55
  //  * stop log replay
56
  //    (by returning kStop replay) - please note that this implies
57
  //    discarding the logs from current record onwards.
58
  //
59
  // @params batch          batch encountered in the log during recovery
60
  // @params new_batch      new_batch to populate if filter wants to change
61
  //                        the batch (for example to filter some records out,
62
  //                        or alter some records).
63
  //                        Please note that the new batch MUST NOT contain
64
  //                        more records than original, else recovery would
65
  //                        be failed.
66
  // @params batch_changed  Whether batch was changed by the filter.
67
  //                        It must be set to true if new_batch was populated,
68
  //                        else new_batch has no effect.
69
  // @returns               Processing option for the current record.
70
  //                        Please see WalProcessingOption enum above for
71
  //                        details.
72
  virtual WalProcessingOption LogRecord(const WriteBatch& batch,
73
                                        WriteBatch* new_batch,
74
                                        bool* batch_changed) const = 0;
75
76
  // Returns a name that identifies this WAL filter.
77
  // The name will be printed to LOG file on start up for diagnosis.
78
  virtual const char* Name() const = 0;
79
};
80
81
}  // namespace rocksdb