-
Notifications
You must be signed in to change notification settings - Fork 109
[sql-56] session: fix FeatureConfigs with an empty config set in kvdb to sql migration
#1162
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -198,6 +198,7 @@ func migrateSessionsToSQLAndValidate(ctx context.Context, | |
| overrideSessionTimeZone(migratedSession) | ||
| overrideMacaroonRecipe(kvSession, migratedSession) | ||
| overrideRemovedAccount(kvSession, migratedSession) | ||
| overrideFeatureConfig(kvSession, migratedSession) | ||
|
|
||
| if !reflect.DeepEqual(kvSession, migratedSession) { | ||
| diff := difflib.UnifiedDiff{ | ||
|
|
@@ -530,3 +531,28 @@ func overrideRemovedAccount(kvSession *Session, migratedSession *Session) { | |
| }, | ||
| ) | ||
| } | ||
|
|
||
| // overrideFeatureConfig overrides a specific feature's config for the SQL | ||
| // session in a certain scenario: | ||
| // | ||
| // In the bbolt store, an empty config for a feature is represented as an empty | ||
| // array, while in for the SQL store, the same config is represented as nil. | ||
| // Therefore, in the scenario where a specific feature has an empty config, we | ||
| // override the SQL FeatureConfig for that feature to also be set to an empty | ||
| // array. This is needed to ensure that the deep equals check in the migration | ||
| // validation does not fail in this scenario. | ||
| func overrideFeatureConfig(kvSession *Session, mSession *Session) { | ||
| // If FeatureConfig is not set for both sessions, we return early. | ||
| if kvSession.FeatureConfig == nil || mSession.FeatureConfig == nil { | ||
|
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. Should this be an |
||
| return | ||
| } | ||
|
|
||
| migratedConf := *mSession.FeatureConfig | ||
| for featureName, config := range *kvSession.FeatureConfig { | ||
| // If the config is empty for the feature, we override | ||
| // the SQL version. | ||
| if len(config) == 0 { | ||
| migratedConf[featureName] = make([]byte, 0) | ||
|
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. What if we erroneously migrated an empty feature config to a non-empty one, then we'd silently override the migrated one, right? So maybe we could just convert the migrated config if it is nil to an empty one? |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach would be to convert
nilconfigs to empty ones inunmarshalFeatureConfigs. Wouldn't that be better because that way we ensure that both session (kvdb/sql) retrievals are consistent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this offline, and we decided to continue with the override approach in favour of changing the
unmarshalfunction. While that approach will likely work, we'll keep the same approach we've used to tackle similar issues previously, and consider to in the future instead change to theunmarshalapproach. But when doing so, we'll change for all current overrides, and not just this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a call-site perspective I think it's fine to keep the
nilherelightning-terminal/session_rpcserver.go
Lines 1550 to 1555 in 5e22106
This just leads to an empty string.