@@ -191,11 +191,11 @@ func assertConflictEngineMatchesModel(t *testing.T, engine *conflictEngine, mode
191191 wantGlobal = max (wantGlobal , ref .Instance )
192192 }
193193 }
194- if got := engine .maxEligibleAny (lane ); got != wantMax {
195- t .Fatalf ("step %d lane %v: max eligible=%d, want %d" , step , lane , got , wantMax )
194+ if resident , retired := engine .maxEligibleAny (lane ); max ( resident , retired ) != wantMax {
195+ t .Fatalf ("step %d lane %v: max eligible=%d/%d , want %d" , step , lane , resident , retired , wantMax )
196196 }
197- if got := engine .globalMax (lane ); got != wantGlobal {
198- t .Fatalf ("step %d lane %v: global max=%d, want %d" , step , lane , got , wantGlobal )
197+ if resident , retired := engine .globalMax (lane ); max ( resident , retired ) != wantGlobal {
198+ t .Fatalf ("step %d lane %v: global max=%d/%d , want %d" , step , lane , resident , retired , wantGlobal )
199199 }
200200 for _ , through := range []InstanceNum {0 , 1 , 63 , 64 , 4_096 , InstanceNum (1 )<< 60 + 63 , ^ InstanceNum (0 )} {
201201 want := modelPrefixMaxSeq (model , lane , through )
@@ -265,9 +265,9 @@ func engineModelAttrs(engine *conflictEngine, conf ConfID, cmd Command) modelAtt
265265 engine .lanes (conf , func (lane instanceLane ) bool {
266266 var dep InstanceNum
267267 if commandHasGlobalConflictScope (cmd .Kind ) {
268- dep = engine .maxEligibleAny (lane )
268+ r , ret : = engine .maxEligibleAny (lane ); dep = max ( r , ret )
269269 } else {
270- dep = engine .globalMax (lane )
270+ r , ret : = engine .globalMax (lane ); dep = max ( r , ret )
271271 for _ , key := range cmd .ConflictKeys {
272272 resident , retired := engine .keyMax (conf , key , lane )
273273 dep = max (dep , resident , retired )
@@ -417,11 +417,11 @@ func TestConflictEnginePostFoldDomination(t *testing.T) {
417417 t .Fatalf ("query %+v decreased across fold: before=%+v after=%+v" , query , beforeAttrs , afterAttrs )
418418 }
419419 }
420- if got := engine .globalMax (lane ); got != 3 {
421- t .Fatalf ("retired global max=%d, want 3" , got )
420+ if resident , retired := engine .globalMax (lane ); max ( resident , retired ) != 3 {
421+ t .Fatalf ("retired global max=%d, want 3" , max ( resident , retired ) )
422422 }
423- if got := engine .maxEligibleAny (lane ); got != 4 {
424- t .Fatalf ("retired eligible max=%d, want 4" , got )
423+ if resident , retired := engine .maxEligibleAny (lane ); max ( resident , retired ) != 4 {
424+ t .Fatalf ("retired eligible max=%d, want 4" , max ( resident , retired ) )
425425 }
426426 if err := engine .verify (); err != nil {
427427 t .Fatal (err )
@@ -471,8 +471,8 @@ func TestConflictEngineNoopMutationDropsMax(t *testing.T) {
471471 if resident != lower .Ref .Instance || retired != 0 {
472472 t .Fatalf ("key max after noop mutation=(%d,%d), want (%d,0)" , resident , retired , lower .Ref .Instance )
473473 }
474- if got := engine .maxEligibleAny (lane ); got != lower .Ref .Instance {
475- t .Fatalf ("max eligible after noop mutation=%d, want %d" , got , lower .Ref .Instance )
474+ if resident , retired := engine .maxEligibleAny (lane ); max ( resident , retired ) != lower .Ref .Instance {
475+ t .Fatalf ("max eligible after noop mutation=%d/%d , want %d" , resident , retired , lower .Ref .Instance )
476476 }
477477 if err := engine .verify (); err != nil {
478478 t .Fatal (err )
@@ -641,3 +641,38 @@ func assertExactKeyPostings(t *testing.T, e *conflictEngine, records map[Instanc
641641 }
642642 }
643643}
644+
645+
646+ func TestWalkGlobalDescSkipsUnrelatedResidents (t * testing.T ) {
647+ t .Parallel ()
648+ var engine conflictEngine
649+ lane := instanceLane {conf : 1 , replica : 1 }
650+ // One old global at instance 1, then many ordinary residents.
651+ global := InstanceRecord {
652+ Ref : InstanceRef {Conf : 1 , Replica : 1 , Instance : 1 },
653+ Status : StatusCommitted , Seq : 1 ,
654+ Command : Command {Kind : CommandConfChange , Payload : []byte ("cfg" )},
655+ }
656+ engine .apply (nil , global )
657+ for i := InstanceNum (2 ); i <= 200 ; i ++ {
658+ rec := InstanceRecord {
659+ Ref : InstanceRef {Conf : 1 , Replica : 1 , Instance : i },
660+ Status : StatusCommitted , Seq : uint64 (i ),
661+ Command : Command {Kind : CommandUser , Payload : []byte ("u" ), ConflictKeys : [][]byte {[]byte ("k" )}},
662+ }
663+ engine .apply (nil , rec )
664+ }
665+ visits := 0
666+ var seen []InstanceNum
667+ engine .walkGlobalDesc (lane , 200 , func (instance InstanceNum , slot laneSlot ) bool {
668+ visits ++
669+ seen = append (seen , instance )
670+ if ! slot .global () {
671+ t .Fatalf ("yielded non-global instance %d" , instance )
672+ }
673+ return true
674+ })
675+ if visits != 1 || len (seen ) != 1 || seen [0 ] != 1 {
676+ t .Fatalf ("walkGlobalDesc visits=%d seen=%v, want only global instance 1" , visits , seen )
677+ }
678+ }
0 commit comments