@@ -77,6 +77,7 @@ rocksdb::Status Hash::IncrBy(engine::Context &ctx, const Slice &user_key, const
7777 int64_t *new_value) {
7878 bool exists = false ;
7979 int64_t old_value = 0 ;
80+ bool expired = false ;
8081 std::string ns_key = AppendNamespacePrefix (user_key);
8182
8283 HashMetadata metadata;
@@ -93,19 +94,21 @@ rocksdb::Status Hash::IncrBy(engine::Context &ctx, const Slice &user_key, const
9394 s = GetSubKeyExpireTimestampMS (ctx, user_key, field, metadata.version , &expire_at);
9495 if (!s.ok () && !s.IsNotFound ()) return s;
9596 if (expire_at != NoExpireTime && expire_at < util::GetTimeStampMS ()) {
97+ expired = true ;
9698 old_value = 0 ;
97- } else {
98- auto parse_result = ParseInt<int64_t >(value_bytes, 10 );
99- if (!parse_result) {
100- return rocksdb::Status::InvalidArgument (parse_result.Msg ());
101- }
102- if (isspace (value_bytes[0 ])) {
103- return rocksdb::Status::InvalidArgument (" value is not an integer" );
104- }
105- old_value = *parse_result;
106- exists = true ;
10799 }
108100 }
101+ if (s.ok () && !expired) {
102+ auto parse_result = ParseInt<int64_t >(value_bytes, 10 );
103+ if (!parse_result) {
104+ return rocksdb::Status::InvalidArgument (parse_result.Msg ());
105+ }
106+ if (isspace (value_bytes[0 ])) {
107+ return rocksdb::Status::InvalidArgument (" value is not an integer" );
108+ }
109+ old_value = *parse_result;
110+ exists = true ;
111+ }
109112 }
110113 if ((increment < 0 && old_value < 0 && increment < (LLONG_MIN - old_value)) ||
111114 (increment > 0 && old_value > 0 && increment > (LLONG_MAX - old_value))) {
@@ -133,7 +136,7 @@ rocksdb::Status Hash::IncrByFloat(engine::Context &ctx, const Slice &user_key, c
133136 double *new_value) {
134137 bool exists = false ;
135138 double old_value = 0 ;
136-
139+ bool expired = false ;
137140 std::string ns_key = AppendNamespacePrefix (user_key);
138141
139142 HashMetadata metadata;
@@ -150,16 +153,18 @@ rocksdb::Status Hash::IncrByFloat(engine::Context &ctx, const Slice &user_key, c
150153 s = GetSubKeyExpireTimestampMS (ctx, user_key, field, metadata.version , &expire_at);
151154 if (!s.ok () && !s.IsNotFound ()) return s;
152155 if (expire_at != NoExpireTime && expire_at < util::GetTimeStampMS ()) {
156+ expired = true ;
153157 old_value = 0 ;
154- } else {
155- auto value_stat = ParseFloat (value_bytes);
156- if (!value_stat || isspace (value_bytes[0 ])) {
157- return rocksdb::Status::InvalidArgument (" value is not a number" );
158- }
159- old_value = *value_stat;
160- exists = true ;
161158 }
162159 }
160+ if (s.ok () && !expired) {
161+ auto value_stat = ParseFloat (value_bytes);
162+ if (!value_stat || isspace (value_bytes[0 ])) {
163+ return rocksdb::Status::InvalidArgument (" value is not a number" );
164+ }
165+ old_value = *value_stat;
166+ exists = true ;
167+ }
163168 }
164169 double n = old_value + increment;
165170 if (std::isinf (n) || std::isnan (n)) {
0 commit comments