Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-3557

[3.1.2 backport] Improve behaviour when allocating sequence much lower than existing doc seq

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • 3.1.2
    • None
    • SyncGateway
    • Security Level: Public
    • None
    • 3

    Description

      SG creates a new unused sequence for every sequence between nextSequence and the one inside the existing doc metadata.

      In cases where the _sync:seq has been reset/wiped this can cause potentially millions of documents to be created with a short TTL.

      If we're able to detect this case, we can create one range of unused sequences to save a lot of work and warn that there's something odd occurring that needs further attention (they need to regenerate sequences)

       

      		for {
      			var err error
      			if docSequence, err = db.sequences.nextSequence(ctx); err != nil {
      				return unusedSequences, err
      			}
       
      			if docSequence > doc.Sequence {
      				break
      			} else {
      				if err := db.sequences.releaseSequence(ctx, docSequence); err != nil {
      					base.WarnfCtx(ctx, "Error returned when releasing sequence %d. Falling back to skipped sequence handling.  Error:%v", docSequence, err)
      				}
      			}
      		}
      		// Could add a db.Sequences.nextSequenceGreaterThan(doc.Sequence) to push the work down into the sequence allocator
      		//  - sequence allocator is responsible for releasing unused sequences, could optimize to do that in bulk if needed
      

      https://github.com/couchbase/sync_gateway/blob/d183dbe21c1296138dd2f8ae898a4848b14ac135/db/crud.go#L1612-L1627

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ben.brooks Ben Brooks
              adamf Adam Fraser
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty