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