1 // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 /**
3  * A TEST MergeOperator for rocksdb that implements string append.
4  * It is built using the MergeOperator interface rather than the simpler
5  * AssociativeMergeOperator interface. This is useful for testing/benchmarking.
6  * While the two operators are semantically the same, all production code
7  * should use the StringAppendOperator defined in stringappend.{h,cc}. The
8  * operator defined in the present file is primarily for testing.
9  *
10  * @author Deon Nicholas (dnicholas@fb.com)
11  * Copyright 2013 Facebook
12  */
13 
14 #pragma once
15 #include <deque>
16 #include <string>
17 
18 #include "rocksdb/merge_operator.h"
19 #include "rocksdb/slice.h"
20 
21 namespace rocksdb {
22 
23 class StringAppendTESTOperator : public MergeOperator {
24  public:
25   // Constructor with delimiter
26   explicit StringAppendTESTOperator(char delim_char);
27 
28   virtual bool FullMergeV2(const MergeOperationInput& merge_in,
29                            MergeOperationOutput* merge_out) const override;
30 
31   virtual bool PartialMergeMulti(const Slice& key,
32                                  const std::deque<Slice>& operand_list,
33                                  std::string* new_value, Logger* logger) const
34       override;
35 
36   virtual const char* Name() const override;
37 
38  private:
39   // A version of PartialMerge that actually performs "partial merging".
40   // Use this to simulate the exact behaviour of the StringAppendOperator.
41   bool _AssocPartialMergeMulti(const Slice& key,
42                                const std::deque<Slice>& operand_list,
43                                std::string* new_value, Logger* logger) const;
44 
45   char delim_;         // The delimiter is inserted between elements
46 
47 };
48 
49 } // namespace rocksdb
50