Skip to content

Commit f7dd87e

Browse files
add merge operator
1 parent ec2e2d0 commit f7dd87e

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

src/storage/hash_merge_operator.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
*/
20+
21+
#include "storage/hash_merge_operator.h"
22+
23+
#include "storage/redis_metadata.h"
24+
25+
namespace engine {
26+
27+
bool HashMergeOperator::Merge(const rocksdb::Slice& key, const rocksdb::Slice* existing_value,
28+
const rocksdb::Slice& value, std::string* new_value, rocksdb::Logger* logger) const {
29+
if (new_value == nullptr) {
30+
return false;
31+
}
32+
33+
new_value->assign(value.data(), value.size());
34+
35+
return true;
36+
}
37+
38+
const char* HashMergeOperator::Name() const { return "HashMergeOperator"; }
39+
40+
} // namespace engine

src/storage/hash_merge_operator.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
*/
20+
21+
#pragma once
22+
23+
#include <rocksdb/merge_operator.h>
24+
25+
namespace engine {
26+
27+
class HashMergeOperator : public rocksdb::AssociativeMergeOperator {
28+
public:
29+
bool Merge(const rocksdb::Slice& key, const rocksdb::Slice* existing_value, const rocksdb::Slice& value,
30+
std::string* new_value, rocksdb::Logger* logger) const override;
31+
32+
const char* Name() const override;
33+
};
34+
35+
} // namespace engine

src/storage/storage.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "rocksdb_crc32c.h"
4949
#include "server/server.h"
5050
#include "storage/batch_indexer.h"
51+
#include "storage/hash_merge_operator.h"
5152
#include "string_util.h"
5253
#include "table_properties_collector.h"
5354
#include "time_util.h"
@@ -338,6 +339,7 @@ Status Storage::Open(DBOpenMode mode) {
338339
subkey_opts.disable_auto_compactions = config_->rocks_db.disable_auto_compactions;
339340
subkey_opts.table_properties_collector_factories.emplace_back(
340341
NewCompactOnExpiredTableCollectorFactory(std::string(kPrimarySubkeyColumnFamilyName), 0.3));
342+
subkey_opts.merge_operator = std::make_shared<HashMergeOperator>();
341343
SetBlobDB(&subkey_opts);
342344

343345
rocksdb::BlockBasedTableOptions pubsub_table_opts = InitTableOptions();

0 commit comments

Comments
 (0)