-
Notifications
You must be signed in to change notification settings - Fork 141
CBG-5153: Implement resync using CBGT for a single node #8057
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
base: main
Are you sure you want to change the base?
Changes from all commits
6b222a1
6dd1179
046136b
7bbc91d
58e51db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ pipeline { | |
| } | ||
|
|
||
| tools { | ||
| go '1.25.6' | ||
| go '1.25.7' | ||
| } | ||
|
|
||
| stages { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ const ( | |
| CBGTCfgNodeDefsKnown = SyncDocPrefix + "cfgnodeDefs-known" | ||
| CBGTCfgNodeDefsWanted = SyncDocPrefix + "cfgnodeDefs-wanted" | ||
| CBGTCfgPlanPIndexes = SyncDocPrefix + "cfgplanPIndexes" | ||
| CBGTIndexTypeSyncGatewayResync = "syncGateway-resync-" | ||
| ) | ||
|
|
||
| // firstVersionToSupportCollections represents the earliest Sync Gateway release that supports collections. | ||
|
|
@@ -42,6 +43,18 @@ var firstVersionToSupportCollections = &ComparableBuildVersion{ | |
| patch: 0, | ||
| } | ||
|
|
||
| type DestType int | ||
|
|
||
| const ( | ||
| ImportDestType DestType = iota // "import" | ||
| ResyncDestType // "resync" | ||
| ) | ||
RIT3shSapata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var destTypeNames = []string{ | ||
| "import", | ||
| "resync", | ||
| } | ||
|
|
||
| // nodeExtras is the contents of the JSON value of the cbgt.NodeDef.Extras field as used by Sync Gateway. | ||
| type nodeExtras struct { | ||
| // Version is the node's version. | ||
|
|
@@ -63,7 +76,7 @@ type CbgtContext struct { | |
|
|
||
| // StartShardedDCPFeed initializes and starts a CBGT Manager targeting the provided bucket. | ||
| // dbName is used to define a unique path name for local file storage of pindex files | ||
| func StartShardedDCPFeed(ctx context.Context, dbName string, configGroup string, uuid string, heartbeater Heartbeater, bucket Bucket, spec BucketSpec, scope string, collections []string, numPartitions uint16, cfg cbgt.Cfg) (*CbgtContext, error) { | ||
| func StartShardedDCPFeed(ctx context.Context, dbName string, configGroup string, uuid string, heartbeater Heartbeater, bucket Bucket, spec BucketSpec, scope string, collections []string, numPartitions uint16, cfg cbgt.Cfg, resyncIndex bool) (*CbgtContext, error) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could take It might be worth figuring out below what is actually needed to do to split on the feed type and whether to pass these arguments into this function or pass a type parameter. Review this comment after looking through the rest of the code and the comments. |
||
| // Ensure we don't try to start collections-enabled feed if there are any pre-collection SG nodes in the cluster. | ||
| minVersion, err := getMinNodeVersion(cfg) | ||
| if err != nil { | ||
|
|
@@ -85,7 +98,7 @@ func StartShardedDCPFeed(ctx context.Context, dbName string, configGroup string, | |
| ctx = CorrelationIDLogCtx(ctx, DCPImportFeedID) | ||
|
|
||
| // Start Manager. Registers this node in the cfg | ||
| err = cbgtContext.StartManager(ctx, dbName, configGroup, bucket, scope, collections, numPartitions) | ||
| err = cbgtContext.StartManager(ctx, dbName, configGroup, bucket, scope, collections, numPartitions, resyncIndex) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -120,15 +133,21 @@ func GenerateLegacyIndexName(dbName string) string { | |
| // to the manager's cbgt cfg. Nodes that have registered for this indexType with the manager via | ||
| // RegisterPIndexImplType (see importListener.RegisterImportPindexImpl) | ||
| // will receive PIndexImpl callbacks (New, Open) for assigned PIndex to initiate DCP processing. | ||
| func createCBGTIndex(ctx context.Context, c *CbgtContext, dbName string, configGroupID string, bucket Bucket, scope string, collections []string, numPartitions uint16) error { | ||
| func createCBGTIndex(ctx context.Context, c *CbgtContext, dbName string, configGroupID string, bucket Bucket, scope string, collections []string, numPartitions uint16, resyncIndex bool) error { | ||
| sourceType := SOURCE_DCP_SG | ||
|
|
||
| sourceParams, err := cbgtFeedParams(ctx, scope, collections, dbName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| indexParams, err := cbgtIndexParams(ImportDestKey(dbName, scope, collections)) | ||
| var destType DestType | ||
| if resyncIndex { | ||
| destType = ResyncDestType | ||
| } else { | ||
| destType = ImportDestType | ||
| } | ||
| indexParams, err := cbgtIndexParams(DestKey(dbName, scope, collections, destType)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -156,7 +175,12 @@ func createCBGTIndex(ctx context.Context, c *CbgtContext, dbName string, configG | |
|
|
||
| // Index types are namespaced by configGroupID to support delete and create of a database targeting the | ||
| // same bucket in a config group | ||
| indexType := CBGTIndexTypeSyncGatewayImport + configGroupID | ||
| var indexType string | ||
| if resyncIndex { | ||
| indexType = CBGTIndexTypeSyncGatewayResync + configGroupID | ||
| } else { | ||
| indexType = CBGTIndexTypeSyncGatewayImport + configGroupID | ||
| } | ||
| err = c.Manager.CreateIndex( | ||
| sourceType, // sourceType | ||
| c.sourceName, // bucket name | ||
|
|
@@ -361,7 +385,7 @@ func initCBGTManager(ctx context.Context, bucket Bucket, spec BucketSpec, cfgSG | |
| } | ||
|
|
||
| // StartManager registers this node with cbgt, and the janitor will start feeds on this node. | ||
| func (c *CbgtContext) StartManager(ctx context.Context, dbName string, configGroup string, bucket Bucket, scope string, collections []string, numPartitions uint16) (err error) { | ||
| func (c *CbgtContext) StartManager(ctx context.Context, dbName string, configGroup string, bucket Bucket, scope string, collections []string, numPartitions uint16, resyncIndex bool) (err error) { | ||
| // TODO: Clarify the functional difference between registering the manager as 'wanted' vs 'known'. | ||
| registerType := cbgt.NODE_DEFS_WANTED | ||
| if err := c.Manager.Start(registerType); err != nil { | ||
|
|
@@ -370,7 +394,7 @@ func (c *CbgtContext) StartManager(ctx context.Context, dbName string, configGro | |
| } | ||
|
|
||
| // Add the index definition for this feed to the cbgt cfg, in case it's not already present. | ||
| err = createCBGTIndex(ctx, c, dbName, configGroup, bucket, scope, collections, numPartitions) | ||
| err = createCBGTIndex(ctx, c, dbName, configGroup, bucket, scope, collections, numPartitions, resyncIndex) | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), "an index with the same name already exists") { | ||
| InfofCtx(ctx, KeyCluster, "Duplicate cbgt index detected during index creation (concurrent creation), using existing") | ||
|
|
@@ -458,10 +482,11 @@ func (c *CbgtContext) RemoveFeedCredentials(dbName string) { | |
| } | ||
|
|
||
| // Format of dest key for retrieval of import dest from cbgtDestFactories | ||
| func ImportDestKey(dbName string, scope string, collections []string) string { | ||
| func DestKey(dbName string, scope string, collections []string, destType DestType) string { | ||
| sort.Strings(collections) | ||
| collectionString := "" | ||
| onlyDefault := true | ||
| destTypeName := destTypeNames[destType] | ||
| for _, collection := range collections { | ||
| if collection != DefaultCollection { | ||
| onlyDefault = false | ||
|
|
@@ -470,9 +495,9 @@ func ImportDestKey(dbName string, scope string, collections []string) string { | |
| } | ||
| // format for _default._default | ||
| if collectionString == "" || (scope == DefaultScope && onlyDefault) { | ||
| return fmt.Sprintf("%s_import", dbName) | ||
| return fmt.Sprintf("%s_%s", dbName, destTypeName) | ||
| } | ||
| return fmt.Sprintf("%s_import_%x", dbName, sha256.Sum256([]byte(collectionString))) | ||
| return fmt.Sprintf("%s_%s_%x", dbName, destTypeName, sha256.Sum256([]byte(collectionString))) | ||
| } | ||
|
|
||
| func registerHeartbeatListener(ctx context.Context, heartbeater Heartbeater, cbgtContext *CbgtContext) (*importHeartbeatListener, error) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.