@@ -436,6 +436,10 @@ private static unsafe bool TryGetNextSetObjects(byte[] key, SortedSetObject sort
436
436
}
437
437
}
438
438
439
+ /// <summary>
440
+ /// Try to get available item(s) from sorted set object based on command type and arguments
441
+ /// When run from initializer (initial = true), can return WRONGTYPE errors
442
+ /// </summary>
439
443
private unsafe bool TryGetResult( byte [ ] key, StorageSession storageSession,
440
444
RespCommand command, ArgSlice[ ] cmdArgs , bool initial ,
441
445
out int currCount , out CollectionItemResult result )
@@ -451,13 +455,13 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
451
455
_ => throw new NotSupportedException ( )
452
456
} ;
453
457
458
+ var asKey = storageSession. scratchBufferManager. CreateArgSlice( key ) ;
454
459
ArgSlice dstKey = default ;
455
460
if ( command == RespCommand . BLMOVE )
456
461
{
457
462
dstKey = cmdArgs [ 0 ] ;
458
463
}
459
464
460
- var asKey = storageSession . scratchBufferManager . CreateArgSlice ( key ) ;
461
465
// Create a transaction if not currently in a running transaction
462
466
if ( storageSession . txnManager . state != TxnState . Running )
463
467
{
@@ -479,8 +483,6 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
479
483
480
484
var lockableContext = storageSession. txnManager . LockableContext ;
481
485
var objectLockableContext = storageSession . txnManager . ObjectStoreLockableContext ;
482
- IGarnetObject dstObj = null ;
483
- byte [ ] arrDstKey = default ;
484
486
485
487
try
486
488
{
@@ -491,42 +493,18 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
491
493
if ( ! initial )
492
494
return false;
493
495
496
+ // Check the string store as well to see if WRONGTYPE should be returned.
494
497
statusOp = storageSession . GET ( asKey , out ArgSlice _ , ref lockableContext ) ;
495
498
496
499
if ( statusOp != GarnetStatus . NOTFOUND )
497
500
{
498
501
result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
499
- return true;
500
- }
501
-
502
- if ( command == RespCommand . BLMOVE )
503
- {
504
- arrDstKey = dstKey . ToArray ( ) ;
505
- var dstStatusOp = storageSession . GET ( arrDstKey , out var osDstObject , ref objectLockableContext ) ;
506
- if ( dstStatusOp != GarnetStatus . NOTFOUND && osDstObject . GarnetObject is not ListObject )
507
- {
508
- result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
509
- return true;
510
- }
511
-
512
- dstStatusOp = storageSession . GET ( dstKey , out ArgSlice _ , ref lockableContext ) ;
513
- if ( dstStatusOp != GarnetStatus . NOTFOUND )
514
- {
515
- result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
516
- return true;
517
- }
502
+ return initial;
518
503
}
519
504
520
505
return false ;
521
506
}
522
507
523
- if ( command == RespCommand . BLMOVE )
524
- {
525
- arrDstKey = dstKey. ToArray ( ) ;
526
- var dstStatusOp = storageSession. GET ( arrDstKey , out var osDstObject , ref objectLockableContext ) ;
527
- if ( dstStatusOp != GarnetStatus . NOTFOUND ) dstObj = osDstObject. GarnetObject ;
528
- }
529
-
530
508
// Check for type match between the observer and the actual object type
531
509
// If types match, get next item based on item type
532
510
switch ( osObject . GarnetObject )
@@ -550,21 +528,46 @@ private unsafe bool TryGetResult(byte[] key, StorageSession storageSession,
550
528
result = new CollectionItemResult ( key , nextItem ) ;
551
529
break ;
552
530
case RespCommand . BLMOVE :
531
+ var arrDstKey = dstKey . ToArray ( ) ;
532
+ var dstStatusOp = storageSession . GET ( arrDstKey , out var osDstObject , ref objectLockableContext ) ;
533
+
553
534
ListObject dstList;
554
535
var newObj = false ;
555
- if ( dstObj == null )
556
- {
557
- dstList = new ListObject ( ) ;
558
- newObj = true ;
559
- }
560
- else if ( dstObj is ListObject tmpDstList)
536
+
537
+ if ( dstStatusOp != GarnetStatus . NOTFOUND )
561
538
{
562
- dstList = tmpDstList ;
539
+ var dstObj = osDstObject. GarnetObject;
540
+
541
+ if ( dstObj = = null )
542
+ {
543
+ dstList = new ListObject ( ) ;
544
+ newObj = true ;
545
+ }
546
+ else if ( dstObj is ListObject tmpDstList)
547
+ {
548
+ dstList = tmpDstList ;
549
+ }
550
+ else
551
+ {
552
+ result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
553
+ return initial;
554
+ }
563
555
}
564
556
else
565
557
{
566
- result = new CollectionItemResult ( GarnetStatus . WRONGTYPE ) ;
567
- return initial;
558
+ if ( initial )
559
+ {
560
+ // Check string store for wrongtype errors on initial run.
561
+ dstStatusOp = storageSession. GET ( dstKey , out ArgSlice _ , ref lockableContext ) ;
562
+ if ( dstStatusOp != GarnetStatus . NOTFOUND )
563
+ {
564
+ result = new CollectionItemResult( GarnetStatus . WRONGTYPE ) ;
565
+ return initial;
566
+ }
567
+ }
568
+
569
+ dstList = new ListObject( ) ;
570
+ newObj = true;
568
571
}
569
572
570
573
isSuccessful = TryMoveNextListItem( listObj , dstList , ( OperationDirection ) cmdArgs [ 1 ] . ReadOnlySpan [ 0 ] ,
0 commit comments