MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestSyncSeqRollbackMultiNode

Function TestSyncSeqRollbackMultiNode

db/sequence_allocator_test.go:569–652  ·  view source on GitHub ↗

TestSyncSeqRollbackMultiNode: - Test rollback of _sync:seq doc in bucket for a multi node cluster node - Use nextSequenceGreaterThan to allocate sequences and trigger the rollback handling code - Alter _sync:seq in the bucket to rollback the value - Alter last seq on each allocator to mock allocatio

(t *testing.T)

Source from the content-addressed store, hash-verified

567// - Use two go routines to test two nodes racing to update the rollback back _sync:seq document
568// - Asser that the resulting batches on each node do not overlap
569func TestSyncSeqRollbackMultiNode(t *testing.T) {
570 ctx := base.TestCtx(t)
571 bucket := base.GetTestBucket(t)
572 defer bucket.Close(ctx)
573
574 stats, err := base.NewSyncGatewayStats()
575 require.NoError(t, err)
576 statsA, err := stats.NewDBStats("A", false, false, false, nil, nil)
577 require.NoError(t, err)
578 statsB, err := stats.NewDBStats("B", false, false, false, nil, nil)
579 require.NoError(t, err)
580 dbStatsA := statsA.DatabaseStats
581 dbStatsB := statsB.DatabaseStats
582 ds := bucket.GetSingleDataStore()
583
584 a := &sequenceAllocator{
585 datastore: bucket.GetSingleDataStore(),
586 dbStats: dbStatsA,
587 sequenceBatchSize: 10,
588 reserveNotify: make(chan struct{}, 50),
589 metaKeys: base.DefaultMetadataKeys,
590 }
591
592 b := &sequenceAllocator{
593 datastore: bucket.GetSingleDataStore(),
594 dbStats: dbStatsB,
595 sequenceBatchSize: 10,
596 reserveNotify: make(chan struct{}, 50),
597 metaKeys: base.DefaultMetadataKeys,
598 }
599
600 // perform batch allocation on sequence allocator a
601 nextSequence, _, err := a.nextSequenceGreaterThan(ctx, 0)
602 assert.NoError(t, err)
603 assert.Equal(t, uint64(1), nextSequence)
604
605 // perform batch allocation on sequence allocator b
606 nextSequence, _, err = b.nextSequenceGreaterThan(ctx, 0)
607 assert.NoError(t, err)
608 assert.Equal(t, uint64(11), nextSequence)
609
610 // alter _sync:seq in bucket to prev value
611 err = ds.Set(a.metaKeys.SyncSeqKey(), 0, nil, 2)
612 require.NoError(t, err)
613
614 // set a.last on this allocator to 5 (mock some sequences being allocated)
615 a.last = 5
616
617 // set b.last on this allocator to 15 (mock some sequences being allocated)
618 b.last = 15
619
620 wg := sync.WaitGroup{}
621 wg.Add(2)
622
623 go func() {
624 _, _, err := b.nextSequenceGreaterThan(ctx, 20)
625 assert.NoError(t, err)
626 wg.Done()

Callers

nothing calls this directly

Calls 14

getSequenceMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewSyncGatewayStatsFunction · 0.92
NewDBStatsMethod · 0.80
SyncSeqKeyMethod · 0.80
DoneMethod · 0.80
CloseMethod · 0.65
GetSingleDataStoreMethod · 0.45
EqualMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected