Skip to content

feat: support for the sort command[draft]#2230

Closed
PokIsemaine wants to merge 0 commit intoapache:unstablefrom
PokIsemaine:unstable
Closed

feat: support for the sort command[draft]#2230
PokIsemaine wants to merge 0 commit intoapache:unstablefrom
PokIsemaine:unstable

Conversation

@PokIsemaine
Copy link
Copy Markdown
Contributor

I'm trying to support the sort command and later the sort_ro command for kvrocks, this is my first time submitting a pull request for this project and I need some advice, so I set it to draft temporarily.

The help I need is as follows:

127.0.0.1:6379> command info sort
1)  1) "sort"
    2) (integer) -2
    3) 1) write
       2) denyoom
       3) movablekeys
  • Whether there is any need to modify or add to the existing code (especially exceptions), comments, and tests (especially boundary cases) in the draft?

If you can provide me with any advice I would be very grateful!

The information and code I referenced are as follows:

@mapleFU
Copy link
Copy Markdown
Member

mapleFU commented Apr 9, 2024

It seems that they are related to ACL, Cluster, CLIENT_SCRIPT, but I have not found relevant support for kvrocks at present. What should I do?

I think we can leave them unimplemented first

How to support denyoom and movablekeys flags

About oom currently it's a bit hard to manage the memory by custom allocator. Maybe we can separate a machine/process level global memory tracking module and check that. This can separate to an other patch or discuss it firstly

@PokIsemaine PokIsemaine marked this pull request as ready for review April 12, 2024 13:44
@PokIsemaine
Copy link
Copy Markdown
Contributor Author

It seems that they are related to ACL, Cluster, CLIENT_SCRIPT, but I have not found relevant support for kvrocks at present. What should I do?

I think we can leave them unimplemented first

How to support denyoom and movablekeys flags

About oom currently it's a bit hard to manage the memory by custom allocator. Maybe we can separate a machine/process level global memory tracking module and check that. This can separate to an other patch or discuss it firstly

Thanks!
So what do we need to do to modify these TODO comments? Delete them or keep them (perhaps with more formal comments)

@PokIsemaine PokIsemaine marked this pull request as draft April 12, 2024 14:30
@PokIsemaine PokIsemaine marked this pull request as ready for review April 13, 2024 15:39
Copy link
Copy Markdown
Member

@jihuayu jihuayu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PokIsemaine Thanks for your PR. Your code is amazingly clean. The test cases are also very detailed.
For these TODO comments, I think we can keep them.

The logic LGTM.
But according to our conventions, this command should be placed in the cmd_key.cc file, and the core logic of the Execute function should be extracted and placed in the redis::Database class.

Below is a example:

class CommandPTTL : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
redis::Database redis(srv->storage, conn->GetNamespace());
int64_t ttl = 0;
auto s = redis.TTL(args_[1], &ttl);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
*output = redis::Integer(ttl);
return Status::OK();
}
};

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Comment on lines +192 to +193
else if (flag == "movable-keys")
flags |= kCmdMovableKeys;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is meaningless in Kvrocks. Please remove it and refer to KeyRangeVecGen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I need to learn about KeyRangeVecGen.

Comment on lines +190 to +191
else if (flag == "deny-oom")
flags |= kCmdDenyOom;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't plan to implement it in this PR, so please remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, thanks for the heads up, I'll remove the flags later on.

Comment on lines +68 to +69
kCmdDenyOom = 1ULL << 13, // "deny-oom" flag
kCmdMovableKeys = 1ULL << 14, // "movable-keys" flag
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

bool desc_ = false; // ASC/DESC
bool alpha_ = false; // ALPHA
std::string storekey_; // STORE
};
Copy link
Copy Markdown
Member

@PragmaTwice PragmaTwice Apr 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of SORT should be in redis_db.cc. The parsing part can be in cmd_key.cc.

@PokIsemaine
Copy link
Copy Markdown
Contributor Author

@PokIsemaine Thanks for your PR. Your code is amazingly clean. The test cases are also very detailed. For these TODO comments, I think we can keep them.

The logic LGTM. But according to our conventions, this command should be placed in the cmd_key.cc file, and the core logic of the Execute function should be extracted and placed in the redis::Database class.

Below is a example:

class CommandPTTL : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
redis::Database redis(srv->storage, conn->GetNamespace());
int64_t ttl = 0;
auto s = redis.TTL(args_[1], &ttl);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
*output = redis::Integer(ttl);
return Status::OK();
}
};

Thanks for the advice, I'll probably do it this weekend

@PokIsemaine PokIsemaine marked this pull request as draft April 18, 2024 12:00
@PokIsemaine PokIsemaine force-pushed the unstable branch 2 times, most recently from 6a0f885 to 1e402bc Compare April 21, 2024 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants