refactor: Use DbContext, OpArgs and Transaction to access DbSlice (#3311)

This is a refactor that will put us closer to adding namespaces, see
included `docs/namespaces.md`
This commit is contained in:
Shahar Mike 2024-07-12 08:13:16 +03:00 committed by GitHub
parent bf2e5fd3f5
commit d7351b315e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 355 additions and 233 deletions

View file

@ -131,7 +131,7 @@ inline JsonType Evaluate(const json::Path& expr, const JsonType& obj) {
}
facade::OpStatus SetJson(const OpArgs& op_args, string_view key, JsonType&& value) {
auto& db_slice = op_args.shard->db_slice();
auto& db_slice = op_args.GetDbSlice();
auto op_res = db_slice.AddOrFind(op_args.db_cntx, key);
RETURN_ON_BAD_STATUS(op_res);
@ -244,7 +244,7 @@ error_code JsonReplace(JsonType& instance, string_view path, json::MutateCallbac
// jsoncons version
OpStatus UpdateEntry(const OpArgs& op_args, std::string_view key, std::string_view path,
json::MutateCallback callback, JsonReplaceVerify verify_op = {}) {
auto it_res = op_args.shard->db_slice().FindMutable(op_args.db_cntx, key, OBJ_JSON);
auto it_res = op_args.GetDbSlice().FindMutable(op_args.db_cntx, key, OBJ_JSON);
if (!it_res.ok()) {
return it_res.status();
}
@ -278,7 +278,7 @@ OpStatus UpdateEntry(const OpArgs& op_args, std::string_view key, std::string_vi
// json::Path version.
OpStatus UpdateEntry(const OpArgs& op_args, string_view key, const json::Path& path,
json::MutateCallback cb) {
auto it_res = op_args.shard->db_slice().FindMutable(op_args.db_cntx, key, OBJ_JSON);
auto it_res = op_args.GetDbSlice().FindMutable(op_args.db_cntx, key, OBJ_JSON);
if (!it_res.ok()) {
return it_res.status();
}
@ -294,7 +294,7 @@ OpStatus UpdateEntry(const OpArgs& op_args, string_view key, const json::Path& p
}
OpResult<JsonType*> GetJson(const OpArgs& op_args, string_view key) {
auto it_res = op_args.shard->db_slice().FindReadOnly(op_args.db_cntx, key, OBJ_JSON);
auto it_res = op_args.GetDbSlice().FindReadOnly(op_args.db_cntx, key, OBJ_JSON);
if (!it_res.ok())
return it_res.status();
@ -753,9 +753,9 @@ OpResult<string> OpDoubleArithmetic(const OpArgs& op_args, string_view key, stri
OpResult<long> OpDel(const OpArgs& op_args, string_view key, string_view path,
optional<JsonPathV2> expression) {
if (!expression || path.empty()) {
auto& db_slice = op_args.shard->db_slice();
auto& db_slice = op_args.GetDbSlice();
auto it = db_slice.FindMutable(op_args.db_cntx, key).it; // post_updater will run immediately
return long(db_slice.Del(op_args.db_cntx.db_index, it));
return long(db_slice.Del(op_args.db_cntx, it));
}
OpResult<JsonType*> result = GetJson(op_args, key);
@ -1200,7 +1200,7 @@ vector<OptString> OpJsonMGet(const JsonPathV2& expression, const Transaction* t,
DCHECK(!args.Empty());
vector<OptString> response(args.Size());
auto& db_slice = shard->db_slice();
auto& db_slice = t->GetDbSlice(shard->shard_id());
unsigned index = 0;
for (string_view key : args) {
auto it_res = db_slice.FindReadOnly(t->GetDbContext(), key, OBJ_JSON);
@ -1288,7 +1288,7 @@ OpResult<bool> OpSet(const OpArgs& op_args, string_view key, string_view path,
// and its not JSON, it would return an error.
if (path == "." || path == "$") {
if (is_nx_condition || is_xx_condition) {
auto it_res = op_args.shard->db_slice().FindReadOnly(op_args.db_cntx, key, OBJ_JSON);
auto it_res = op_args.GetDbSlice().FindReadOnly(op_args.db_cntx, key, OBJ_JSON);
bool key_exists = (it_res.status() != OpStatus::KEY_NOTFOUND);
if (is_nx_condition && key_exists) {
return false;
@ -1417,7 +1417,7 @@ OpStatus OpMerge(const OpArgs& op_args, string_view key, std::string_view json_s
return OpStatus::SYNTAX_ERR;
}
auto& db_slice = op_args.shard->db_slice();
auto& db_slice = op_args.GetDbSlice();
auto it_res = db_slice.FindMutable(op_args.db_cntx, key, OBJ_JSON);
if (it_res.ok()) {
op_args.shard->search_indices()->RemoveDoc(key, op_args.db_cntx, it_res->it->second);