Skip to content

Commit ec497ab

Browse files
committed
wip
1 parent 94a01d7 commit ec497ab

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

base/dcp_client_metadata.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ func (m *DCPMetadataCS) Persist(ctx context.Context, workerID int, vbIDs []uint1
228228
for _, vbID := range vbIDs {
229229
meta.DCPMeta[vbID] = m.metadata[vbID]
230230
}
231-
fmt.Printf("HONK m.setMetadataKey(workerID): %s\n", m.getMetadataKey(workerID))
232231
err := m.dataStore.Set(m.getMetadataKey(workerID), 0, nil, meta)
233232
if err != nil {
234233
InfofCtx(ctx, KeyDCP, "Unable to persist DCP metadata: %v", err)
@@ -240,7 +239,6 @@ func (m *DCPMetadataCS) Persist(ctx context.Context, workerID int, vbIDs []uint1
240239

241240
func (m *DCPMetadataCS) load(ctx context.Context, workerID int) {
242241
var meta WorkerMetadata
243-
fmt.Printf("HONK m.getMetadataKey(workerID): %s\n", m.getMetadataKey(workerID))
244242
_, err := m.dataStore.Get(m.getMetadataKey(workerID), &meta)
245243
if err != nil {
246244
if IsDocNotFoundError(err) {

base/dcp_client_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestOneShotDCP(t *testing.T) {
5151
}
5252

5353
dcpOptions := DCPClientOptions{
54-
ID: t.Name(),
54+
ID: t.Name() + UUID(t),
5555
CollectionNames: CollectionNames{
5656
dataStore.ScopeName(): {dataStore.CollectionName()},
5757
},
@@ -112,7 +112,7 @@ func TestTerminateDCPFeed(t *testing.T) {
112112
}
113113

114114
dcpOptions := DCPClientOptions{
115-
ID: t.Name(),
115+
ID: t.Name() + UUID(t),
116116
CollectionNames: map[string][]string{
117117
dataStore.ScopeName(): {dataStore.CollectionName()},
118118
},
@@ -207,8 +207,6 @@ func TestDCPClientMultiFeedConsistency(t *testing.T) {
207207
return false
208208
}
209209

210-
feedID := t.Name()
211-
212210
// Add documents
213211
updatedBody := map[string]any{"foo": "bar"}
214212
for i := range 10000 {
@@ -225,7 +223,7 @@ func TestDCPClientMultiFeedConsistency(t *testing.T) {
225223
CollectionNames: collectionNames,
226224
CheckpointPrefix: DefaultMetadataKeys.DCPCheckpointPrefix(t.Name()),
227225
Callback: counterCallback,
228-
ID: feedID,
226+
ID: t.Name() + UUID(t),
229227
}
230228

231229
dcpClient, err := NewDCPClient(ctx, bucket, dcpClientOpts)
@@ -256,7 +254,7 @@ func TestDCPClientMultiFeedConsistency(t *testing.T) {
256254
uuidMismatchMetadata[0].SnapEndSeqNo = test.startSeqNo
257255

258256
dcpClientOpts = DCPClientOptions{
259-
ID: feedID,
257+
ID: t.Name() + UUID(t),
260258
CollectionNames: collectionNames,
261259
InitialMetadata: uuidMismatchMetadata,
262260
FailOnRollback: true,
@@ -276,7 +274,7 @@ func TestDCPClientMultiFeedConsistency(t *testing.T) {
276274
// Perform a third DCP feed - mismatched VbUUID, failOnRollback=false
277275
atomic.StoreUint64(&mutationCount, 0)
278276
dcpClientOpts = DCPClientOptions{
279-
ID: feedID,
277+
ID: t.Name() + UUID(t),
280278
InitialMetadata: uuidMismatchMetadata,
281279
FailOnRollback: false,
282280
OneShot: true,
@@ -688,7 +686,7 @@ func TestDCPFeedEventTypes(t *testing.T) {
688686
return true
689687
}
690688
clientOptions := DCPClientOptions{
691-
ID: t.Name(),
689+
ID: t.Name() + UUID(t),
692690
CollectionNames: collectionNames,
693691
CheckpointPrefix: DefaultMetadataKeys.DCPCheckpointPrefix(t.Name()),
694692
Callback: callback,
@@ -777,7 +775,7 @@ func TestDCPClientAgentConfig(t *testing.T) {
777775
defer func() { gocbv2Bucket.Spec.Server = oldBucketSpecServer }()
778776
gocbv2Bucket.Spec.Server += tc.serverSuffix
779777
opts := DCPClientOptions{
780-
ID: "fakeFeedID",
778+
ID: "fakeFeedID" + UUID(t),
781779
CollectionNames: CollectionNames{
782780
bucket.GetSingleDataStore().ScopeName(): {bucket.GetSingleDataStore().CollectionName()},
783781
},

base/util_testing.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/couchbase/gocb/v2"
3737
sgbucket "github.com/couchbase/sg-bucket"
3838
"github.com/couchbaselabs/rosmar"
39+
"github.com/google/uuid"
3940
"github.com/stretchr/testify/assert"
4041
"github.com/stretchr/testify/require"
4142
)
@@ -1023,3 +1024,9 @@ func RequireXattrNotFound(t testing.TB, dataStore sgbucket.DataStore, docID stri
10231024
func underGoTest() bool {
10241025
return testing.Testing()
10251026
}
1027+
1028+
func UUID(t testing.TB) string {
1029+
id, err := uuid.NewRandom()
1030+
require.NoError(t, err)
1031+
return id.String()
1032+
}

db/background_mgr_attachment_migration.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,24 @@ func (a *AttachmentMigrationManager) Run(ctx context.Context, options map[string
162162
if err != nil {
163163
return err
164164
}
165-
dcpFeedKey, err := GenerateAttachmentMigrationDCPStreamName(a.MigrationID)
165+
dcpOptions, err := getMigrationDCPClientOptions(db, a.MigrationID, scopes, callback)
166166
if err != nil {
167167
return err
168168
}
169-
dcpPrefix := db.MetadataKeys.DCPCheckpointPrefix(db.Options.GroupID)
170169

171170
// check for mismatch in collection id's between current collections on the db and prev run
172-
checkpointPrefix := fmt.Sprintf("%s:%v", dcpPrefix, dcpFeedKey)
173-
err = a.resetDCPMetadataIfNeeded(ctx, db, checkpointPrefix, currCollectionIDs)
171+
err = a.resetDCPMetadataIfNeeded(ctx, db, dcpOptions.CheckpointPrefix, currCollectionIDs)
174172
if err != nil {
175173
return err
176174
}
177175

178176
a.SetCollectionIDs(currCollectionIDs)
179-
dcpOptions := getMigrationDCPClientOptions(scopes, dcpPrefix)
180-
dcpOptions.ID = dcpFeedKey
181-
dcpOptions.Callback = callback
182177
dcpClient, err := base.NewDCPClient(ctx, db.Bucket, dcpOptions)
183178
if err != nil {
184179
base.WarnfCtx(ctx, "[%s] Failed to create attachment migration DCP client: %v", migrationLoggingID, err)
185180
return err
186181
}
187-
base.DebugfCtx(ctx, base.KeyAll, "[%s] Starting DCP feed %q for attachment migration", migrationLoggingID, dcpFeedKey)
182+
base.DebugfCtx(ctx, base.KeyAll, "[%s] Starting DCP feed for attachment migration", migrationLoggingID)
188183

189184
doneChan, err := dcpClient.Start(ctx)
190185
if err != nil {
@@ -283,14 +278,22 @@ func (a *AttachmentMigrationManager) GetProcessStatus(status BackgroundManagerSt
283278
return statusJSON, metaJSON, err
284279
}
285280

286-
func getMigrationDCPClientOptions(scopes base.CollectionNames, prefix string) base.DCPClientOptions {
281+
func getMigrationDCPClientOptions(db *DatabaseContext, migrationID string, scopes base.CollectionNames, callback sgbucket.FeedEventCallbackFunc) (base.DCPClientOptions, error) {
282+
prefix := getAttachmentMigrationPrefix(migrationID)
283+
284+
feedID, err := base.GenerateDcpStreamName(prefix)
285+
if err != nil {
286+
return base.DCPClientOptions{}, err
287+
}
287288
return base.DCPClientOptions{
289+
ID: feedID,
288290
OneShot: true,
289291
FailOnRollback: false,
290292
MetadataStoreType: base.DCPMetadataStoreCS,
291293
CollectionNames: scopes,
292-
CheckpointPrefix: prefix,
293-
}
294+
CheckpointPrefix: fmt.Sprintf("%s:%v", db.MetadataKeys.DCPCheckpointPrefix(db.Options.GroupID), prefix),
295+
Callback: callback,
296+
}, nil
294297
}
295298

296299
type AttachmentMigrationManagerResponse struct {
@@ -310,12 +313,12 @@ type AttachmentMigrationManagerStatusDoc struct {
310313
AttachmentMigrationMeta `json:"meta"`
311314
}
312315

313-
// GenerateAttachmentMigrationDCPStreamName returns the DCP stream name for attachment migration job.
314-
func GenerateAttachmentMigrationDCPStreamName(migrationID string) (string, error) {
315-
return base.GenerateDcpStreamName(fmt.Sprintf(
316+
// getAttachmentMigrationPrefix returns a prefix for identifying attachment migration dcp feed and checkpoints.
317+
func getAttachmentMigrationPrefix(migrationID string) string {
318+
return fmt.Sprintf(
316319
"sg-%v:att_migration:%v",
317320
base.ProductAPIVersion,
318-
migrationID))
321+
migrationID)
319322
}
320323

321324
// resetDCPMetadataIfNeeded will check for mismatch between current collectionIDs and collectionIDs on previous run

0 commit comments

Comments
 (0)