feat(tdigest): add TDIGEST.CREATE and TDIGEST.INFO command#2799
feat(tdigest): add TDIGEST.CREATE and TDIGEST.INFO command#2799PragmaTwice merged 11 commits intoapache:unstablefrom
Conversation
src/commands/cmd_tdigest.cc
Outdated
| if (args.size() != 2) { | ||
| return {Status::RedisParseErr, kErrWrongNumOfInfoArguments}; | ||
| } |
There was a problem hiding this comment.
| if (args.size() != 2) { | |
| return {Status::RedisParseErr, kErrWrongNumOfInfoArguments}; | |
| } |
There was a problem hiding this comment.
src/commands/cmd_tdigest.cc
Outdated
| output->append(redis::BulkString(kInfoMemoryUsage)); | ||
| output->append(redis::Integer(sizeof(TDigest))); |
There was a problem hiding this comment.
It seems this is not so useful, and also, not so accurate. Maybe we can just remove this.
There was a problem hiding this comment.
Hi @PragmaTwice ,
Thanks for your suggestion! 😊
I have removed this property and left a comment line in code and test case.
Best Regards,
Edward
src/commands/cmd_tdigest.cc
Outdated
| bool invalid_keyword = false; | ||
| if (args.size() != 2 && (args.size() != 4 || (invalid_keyword = !util::EqualICase(kCompressionArg, args[2])))) { | ||
| return {Status::RedisParseErr, invalid_keyword ? kErrWrongKeyword : kErrWrongNumOfCreateArguments}; | ||
| } | ||
| if (parser.EatEqICase(kCompressionArg)) { | ||
| auto status = parser.TakeInt<int32_t>(); | ||
| if (!status) { | ||
| return {Status::RedisParseErr, kErrParseCompression}; | ||
| } | ||
| auto compression = *status; | ||
| if (compression <= 0) { | ||
| return {Status::RedisParseErr, kErrCompressionMustBePositive}; | ||
| } | ||
| if (compression < 1 || compression > static_cast<int32_t>(kTDigestMaxCompression)) { | ||
| return {Status::RedisParseErr, kErrCompressionOutOfRange}; | ||
| } | ||
| options_.compression = static_cast<uint32_t>(compression); | ||
| } |
There was a problem hiding this comment.
| bool invalid_keyword = false; | |
| if (args.size() != 2 && (args.size() != 4 || (invalid_keyword = !util::EqualICase(kCompressionArg, args[2])))) { | |
| return {Status::RedisParseErr, invalid_keyword ? kErrWrongKeyword : kErrWrongNumOfCreateArguments}; | |
| } | |
| if (parser.EatEqICase(kCompressionArg)) { | |
| auto status = parser.TakeInt<int32_t>(); | |
| if (!status) { | |
| return {Status::RedisParseErr, kErrParseCompression}; | |
| } | |
| auto compression = *status; | |
| if (compression <= 0) { | |
| return {Status::RedisParseErr, kErrCompressionMustBePositive}; | |
| } | |
| if (compression < 1 || compression > static_cast<int32_t>(kTDigestMaxCompression)) { | |
| return {Status::RedisParseErr, kErrCompressionOutOfRange}; | |
| } | |
| options_.compression = static_cast<uint32_t>(compression); | |
| } | |
| if (parser.EatEqICase(kCompressionArg)) { | |
| auto status = parser.TakeInt<int32_t>(); | |
| if (!status) { | |
| return {Status::RedisParseErr, kErrParseCompression}; | |
| } | |
| auto compression = *status; | |
| if (compression <= 0) { | |
| return {Status::RedisParseErr, kErrCompressionMustBePositive}; | |
| } | |
| if (compression < 1 || compression > static_cast<int32_t>(kTDigestMaxCompression)) { | |
| return {Status::RedisParseErr, kErrCompressionOutOfRange}; | |
| } | |
| options_.compression = static_cast<uint32_t>(compression); | |
| } | |
| if (parser.Good()) { | |
| return ... // invalid arguments | |
| } |
There was a problem hiding this comment.
Hi @PragmaTwice ,
Thanks for your advice! 😊
I have refactored the block with parser.Good().
Best Regards,
Edward
src/commands/cmd_tdigest.cc
Outdated
| namespace redis { | ||
| namespace { | ||
| constexpr auto kCompressionArg = "compression"; | ||
| constexpr auto kErrWrongKeyword = "T-Digest: wrong keyword"; |
There was a problem hiding this comment.
We could remove the prefix(T-Digest) in the error message to be consistent with other commands. Users should know the context according to the command they sent, so that we can avoid creating a dedicated error message for each command.
There was a problem hiding this comment.
Hi @git-hulk ,
Got it! Thanks for your suggestions! 😊
I have removed all T-Digest: prefixes from error message.
Best Regards,
Edward
8b92ed4 to
3622c1d
Compare
|
|
||
| namespace redis { | ||
| namespace { | ||
| constexpr auto kCompressionArg = "compression"; |
There was a problem hiding this comment.
Could put those error messages into https://github.com/apache/kvrocks/blob/9d2fcdef3bdff9f01451ae72491b3a438b9e6a2f/src/commands/error_constants.h, sorry for forgetting to mention this in the last review. Others are good to me, thanks for your contribution.
There was a problem hiding this comment.
src/commands/cmd_tdigest.cc
Outdated
| parser.RawTake(); | ||
| return {Status::RedisParseErr, parser.Good() ? kErrWrongKeyword : kErrWrongNumOfArguments}; |
There was a problem hiding this comment.
| parser.RawTake(); | |
| return {Status::RedisParseErr, parser.Good() ? kErrWrongKeyword : kErrWrongNumOfArguments}; | |
| return {Status::RedisParseErr, kErrWrongNumOfArguments}; |
There was a problem hiding this comment.
Hi @PragmaTwice ,
Thanks for your suggestion! 😊
I have simplified the logic as suggested.
Best Regards,
Edward
| // require.NoError(t, rdb.Do(ctx, "TDIGEST.CREATE", keyPrefix+"key1", "compression", "1000").Err()) | ||
| // rsp = rdb.Do(ctx, "TDIGEST.INFO", keyPrefix+"key1") | ||
| // require.NoError(t, rsp.Err()) | ||
| // info = toTdigestInfo(t, rsp.Val()) | ||
| // require.EqualValues(t, 1000, info.Compression) | ||
| // require.EqualValues(t, 1024, info.Capacity) // max is 1024 | ||
| // require.EqualValues(t, 0, info.MergedNodes) | ||
| // require.EqualValues(t, 0, info.UnmergedNodes) | ||
| // require.EqualValues(t, 0, info.MergedWeight) | ||
| // require.EqualValues(t, 0, info.UnmergedWeight) | ||
| // require.EqualValues(t, 0, info.Observations) | ||
| // require.EqualValues(t, 0, info.TotalCompressions) |
There was a problem hiding this comment.
Hmm what's the situation of this commented block?
There was a problem hiding this comment.
Hmm what's the situation of this commented block?
Oh, my mistake! Sorry that I think I forgot to recover some parts for debug. I will double check my commit today.
There was a problem hiding this comment.
Hi @PragmaTwice ,
Thanks very much for your correction! ❤
I have recovered the commented test case and have run it in my local environment.
Best Regards,
Edward
|



Issue
Close #2791
Proposed Changes
tdigest.addcommand.tdigest.infocommand.Comment
tdigest.infohas one propertyMemory usage, and kvrocks's data structure is not in memory, could you give me some suggestions on evaluating the memory usage? 😊So, I will remove locks after adding "write" property to commands.
For
quantilecommand I plan to use "read" property and manually manage the lock to improve performance.