@@ -285,9 +285,12 @@ OpResult<int64_t> OpIncrBy(const OpArgs& op_args, string_view key, int64_t incr,
285
285
auto & db_slice = op_args.GetDbSlice ();
286
286
287
287
// we avoid using AddOrFind because of skip_on_missing option for memcache.
288
- auto res = db_slice.FindMutable (op_args.db_cntx , key);
288
+ auto res = db_slice.FindMutable (op_args.db_cntx , key, OBJ_STRING);
289
+
290
+ if (!res) {
291
+ if (res.status () == OpStatus::WRONG_TYPE)
292
+ return res.status ();
289
293
290
- if (!IsValid (res.it )) {
291
294
if (skip_on_missing)
292
295
return OpStatus::KEY_NOTFOUND;
293
296
@@ -300,11 +303,8 @@ OpResult<int64_t> OpIncrBy(const OpArgs& op_args, string_view key, int64_t incr,
300
303
return incr;
301
304
}
302
305
303
- if (res.it ->second .ObjType () != OBJ_STRING) {
304
- return OpStatus::WRONG_TYPE;
305
- }
306
-
307
- auto opt_prev = res.it ->second .TryGetInt ();
306
+ // Type is already checked by FindMutable (OBJ_STRING)
307
+ auto opt_prev = res->it ->second .TryGetInt ();
308
308
if (!opt_prev) {
309
309
return OpStatus::INVALID_VALUE;
310
310
}
@@ -316,8 +316,8 @@ OpResult<int64_t> OpIncrBy(const OpArgs& op_args, string_view key, int64_t incr,
316
316
}
317
317
318
318
int64_t new_val = prev + incr;
319
- DCHECK (!res. it ->second .IsExternal ());
320
- res. it ->second .SetInt (new_val);
319
+ DCHECK (!res-> it ->second .IsExternal ());
320
+ res-> it ->second .SetInt (new_val);
321
321
322
322
return new_val;
323
323
}
@@ -383,20 +383,19 @@ OpResult<array<int64_t, 5>> OpThrottle(const OpArgs& op_args, const string_view
383
383
// Cost of this request
384
384
const int64_t increment_ns = emission_interval_ns * quantity; // should be nonnegative
385
385
386
- auto res = db_slice.FindMutable (op_args.db_cntx , key);
386
+ auto res = db_slice.FindMutable (op_args.db_cntx , key, OBJ_STRING );
387
387
const int64_t now_ns = GetCurrentTimeNs ();
388
388
389
389
int64_t tat_ns = now_ns;
390
- if (IsValid (res.it )) {
391
- if (res.it ->second .ObjType () != OBJ_STRING) {
392
- return OpStatus::WRONG_TYPE;
393
- }
394
-
395
- auto opt_prev = res.it ->second .TryGetInt ();
390
+ if (res) {
391
+ // Type is already checked by FindMutable (OBJ_STRING)
392
+ auto opt_prev = res->it ->second .TryGetInt ();
396
393
if (!opt_prev) {
397
394
return OpStatus::INVALID_VALUE;
398
395
}
399
396
tat_ns = *opt_prev;
397
+ } else if (res.status () == OpStatus::WRONG_TYPE) {
398
+ return res.status ();
400
399
}
401
400
402
401
int64_t new_tat_ns = max (tat_ns, now_ns);
@@ -458,14 +457,14 @@ OpResult<array<int64_t, 5>> OpThrottle(const OpArgs& op_args, const string_view
458
457
// break behavior because the tat_ns value will be used to check for throttling.
459
458
const int64_t new_tat_ms =
460
459
(new_tat_ns + kMilliSecondToNanoSecond - 1 ) / kMilliSecondToNanoSecond ;
461
- if (IsValid ( res. it ) ) {
462
- if (IsValid (res. exp_it )) {
463
- res. exp_it ->second = db_slice.FromAbsoluteTime (new_tat_ms);
460
+ if (res) {
461
+ if (IsValid (res-> exp_it )) {
462
+ res-> exp_it ->second = db_slice.FromAbsoluteTime (new_tat_ms);
464
463
} else {
465
- db_slice.AddExpire (op_args.db_cntx .db_index , res. it , new_tat_ms);
464
+ db_slice.AddExpire (op_args.db_cntx .db_index , res-> it , new_tat_ms);
466
465
}
467
466
468
- res. it ->second .SetInt (new_tat_ns);
467
+ res-> it ->second .SetInt (new_tat_ns);
469
468
} else {
470
469
CompactObj cobj;
471
470
cobj.SetInt (new_tat_ns);
0 commit comments