git-hulk commented on code in PR #3472:
URL: https://github.com/apache/kvrocks/pull/3472#discussion_r3185976165


##########
src/types/redis_hash.cc:
##########
@@ -91,23 +232,23 @@ rocksdb::Status Hash::IncrBy(engine::Context &ctx, const 
Slice &user_key, const
 
   std::string sub_key = InternalKey(ns_key, field, metadata.version, 
storage_->IsSlotIdEncoded()).Encode();
   if (s.ok()) {
-    std::string raw_value;
-    Slice value_bytes;
-    s = getRawValue(ctx, sub_key, &raw_value);
-    if (!s.ok() && !s.IsNotFound()) return s;
-    if (s.ok()) {
-      value_bytes = Slice(raw_value);
-      s = decodeValue(metadata, &value_bytes);
-      if (!s.ok()) return s;
-      auto parse_result = ParseInt<int64_t>(value_bytes.ToStringView(), 10);
+    HashFieldState state;
+    s = LoadFieldState(storage_, ctx, metadata, sub_key, 
util::GetTimeStampMS(), &state);
+    if (!s.ok()) return s;
+    if (state.kind == HashFieldStateKind::kPersistent || state.kind == 
HashFieldStateKind::kLiveTTL) {
+      auto parse_result = ParseInt<int64_t>(state.value, 10);
       if (!parse_result) {
         return rocksdb::Status::InvalidArgument(parse_result.Msg());
       }
-      if (isspace(value_bytes[0])) {
+      if (!state.value.empty() && isspace(state.value[0])) {
         return rocksdb::Status::InvalidArgument("value is not an integer");
       }
       old_value = *parse_result;
       exists = true;
+      ttl_to_persistent = state.kind == HashFieldStateKind::kLiveTTL;

Review Comment:
   We shouldn't clear the field TTL when increasing the value. 



##########
src/types/redis_hash.cc:
##########
@@ -146,20 +294,20 @@ rocksdb::Status Hash::IncrByFloat(engine::Context &ctx, 
const Slice &user_key, c
 
   std::string sub_key = InternalKey(ns_key, field, metadata.version, 
storage_->IsSlotIdEncoded()).Encode();
   if (s.ok()) {
-    std::string raw_value;
-    Slice value_bytes;
-    s = getRawValue(ctx, sub_key, &raw_value);
-    if (!s.ok() && !s.IsNotFound()) return s;
-    if (s.ok()) {
-      value_bytes = Slice(raw_value);
-      s = decodeValue(metadata, &value_bytes);
-      if (!s.ok()) return s;
-      auto value_stat = ParseFloat(value_bytes.ToStringView());
-      if (!value_stat || isspace(value_bytes[0])) {
+    HashFieldState state;
+    s = LoadFieldState(storage_, ctx, metadata, sub_key, 
util::GetTimeStampMS(), &state);
+    if (!s.ok()) return s;
+    if (state.kind == HashFieldStateKind::kPersistent || state.kind == 
HashFieldStateKind::kLiveTTL) {
+      auto value_stat = ParseFloat(state.value);
+      if (!value_stat || (!state.value.empty() && isspace(state.value[0]))) {
         return rocksdb::Status::InvalidArgument("value is not a number");
       }
       old_value = *value_stat;
       exists = true;
+      ttl_to_persistent = state.kind == HashFieldStateKind::kLiveTTL;

Review Comment:
   The same as the HINCBY



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