PragmaTwice commented on code in PR #1841:
URL: https://github.com/apache/kvrocks/pull/1841#discussion_r1379799420


##########
src/types/redis_json.cc:
##########
@@ -201,4 +201,63 @@ rocksdb::Status Json::ArrLen(const std::string &user_key, 
const std::string &pat
 
   return rocksdb::Status::OK();
 }
+
+rocksdb::Status Json::StrAppend(const std::string &user_key, const std::string 
&path, const std::string &value,
+                                std::vector<uint64_t> &append_cnt) {
+  auto ns_key = AppendNamespacePrefix(user_key);
+
+  LockGuard guard(storage_->GetLockManager(), ns_key);
+
+  std::string bytes;
+  JsonMetadata metadata;
+  Slice rest;
+  auto s = GetMetadata(kRedisJson, ns_key, &bytes, &metadata, &rest);
+  if (!s.ok()) return s;
+
+  if (metadata.format != JsonStorageFormat::JSON)
+    return rocksdb::Status::NotSupported("JSON storage format not supported");
+
+  auto json_res = JsonValue::FromString(rest.ToStringView());
+  if (!json_res) return rocksdb::Status::Corruption(json_res.Msg());
+  auto json_val = *std::move(json_res);

Review Comment:
   Could you use the `read` method instead these code? You can refer to other 
method for how to use `read`.



##########
src/types/redis_json.cc:
##########
@@ -201,4 +201,63 @@ rocksdb::Status Json::ArrLen(const std::string &user_key, 
const std::string &pat
 
   return rocksdb::Status::OK();
 }
+
+rocksdb::Status Json::StrAppend(const std::string &user_key, const std::string 
&path, const std::string &value,
+                                std::vector<uint64_t> &append_cnt) {
+  auto ns_key = AppendNamespacePrefix(user_key);
+
+  LockGuard guard(storage_->GetLockManager(), ns_key);
+
+  std::string bytes;
+  JsonMetadata metadata;
+  Slice rest;
+  auto s = GetMetadata(kRedisJson, ns_key, &bytes, &metadata, &rest);
+  if (!s.ok()) return s;
+
+  if (metadata.format != JsonStorageFormat::JSON)
+    return rocksdb::Status::NotSupported("JSON storage format not supported");
+
+  auto json_res = JsonValue::FromString(rest.ToStringView());
+  if (!json_res) return rocksdb::Status::Corruption(json_res.Msg());
+  auto json_val = *std::move(json_res);
+
+  auto append_res = json_val.StrAppend(path, value, append_cnt);
+  if (!append_res) return rocksdb::Status::InvalidArgument(append_res.Msg());
+  // need Reverse order
+  std::reverse(append_cnt.begin(), append_cnt.end());
+
+  bool need_overwrite = false;
+  for (auto append : append_cnt) {
+    if (append > 0) {
+      need_overwrite = true;
+    }
+  }
+  if (!need_overwrite) {
+    return rocksdb::Status::OK();
+  }
+
+  return write(ns_key, &metadata, json_val);
+}
+
+rocksdb::Status Json::StrLen(const std::string &user_key, const std::string 
&path, std::vector<uint64_t> &str_lens) {
+  auto ns_key = AppendNamespacePrefix(user_key);
+
+  std::string bytes;
+  JsonMetadata metadata;
+  Slice rest;
+  auto s = GetMetadata(kRedisJson, ns_key, &bytes, &metadata, &rest);
+  if (!s.ok()) return s;
+
+  if (metadata.format != JsonStorageFormat::JSON)
+    return rocksdb::Status::NotSupported("JSON storage format not supported");
+
+  auto json_res = JsonValue::FromString(rest.ToStringView());
+  if (!json_res) return rocksdb::Status::Corruption(json_res.Msg());

Review Comment:
   ditto



-- 
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]

Reply via email to