]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/wal_filter.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / wal_filter.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7
8 #include <string>
9 #include <map>
10
11 namespace rocksdb {
12
13 class WriteBatch;
14
15 // WALFilter allows an application to inspect write-ahead-log (WAL)
16 // records or modify their processing on recovery.
17 // Please see the details below.
18 class WalFilter {
19 public:
20 enum class WalProcessingOption {
21 // Continue processing as usual
22 kContinueProcessing = 0,
23 // Ignore the current record but continue processing of log(s)
24 kIgnoreCurrentRecord = 1,
25 // Stop replay of logs and discard logs
26 // Logs won't be replayed on subsequent recovery
27 kStopReplay = 2,
28 // Corrupted record detected by filter
29 kCorruptedRecord = 3,
30 // Marker for enum count
31 kWalProcessingOptionMax = 4
32 };
33
34 virtual ~WalFilter() {}
35
36 // Provide ColumnFamily->LogNumber map to filter
37 // so that filter can determine whether a log number applies to a given
38 // column family (i.e. that log hasn't been flushed to SST already for the
39 // column family).
40 // We also pass in name->id map as only name is known during
41 // recovery (as handles are opened post-recovery).
42 // while write batch callbacks happen in terms of column family id.
43 //
44 // @params cf_lognumber_map column_family_id to lognumber map
45 // @params cf_name_id_map column_family_name to column_family_id map
46
47 virtual void ColumnFamilyLogNumberMap(
48 const std::map<uint32_t, uint64_t>& /*cf_lognumber_map*/,
49 const std::map<std::string, uint32_t>& /*cf_name_id_map*/) {}
50
51 // LogRecord is invoked for each log record encountered for all the logs
52 // during replay on logs on recovery. This method can be used to:
53 // * inspect the record (using the batch parameter)
54 // * ignoring current record
55 // (by returning WalProcessingOption::kIgnoreCurrentRecord)
56 // * reporting corrupted record
57 // (by returning WalProcessingOption::kCorruptedRecord)
58 // * stop log replay
59 // (by returning kStop replay) - please note that this implies
60 // discarding the logs from current record onwards.
61 //
62 // @params log_number log_number of the current log.
63 // Filter might use this to determine if the log
64 // record is applicable to a certain column family.
65 // @params log_file_name log file name - only for informational purposes
66 // @params batch batch encountered in the log during recovery
67 // @params new_batch new_batch to populate if filter wants to change
68 // the batch (for example to filter some records out,
69 // or alter some records).
70 // Please note that the new batch MUST NOT contain
71 // more records than original, else recovery would
72 // be failed.
73 // @params batch_changed Whether batch was changed by the filter.
74 // It must be set to true if new_batch was populated,
75 // else new_batch has no effect.
76 // @returns Processing option for the current record.
77 // Please see WalProcessingOption enum above for
78 // details.
79 virtual WalProcessingOption LogRecordFound(
80 unsigned long long /*log_number*/, const std::string& /*log_file_name*/,
81 const WriteBatch& batch, WriteBatch* new_batch, bool* batch_changed) {
82 // Default implementation falls back to older function for compatibility
83 return LogRecord(batch, new_batch, batch_changed);
84 }
85
86 // Please see the comments for LogRecord above. This function is for
87 // compatibility only and contains a subset of parameters.
88 // New code should use the function above.
89 virtual WalProcessingOption LogRecord(const WriteBatch& /*batch*/,
90 WriteBatch* /*new_batch*/,
91 bool* /*batch_changed*/) const {
92 return WalProcessingOption::kContinueProcessing;
93 }
94
95 // Returns a name that identifies this WAL filter.
96 // The name will be printed to LOG file on start up for diagnosis.
97 virtual const char* Name() const = 0;
98 };
99
100 } // namespace rocksdb