stringappend2.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. explicit StringAppendTESTOperator(const std::string& delim);
  24. bool FullMergeV2(const MergeOperationInput& merge_in,
  25. MergeOperationOutput* merge_out) const override;
  26. bool PartialMergeMulti(const Slice& key,
  27. const std::deque<Slice>& operand_list,
  28. std::string* new_value, Logger* logger) const override;
  29. static const char* kClassName() { return "StringAppendTESTOperator"; }
  30. static const char* kNickName() { return "stringappendtest"; }
  31. const char* Name() const override { return kClassName(); }
  32. const char* NickName() const override { return kNickName(); }
  33. private:
  34. // A version of PartialMerge that actually performs "partial merging".
  35. // Use this to simulate the exact behaviour of the StringAppendOperator.
  36. bool _AssocPartialMergeMulti(const Slice& key,
  37. const std::deque<Slice>& operand_list,
  38. std::string* new_value, Logger* logger) const;
  39. std::string delim_; // The delimiter is inserted between elements
  40. };
  41. } // namespace ROCKSDB_NAMESPACE