-
Notifications
You must be signed in to change notification settings - Fork 631
feat(cf): add cf.add command #3481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nagisa-kunhah
wants to merge
46
commits into
apache:unstable
Choose a base branch
from
nagisa-kunhah:feature/3351-cf-add-ci-fix
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,486
−7
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
1e98a87
feat: Implement CF.RESERVE command with bucket-based storage
LiuQhahah 577ee71
feat: Implement CF.RESERVE command with bucket-based storage
LiuQhahah 77b4c4a
feat: Implement CF.RESERVE command with bucket-based storage
LiuQhahah 025ee86
feat: Implement CF.RESERVE command with bucket-based storage
LiuQhahah 6a018df
Merge branch 'unstable' into feature/3122-cf-reserve-bucket-storage
LiuQhahah 1fe2c6f
feat: Implement CF.ADD command with kick-out insertion
LiuQhahah f50125c
trigger CI checks
LiuQhahah 65664fe
style: Apply clang-format to cuckoo filter files
LiuQhahah 73ba1d4
fix: Correct WriteBatchLogData constructor calls in CuckooChain
LiuQhahah 7401065
Merge branch 'unstable' into feature/3351-cf-add
LiuQhahah 9ddfc83
fix: ci
nagisa-kunhah a361dd9
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah 543e459
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
jihuayu 4ef241f
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah c89f2de
fix: ci
nagisa-kunhah 00abd42
fix: loses atomicity
nagisa-kunhah 67f4c0d
fix: create new filter in CuckooChain::Add when key is not found
nagisa-kunhah 23beb86
optimize test
nagisa-kunhah 1ade399
fix: lint
nagisa-kunhah da03915
feat: CuckooPageSet
nagisa-kunhah adf0ff0
fix: lint
nagisa-kunhah cb91f43
optimize code
nagisa-kunhah 343ff28
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah d924d0a
fix: ci
nagisa-kunhah 87b8bdd
fix: ci
nagisa-kunhah 382670f
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah 7005105
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
aleksraiden b605d74
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
jihuayu f231a60
fix: part1
nagisa-kunhah 2edeaa0
rename: CuckooFilter->CuckooFilterHelper
nagisa-kunhah 6509d05
feat: CuckooSubFilter
nagisa-kunhah 8a88aa9
remove: comment
nagisa-kunhah ced9bc6
fix: MBbloomCF
nagisa-kunhah 9d7f5e8
fix: CuckooPageSet->CuckooPageCache
nagisa-kunhah 3c5c3a7
fix: ci
nagisa-kunhah dc4fe95
optimize CuckooPageCache
nagisa-kunhah f3f4493
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah 2fd2b3b
fix:
nagisa-kunhah 7fd5abb
optimize code
nagisa-kunhah 58abab9
fix: split add into three phase
nagisa-kunhah 5fd065f
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah cc2cc1b
fix: sematic for the TryKickOutInsert
nagisa-kunhah 98cbb54
rename: Discard->DiscardCachedPages
nagisa-kunhah a9364c4
restore: scan test
nagisa-kunhah e0435dd
add: cf scan test
nagisa-kunhah 67ad024
Merge branch 'unstable' into feature/3351-cf-add-ci-fix
nagisa-kunhah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * 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 "command_parser.h" | ||
| #include "commander.h" | ||
| #include "error_constants.h" | ||
| #include "server/server.h" | ||
| #include "types/redis_cuckoo_chain.h" | ||
|
|
||
| namespace redis { | ||
|
|
||
| class CommandCFReserve : public Commander { | ||
| public: | ||
| Status Parse(const std::vector<std::string> &args) override { | ||
| // CF.RESERVE key capacity [BUCKETSIZE bs] [MAXITERATIONS mi] [EXPANSION ex] | ||
| if (args.size() < 3) { | ||
| return {Status::RedisParseErr, errWrongNumOfArguments}; | ||
| } | ||
|
|
||
| // Parse capacity (required) | ||
| auto parse_capacity = ParseInt<uint64_t>(args[2], 10); | ||
| if (!parse_capacity) { | ||
| return {Status::RedisParseErr, "invalid capacity"}; | ||
| } | ||
| capacity_ = *parse_capacity; | ||
| if (capacity_ <= 0) { | ||
| return {Status::RedisParseErr, "capacity must be larger than 0"}; | ||
| } | ||
|
|
||
| // Parse optional parameters | ||
| CommandParser parser(args, 3); | ||
| while (parser.Good()) { | ||
| if (parser.EatEqICase("BUCKETSIZE")) { | ||
| auto parse_bucket_size = parser.TakeInt<uint8_t>(); | ||
| if (!parse_bucket_size.IsOK()) { | ||
| return {Status::RedisParseErr, "invalid bucket size"}; | ||
| } | ||
| bucket_size_ = parse_bucket_size.GetValue(); | ||
| if (bucket_size_ == 0 || bucket_size_ > 255) { | ||
| return {Status::RedisParseErr, "bucket size must be between 1 and 255"}; | ||
| } | ||
| } else if (parser.EatEqICase("MAXITERATIONS")) { | ||
| auto parse_max_iterations = parser.TakeInt<uint16_t>(); | ||
| if (!parse_max_iterations.IsOK()) { | ||
| return {Status::RedisParseErr, "invalid max iterations"}; | ||
| } | ||
| max_iterations_ = parse_max_iterations.GetValue(); | ||
| if (max_iterations_ == 0) { | ||
| return {Status::RedisParseErr, "max iterations must be larger than 0"}; | ||
| } | ||
| } else if (parser.EatEqICase("EXPANSION")) { | ||
| auto parse_expansion = parser.TakeInt<uint16_t>(); | ||
| if (!parse_expansion.IsOK()) { | ||
| return {Status::RedisParseErr, "invalid expansion factor"}; | ||
| } | ||
| expansion_ = parse_expansion.GetValue(); | ||
| if (expansion_ > kCFMaxExpansion) { | ||
| return {Status::RedisParseErr, "expansion must be between 0 and 32768"}; | ||
| } | ||
| } else { | ||
| return {Status::RedisParseErr, errInvalidSyntax}; | ||
| } | ||
| } | ||
|
|
||
| return Commander::Parse(args); | ||
| } | ||
|
|
||
| Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override { | ||
| redis::CuckooChain cuckoo_db(srv->storage, conn->GetNamespace()); | ||
| auto s = cuckoo_db.Reserve(ctx, args_[1], capacity_, bucket_size_, max_iterations_, expansion_, | ||
| kCuckooFilterDefaultPageSize); | ||
|
|
||
| if (!s.ok()) { | ||
| if (s.IsInvalidArgument()) { | ||
| // Return error message to client | ||
| return {Status::RedisExecErr, s.ToString()}; | ||
| } | ||
| return {Status::RedisExecErr, "failed to create cuckoo filter"}; | ||
| } | ||
|
|
||
| *output = redis::SimpleString("OK"); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| private: | ||
| uint64_t capacity_ = kCFDefaultCapacity; | ||
| uint8_t bucket_size_ = kCFDefaultBucketSize; | ||
| uint16_t max_iterations_ = kCFDefaultMaxIterations; | ||
| uint16_t expansion_ = kCFDefaultExpansion; | ||
| }; | ||
|
|
||
| class CommandCFAdd : public Commander { | ||
| public: | ||
| Status Parse(const std::vector<std::string> &args) override { | ||
| // CF.ADD key item | ||
| if (args.size() != 3) { | ||
| return {Status::RedisParseErr, errWrongNumOfArguments}; | ||
| } | ||
| return Commander::Parse(args); | ||
| } | ||
|
|
||
| Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override { | ||
| redis::CuckooChain cuckoo_db(srv->storage, conn->GetNamespace()); | ||
| bool added = false; | ||
| auto s = cuckoo_db.Add(ctx, args_[1], args_[2], &added); | ||
|
|
||
| if (!s.ok()) { | ||
| return {Status::RedisExecErr, s.ToString()}; | ||
| } | ||
|
|
||
| // Duplicate items are allowed, so successful insertions return 1. | ||
| *output = redis::Integer(added ? 1 : 0); | ||
| return Status::OK(); | ||
| } | ||
| }; | ||
|
|
||
| // Register the CF.RESERVE and CF.ADD commands | ||
| REDIS_REGISTER_COMMANDS(CuckooFilter, MakeCmdAttr<CommandCFReserve>("cf.reserve", -3, "write", 1, 1, 1), | ||
| MakeCmdAttr<CommandCFAdd>("cf.add", 3, "write", 1, 1, 1)) | ||
|
|
||
| } // namespace redis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.