zncleon commented on code in PR #1699: URL: https://github.com/apache/kvrocks/pull/1699#discussion_r1305210272
########## src/types/redis_sb_chain.cc: ########## @@ -0,0 +1,240 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "redis_sb_chain.h" + +namespace redis { + +void SBChain::appendBFSuffix(const Slice &ns_key, uint16_t filters_index, std::string *output) { + output->clear(); + + output->append(ns_key.data(), ns_key.size()); + output->append(kBloomFilterSeparator); + PutFixed16(output, filters_index); +} + +void SBChain ::appendBFMetaSuffix(const Slice &bf_key, std::string *output) { + output->clear(); + + output->append(bf_key.data(), bf_key.size()); + output->append(kBloomFilterSeparator); + output->append("meta"); +} + +void SBChain::bfInit(BFMetadata *bf_metadata, std::string *bf_data, uint32_t entries, double error) { + bf_metadata->entries = entries; + bf_metadata->error = error; + bf_metadata->size = 0; + + uint32_t bf_bytes = BlockSplitBloomFilter::OptimalNumOfBytes(entries, error); + bf_metadata->bf_bytes = bf_bytes; + + BlockSplitBloomFilter block_split_bloom_filter; + block_split_bloom_filter.Init(bf_bytes); + *bf_data = block_split_bloom_filter.GetData(); +} + +rocksdb::Status SBChain::getSBChainMetadata(const Slice &ns_key, SBChainMetadata *metadata) { + return Database::GetMetadata(kRedisBloomFilter, ns_key, metadata); +} + +rocksdb::Status SBChain::getBFMetadata(const Slice &bf_meta_key, BFMetadata *metadata) { + LatestSnapShot ss(storage_); + rocksdb::ReadOptions read_options; + read_options.snapshot = ss.GetSnapShot(); + std::string bytes; + auto s = storage_->Get(read_options, bf_meta_key, &bytes); + + std::string old_metadata; + metadata->Encode(&old_metadata); Review Comment: It’s just like the function `getMetadata`. I think if run error(expired or other), metadata will just return the old_metadata ########## src/types/redis_sb_chain.cc: ########## @@ -0,0 +1,240 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "redis_sb_chain.h" + +namespace redis { + +void SBChain::appendBFSuffix(const Slice &ns_key, uint16_t filters_index, std::string *output) { + output->clear(); + + output->append(ns_key.data(), ns_key.size()); + output->append(kBloomFilterSeparator); + PutFixed16(output, filters_index); +} + +void SBChain ::appendBFMetaSuffix(const Slice &bf_key, std::string *output) { + output->clear(); + + output->append(bf_key.data(), bf_key.size()); + output->append(kBloomFilterSeparator); + output->append("meta"); +} + +void SBChain::bfInit(BFMetadata *bf_metadata, std::string *bf_data, uint32_t entries, double error) { + bf_metadata->entries = entries; + bf_metadata->error = error; + bf_metadata->size = 0; + + uint32_t bf_bytes = BlockSplitBloomFilter::OptimalNumOfBytes(entries, error); + bf_metadata->bf_bytes = bf_bytes; + + BlockSplitBloomFilter block_split_bloom_filter; + block_split_bloom_filter.Init(bf_bytes); + *bf_data = block_split_bloom_filter.GetData(); +} + +rocksdb::Status SBChain::getSBChainMetadata(const Slice &ns_key, SBChainMetadata *metadata) { + return Database::GetMetadata(kRedisBloomFilter, ns_key, metadata); +} + +rocksdb::Status SBChain::getBFMetadata(const Slice &bf_meta_key, BFMetadata *metadata) { + LatestSnapShot ss(storage_); + rocksdb::ReadOptions read_options; + read_options.snapshot = ss.GetSnapShot(); + std::string bytes; + auto s = storage_->Get(read_options, bf_meta_key, &bytes); + + std::string old_metadata; + metadata->Encode(&old_metadata); Review Comment: It’s just like the function `getMetadata`. I think if run error(expired or other), metadata will just return the old_metadata -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
