stringappend2.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #pragma once
  14. #include <deque>
  15. #include <string>
  16. #include "rocksdb/merge_operator.h"
  17. #include "rocksdb/slice.h"
  18. namespace ROCKSDB_NAMESPACE {
  19. class StringAppendTESTOperator : public MergeOperator {
  20. public:
  21. // Constructor with delimiter
  22. explicit StringAppendTESTOperator(char delim_char);
  23. virtual bool FullMergeV2(const MergeOperationInput& merge_in,
  24. MergeOperationOutput* merge_out) const override;
  25. virtual bool PartialMergeMulti(const Slice& key,
  26. const std::deque<Slice>& operand_list,
  27. std::string* new_value, Logger* logger) const
  28. override;
  29. virtual const char* Name() const override;
  30. private:
  31. // A version of PartialMerge that actually performs "partial merging".
  32. // Use this to simulate the exact behaviour of the StringAppendOperator.
  33. bool _AssocPartialMergeMulti(const Slice& key,
  34. const std::deque<Slice>& operand_list,
  35. std::string* new_value, Logger* logger) const;
  36. char delim_; // The delimiter is inserted between elements
  37. };
  38. } // namespace ROCKSDB_NAMESPACE