merge_operator.h 1.5 KB

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