Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvement while saving metadata #41

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions couchbase/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package couchbase
import (
"context"
"errors"
"golang.org/x/sync/errgroup"
"strconv"
"sync"

Expand Down Expand Up @@ -30,18 +31,15 @@ func (s *cbMetadata) Save(state map[uint16]*models.CheckpointDocument, dirtyOffs
ctx, cancel := context.WithTimeout(context.Background(), s.config.Checkpoint.Timeout)
defer cancel()

errCh := make(chan error, 1)

go func(ctx context.Context) {
var err error

for vbID, checkpointDocument := range state {
if !dirtyOffsets[vbID] {
continue
}
eg, _ := errgroup.WithContext(ctx)

for vbID, checkpointDocument := range state {
if !dirtyOffsets[vbID] {
continue
}
eg.Go(func() error {
id := getCheckpointID(vbID, s.config.Dcp.Group.Name)
err = s.upsertXattrs(ctx, s.scopeName, s.collectionName, id, helpers.Name, checkpointDocument, 0)
err := s.upsertXattrs(ctx, s.scopeName, s.collectionName, id, helpers.Name, checkpointDocument, 0)

var kvErr *gocbcore.KeyValueError
if err != nil && errors.As(err, &kvErr) && kvErr.StatusCode == memd.StatusKeyNotFound {
Expand All @@ -51,21 +49,10 @@ func (s *cbMetadata) Save(state map[uint16]*models.CheckpointDocument, dirtyOffs
err = s.upsertXattrs(ctx, s.scopeName, s.collectionName, id, helpers.Name, checkpointDocument, 0)
}
}

if err != nil {
break
}
}

errCh <- err
}(ctx)

select {
case <-ctx.Done():
return ctx.Err()
case err := <-errCh:
return err
return err
})
}
return eg.Wait()
}

func (s *cbMetadata) getXattrs(scopeName string, collectionName string, id []byte, path string) ([]byte, error) {
Expand Down