merge_operator.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "merge_operator.h"
  6. #include <memory>
  7. #include <assert.h>
  8. #include "rocksdb/slice.h"
  9. #include "rocksdb/merge_operator.h"
  10. #include "utilities/merge_operators.h"
  11. #include "utilities/cassandra/format.h"
  12. namespace ROCKSDB_NAMESPACE {
  13. namespace cassandra {
  14. // Implementation for the merge operation (merges two Cassandra values)
  15. bool CassandraValueMergeOperator::FullMergeV2(
  16. const MergeOperationInput& merge_in,
  17. MergeOperationOutput* merge_out) const {
  18. // Clear the *new_value for writing.
  19. merge_out->new_value.clear();
  20. std::vector<RowValue> row_values;
  21. if (merge_in.existing_value) {
  22. row_values.push_back(
  23. RowValue::Deserialize(merge_in.existing_value->data(),
  24. merge_in.existing_value->size()));
  25. }
  26. for (auto& operand : merge_in.operand_list) {
  27. row_values.push_back(RowValue::Deserialize(operand.data(), operand.size()));
  28. }
  29. RowValue merged = RowValue::Merge(std::move(row_values));
  30. merged = merged.RemoveTombstones(gc_grace_period_in_seconds_);
  31. merge_out->new_value.reserve(merged.Size());
  32. merged.Serialize(&(merge_out->new_value));
  33. return true;
  34. }
  35. bool CassandraValueMergeOperator::PartialMergeMulti(
  36. const Slice& /*key*/, const std::deque<Slice>& operand_list,
  37. std::string* new_value, Logger* /*logger*/) const {
  38. // Clear the *new_value for writing.
  39. assert(new_value);
  40. new_value->clear();
  41. std::vector<RowValue> row_values;
  42. for (auto& operand : operand_list) {
  43. row_values.push_back(RowValue::Deserialize(operand.data(), operand.size()));
  44. }
  45. RowValue merged = RowValue::Merge(std::move(row_values));
  46. new_value->reserve(merged.Size());
  47. merged.Serialize(new_value);
  48. return true;
  49. }
  50. const char* CassandraValueMergeOperator::Name() const {
  51. return "CassandraValueMergeOperator";
  52. }
  53. } // namespace cassandra
  54. } // namespace ROCKSDB_NAMESPACE