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

Function multiNodeUpdate

db/sequence_allocator_test.go:852–875  ·  view source on GitHub ↗

multiNodeUpdate obtains an initial sequence from an import allocator (import node), then performs repeated updates to the doc using random pool of iterators (random SG node). Performs sequenceGreaterThan, then ensures that allocator doesn't release more than the sequence batch size

(t *testing.T, ctx context.Context, importAllocator *sequenceAllocator, clientAllocators []*sequenceAllocator, updateCount int, interval time.Duration)

Source from the content-addressed store, hash-verified

850// multiNodeUpdate obtains an initial sequence from an import allocator (import node), then performs repeated updates to the doc using random pool of iterators (random SG node).
851// Performs sequenceGreaterThan, then ensures that allocator doesn't release more than the sequence batch size
852func multiNodeUpdate(t *testing.T, ctx context.Context, importAllocator *sequenceAllocator, clientAllocators []*sequenceAllocator, updateCount int, interval time.Duration) (releasedCount uint64) {
853 currentSequence, _ := importAllocator.nextSequence(ctx)
854
855 for i := 0; i < updateCount; i++ {
856 allocatorIndex := rand.Intn(len(clientAllocators))
857 clientAllocator := clientAllocators[allocatorIndex]
858 nextSequence, err := clientAllocator.nextSequence(ctx)
859 require.NoError(t, err, "nextSequence error: %v", err)
860 if nextSequence < currentSequence {
861 prevNext := nextSequence
862 var numReleased uint64
863 nextSequence, numReleased, err = clientAllocator.nextSequenceGreaterThan(ctx, currentSequence)
864 require.NoError(t, err, "nextSequenceGreaterThan error: %v", err)
865 log.Printf("allocator %d released %d sequences because next < current (%d < %d)", numReleased, allocatorIndex, prevNext, currentSequence)
866 // At most clientAllocator should only need to release the current batch
867 assert.LessOrEqual(t, numReleased, getClientSequenceBatchSize(clientAllocator))
868 releasedCount += numReleased
869 }
870 currentSequence = nextSequence
871 time.Sleep(interval)
872 }
873
874 return releasedCount
875}
876
877func runAllocator(ctx context.Context, a *sequenceAllocator, frequency time.Duration) (allocationCount uint64) {
878

Callers 1

Calls 3

nextSequenceMethod · 0.80

Tested by

no test coverage detected