PragmaTwice commented on code in PR #3264:
URL: https://github.com/apache/kvrocks/pull/3264#discussion_r2536164101
##########
src/commands/cmd_timeseries.cc:
##########
@@ -342,6 +342,51 @@ class CommandTSCreate : public CommandTSCreateBase {
}
};
+class CommandTSAlter : public CommandTSCreateBase {
+ public:
+ CommandTSAlter() { registerDefaultHandlers(); }
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 2) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ CommandTSCreateBase::setSkipNum(2);
+ return CommandTSCreateBase::Parse(args);
+ }
+ Status Execute(engine::Context &ctx, Server *srv, Connection *conn,
std::string *output) override {
+ auto sc = CommandTSCreateBase::Execute(ctx, srv, conn, output);
+ if (!sc.IsOK()) return sc;
+
+ auto timeseries_db = TimeSeries(srv->storage, conn->GetNamespace());
+ auto s = timeseries_db.Alter(ctx, args_[1], getCreateOption(), mask_);
+ if (!s.ok() && s.IsInvalidArgument()) return {Status::RedisExecErr,
errKeyNotFound};
+ if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+ *output = redis::RESP_OK;
+ return Status::OK();
+ }
+
+ private:
+ uint8_t mask_ = 0; // Bitmask, LSB 0 - retention time, LSB 1 - chunk size,
LSB 2 - duplicate policy, LSB 4 - Labels
+
+ void registerDefaultHandlers() override {
+ registerHandler("RETENTION", [this](TSOptionsParser &parser) {
+ mask_ |= 1;
+ return handleRetention(parser, create_option_.retention_time);
+ });
+ registerHandler("CHUNK_SIZE", [this](TSOptionsParser &parser) {
+ mask_ |= (1 << 1);
+ return handleChunkSize(parser, create_option_.chunk_size);
+ });
+ registerHandler("DUPLICATE_POLICY", [this](TSOptionsParser &parser) {
+ mask_ |= (1 << 2);
+ return handleDuplicatePolicy(parser, create_option_.duplicate_policy);
+ });
+ registerHandler("LABELS", [this](TSOptionsParser &parser) {
+ mask_ |= (1 << 4);
+ return handleLabels(parser, create_option_.labels);
+ });
+ }
Review Comment:
It seems not so obvious to indicate which to alter.
Would you like to add an enum type for it, e.g.
```
enum AlterMode {
RETENTION = 1,
CHUNK_SIZE = 1 << 1,
...
}
```
And also:
```
mask_ |= 1 to mask_ |= AlterMode::RETENTION
(mask & 1) to (mask & AlterMode::RETENTION)
```
--
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]