Skip to content
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

refactor: promote the engine::Context in the Execute #2586

Merged
merged 8 commits into from
Oct 11, 2024
24 changes: 12 additions & 12 deletions src/commands/cmd_bit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class CommandGetBit : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
bool bit = false;
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bitmap_db.GetBit(ctx, args_[1], offset_, &bit);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -78,10 +78,10 @@ class CommandSetBit : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
bool old_bit = false;
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bitmap_db.SetBit(ctx, args_[1], offset_, bit_, &old_bit);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -134,10 +134,10 @@ class CommandBitCount : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
uint32_t cnt = 0;
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bitmap_db.BitCount(ctx, args_[1], start_, stop_, is_bit_index_, &cnt);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -194,10 +194,10 @@ class CommandBitPos : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
int64_t pos = 0;
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bitmap_db.BitPos(ctx, args_[1], bit_, start_, stop_, stop_given_, &pos, is_bit_index_);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -234,7 +234,7 @@ class CommandBitOp : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<Slice> op_keys;
op_keys.reserve(args_.size() - 2);
for (uint64_t i = 3; i < args_.size(); i++) {
Expand All @@ -243,7 +243,7 @@ class CommandBitOp : public Commander {

int64_t dest_key_len = 0;
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bitmap_db.BitOp(ctx, op_flag_, args_[1], args_[2], op_keys, &dest_key_len);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -337,11 +337,11 @@ class CommandBitfield : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::Bitmap bitmap_db(srv->storage, conn->GetNamespace());
std::vector<std::optional<BitfieldValue>> rets;
rocksdb::Status s;
engine::Context ctx(srv->storage);

if (read_only_) {
s = bitmap_db.BitfieldReadOnly(ctx, args_[1], cmds_, &rets);
} else {
Expand Down
32 changes: 16 additions & 16 deletions src/commands/cmd_bloom_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class CommandBFReserve : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloomfilter_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = bloomfilter_db.Reserve(ctx, args_[1], capacity_, error_rate_, expansion_);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand All @@ -106,10 +106,10 @@ class CommandBFReserve : public Commander {

class CommandBFAdd : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
BloomFilterAddResult ret = BloomFilterAddResult::kOk;
engine::Context ctx(srv->storage);

auto s = bloom_db.Add(ctx, args_[1], args_[2], &ret);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -138,10 +138,10 @@ class CommandBFMAdd : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
std::vector<BloomFilterAddResult> rets(items_.size(), BloomFilterAddResult::kOk);
engine::Context ctx(srv->storage);

auto s = bloom_db.MAdd(ctx, args_[1], items_, &rets);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -234,10 +234,10 @@ class CommandBFInsert : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
std::vector<BloomFilterAddResult> rets(items_.size(), BloomFilterAddResult::kOk);
engine::Context ctx(srv->storage);

auto s = bloom_db.InsertCommon(ctx, args_[1], items_, insert_options_, &rets);
if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"};
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
Expand Down Expand Up @@ -266,10 +266,10 @@ class CommandBFInsert : public Commander {

class CommandBFExists : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
bool exist = false;
engine::Context ctx(srv->storage);

auto s = bloom_db.Exists(ctx, args_[1], args_[2], &exist);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand All @@ -288,10 +288,10 @@ class CommandBFMExists : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
std::vector<bool> exists(items_.size(), false);
engine::Context ctx(srv->storage);

auto s = bloom_db.MExists(ctx, args_[1], items_, &exists);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

Expand Down Expand Up @@ -332,10 +332,10 @@ class CommandBFInfo : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
BloomFilterInfo info;
engine::Context ctx(srv->storage);

auto s = bloom_db.Info(ctx, args_[1], &info);
if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"};
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
Expand Down Expand Up @@ -380,10 +380,10 @@ class CommandBFInfo : public Commander {

class CommandBFCard : public Commander {
public:
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
redis::BloomChain bloom_db(srv->storage, conn->GetNamespace());
BloomFilterInfo info;
engine::Context ctx(srv->storage);

auto s = bloom_db.Info(ctx, args_[1], &info);
if (!s.ok() && !s.IsNotFound()) return {Status::RedisExecErr, s.ToString()};
if (s.IsNotFound()) {
Expand Down
13 changes: 8 additions & 5 deletions src/commands/cmd_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CommandCluster : public Commander {
return {Status::RedisParseErr, "CLUSTER command, CLUSTER INFO|NODES|SLOTS|KEYSLOT|RESET|REPLICAS"};
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
if (!srv->GetConfig()->cluster_enabled) {
return {Status::RedisExecErr, "Cluster mode is not enabled"};
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class CommandClusterX : public Commander {
return {Status::RedisParseErr, "CLUSTERX command, CLUSTERX VERSION|MYID|SETNODEID|SETNODES|SETSLOT|MIGRATE"};
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
if (!srv->GetConfig()->cluster_enabled) {
return {Status::RedisExecErr, "Cluster mode is not enabled"};
}
Expand Down Expand Up @@ -329,7 +329,8 @@ static uint64_t GenerateClusterFlag(uint64_t flags, const std::vector<std::strin

class CommandReadOnly : public Commander {
public:
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
*output = redis::SimpleString("OK");
conn->EnableFlag(redis::Connection::kReadOnly);
return Status::OK();
Expand All @@ -338,7 +339,8 @@ class CommandReadOnly : public Commander {

class CommandReadWrite : public Commander {
public:
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
*output = redis::SimpleString("OK");
conn->DisableFlag(redis::Connection::kReadOnly);
return Status::OK();
Expand All @@ -347,7 +349,8 @@ class CommandReadWrite : public Commander {

class CommandAsking : public Commander {
public:
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
conn->EnableFlag(redis::Connection::kAsking);
*output = redis::SimpleString("OK");
return Status::OK();
Expand Down
7 changes: 4 additions & 3 deletions src/commands/cmd_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
namespace redis {

struct CommandFunction : Commander {
Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
CommandParser parser(args_, 1);
engine::Context ctx(srv->storage);

if (parser.EatEqICase("load")) {
bool replace = false;
if (parser.EatEqICase("replace")) {
Expand Down Expand Up @@ -85,7 +85,8 @@ struct CommandFunction : Commander {

template <bool read_only = false>
struct CommandFCall : Commander {
Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override {
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
int64_t numkeys = GET_OR_RET(ParseInt<int64_t>(args_[2], 10));
if (numkeys > int64_t(args_.size() - 3)) {
return {Status::NotOK, "Number of keys can't be greater than number of args"};
Expand Down
30 changes: 14 additions & 16 deletions src/commands/cmd_geo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class CommandGeoAdd : public CommandGeoBase {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
uint64_t ret = 0;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.Add(ctx, args_[1], &geo_points_, &ret);
if (!s.ok()) {
return {Status::RedisExecErr, s.ToString()};
Expand All @@ -140,10 +140,10 @@ class CommandGeoDist : public CommandGeoBase {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
double distance = 0;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.Dist(ctx, args_[1], args_[2], args_[3], &distance);
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
Expand All @@ -167,10 +167,10 @@ class CommandGeoHash : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<std::string> hashes;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.Hash(ctx, args_[1], members_, &hashes);
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
Expand All @@ -197,10 +197,10 @@ class CommandGeoPos : public Commander {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::map<std::string, GeoPoint> geo_points;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.Pos(ctx, args_[1], members_, &geo_points);
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
Expand Down Expand Up @@ -305,10 +305,10 @@ class CommandGeoRadius : public CommandGeoBase {
return Status::OK();
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<GeoPoint> geo_points;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.Radius(ctx, args_[1], longitude_, latitude_, GetRadiusMeters(radius_), count_, sort_, store_key_,
store_distance_, GetUnitConversion(), &geo_points);
if (!s.ok()) {
Expand Down Expand Up @@ -453,11 +453,10 @@ class CommandGeoSearch : public CommandGeoBase {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<GeoPoint> geo_points;
redis::Geo geo_db(srv->storage, conn->GetNamespace());

engine::Context ctx(srv->storage);
auto s = geo_db.Search(ctx, args_[1], geo_shape_, origin_point_type_, member_, count_, sort_, false,
GetUnitConversion(), &geo_points);

Expand Down Expand Up @@ -616,11 +615,10 @@ class CommandGeoSearchStore : public CommandGeoSearch {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<GeoPoint> geo_points;
redis::Geo geo_db(srv->storage, conn->GetNamespace());

engine::Context ctx(srv->storage);
auto s = geo_db.SearchStore(ctx, args_[2], geo_shape_, origin_point_type_, member_, count_, sort_, store_key_,
store_distance_, GetUnitConversion(), &geo_points);

Expand Down Expand Up @@ -660,10 +658,10 @@ class CommandGeoRadiusByMember : public CommandGeoRadius {
return Commander::Parse(args);
}

Status Execute(Server *srv, Connection *conn, std::string *output) override {
Status Execute(engine::Context &ctx, Server *srv, Connection *conn, std::string *output) override {
std::vector<GeoPoint> geo_points;
redis::Geo geo_db(srv->storage, conn->GetNamespace());
engine::Context ctx(srv->storage);

auto s = geo_db.RadiusByMember(ctx, args_[1], args_[2], GetRadiusMeters(radius_), count_, sort_, store_key_,
store_distance_, GetUnitConversion(), &geo_points);
if (!s.ok()) {
Expand Down
Loading
Loading