put_operator.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // A merge operator that mimics Put semantics
  7. // Since this merge-operator will not be used in production,
  8. // it is implemented as a non-associative merge operator to illustrate the
  9. // new interface and for testing purposes. (That is, we inherit from
  10. // the MergeOperator class rather than the AssociativeMergeOperator
  11. // which would be simpler in this case).
  12. //
  13. // From the client-perspective, semantics are the same.
  14. #pragma once
  15. #include "rocksdb/merge_operator.h"
  16. namespace ROCKSDB_NAMESPACE {
  17. class Logger;
  18. class Slice;
  19. class PutOperator : public MergeOperator {
  20. public:
  21. static const char* kClassName() { return "PutOperator"; }
  22. static const char* kNickName() { return "put_v1"; }
  23. const char* Name() const override { return kClassName(); }
  24. const char* NickName() const override { return kNickName(); }
  25. bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
  26. const std::deque<std::string>& operand_sequence,
  27. std::string* new_value, Logger* /*logger*/) const override;
  28. bool PartialMerge(const Slice& /*key*/, const Slice& left_operand,
  29. const Slice& right_operand, std::string* new_value,
  30. Logger* /*logger*/) const override;
  31. using MergeOperator::PartialMergeMulti;
  32. bool PartialMergeMulti(const Slice& /*key*/,
  33. const std::deque<Slice>& operand_list,
  34. std::string* new_value,
  35. Logger* /*logger*/) const override;
  36. };
  37. class PutOperatorV2 : public PutOperator {
  38. public:
  39. static const char* kNickName() { return "put"; }
  40. const char* NickName() const override { return kNickName(); }
  41. bool FullMerge(const Slice& /*key*/, const Slice* /*existing_value*/,
  42. const std::deque<std::string>& /*operand_sequence*/,
  43. std::string* /*new_value*/, Logger* /*logger*/) const override;
  44. bool FullMergeV2(const MergeOperationInput& merge_in,
  45. MergeOperationOutput* merge_out) const override;
  46. };
  47. } // namespace ROCKSDB_NAMESPACE