merge_operator.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2017-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. #pragma once
  6. #include "rocksdb/merge_operator.h"
  7. #include "rocksdb/slice.h"
  8. namespace ROCKSDB_NAMESPACE {
  9. namespace cassandra {
  10. /**
  11. * A MergeOperator for rocksdb that implements Cassandra row value merge.
  12. */
  13. class CassandraValueMergeOperator : public MergeOperator {
  14. public:
  15. explicit CassandraValueMergeOperator(int32_t gc_grace_period_in_seconds,
  16. size_t operands_limit = 0)
  17. : gc_grace_period_in_seconds_(gc_grace_period_in_seconds),
  18. operands_limit_(operands_limit) {}
  19. virtual bool FullMergeV2(const MergeOperationInput& merge_in,
  20. MergeOperationOutput* merge_out) const override;
  21. virtual bool PartialMergeMulti(const Slice& key,
  22. const std::deque<Slice>& operand_list,
  23. std::string* new_value,
  24. Logger* logger) const override;
  25. virtual const char* Name() const override;
  26. virtual bool AllowSingleOperand() const override { return true; }
  27. virtual bool ShouldMerge(const std::vector<Slice>& operands) const override {
  28. return operands_limit_ > 0 && operands.size() >= operands_limit_;
  29. }
  30. private:
  31. int32_t gc_grace_period_in_seconds_;
  32. size_t operands_limit_;
  33. };
  34. } // namespace cassandra
  35. } // namespace ROCKSDB_NAMESPACE