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 "rocksdb/status.h"
9 
10 namespace ROCKSDB_NAMESPACE {
11 
12 class DB;
13 
14 class PreReleaseCallback {
15  public:
~PreReleaseCallback()16   virtual ~PreReleaseCallback() {}
17 
18   // Will be called while on the write thread after the write to the WAL and
19   // before the write to memtable. This is useful if any operation needs to be
20   // done before the write gets visible to the readers, or if we want to reduce
21   // the overhead of locking by updating something sequentially while we are on
22   // the write thread. If the callback fails, this function returns a non-OK
23   // status, the sequence number will not be released, and same status will be
24   // propagated to all the writers in the write group.
25   // seq is the sequence number that is used for this write and will be
26   // released.
27   // is_mem_disabled is currently used for debugging purposes to assert that
28   // the callback is done from the right write queue.
29   // If non-zero, log_number indicates the WAL log to which we wrote.
30   // index >= 0 specifies the order of callback in the same write thread.
31   // total > index specifies the total number of callbacks in the same write
32   // thread. Together with index, could be used to reduce the redundant
33   // operations among the callbacks.
34   virtual Status Callback(SequenceNumber seq, bool is_mem_disabled,
35                           uint64_t log_number, size_t index, size_t total) = 0;
36 };
37 
38 }  // namespace ROCKSDB_NAMESPACE
39