graph/db+sqldb: make policy migration idempotent
Finally, we make the channel-policy part of the SQL migration idempotent by adding a migration-only policy insert query which will not error out if the policy already exists and does not have a timestamp that is newer than the existing records timestamp. To keep the commit simple, a insertChanEdgePolicyMig function is added which is basically identical to the updateChanEdgePolicy function except for the fact that it uses the newly added query. In the next commit, it will be simplified even more.
This commit is contained in:
6 files changed
+221
-23
No files matched your search
@@ -105,15 +105,6 @@ func TestMigrateGraphToSQL(t *testing.T) {
|
||||
write func(t *testing.T, db *KVStore, object any)
|
||||
objects []any
|
||||
expGraphStats graphStats
|
||||
|
||||
// expNotRetrySafety is true if we expect an error to occur for
|
||||
// the test if the migration is run twice. In other-words, if
|
||||
// the specific case in question is currently not idempotent.
|
||||
//
|
||||
// NOTE: we want _all_ the cases here to be idempotent, so this
|
||||
// is a temporary field which will be removed once we have
|
||||
// properly made the migration retry-safe.
|
||||
expNotRetrySafety bool
|
||||
}{
|
||||
{
|
||||
name: "empty",
|
||||
@@ -297,7 +288,6 @@ func TestMigrateGraphToSQL(t *testing.T) {
|
||||
numChannels: 3,
|
||||
numPolicies: 3,
|
||||
},
|
||||
expNotRetrySafety: true,
|
||||
},
|
||||
{
|
||||
name: "prune log",
|
||||
@@ -409,19 +399,11 @@ func TestMigrateGraphToSQL(t *testing.T) {
|
||||
// Validate that the two databases are now in sync.
|
||||
assertInSync(t, kvDB, sql, test.expGraphStats)
|
||||
|
||||
// NOTE: for now, not all the cases in the test are
|
||||
// retry safe! The aim is to completely remove this
|
||||
// field once we have made the migration retry-safe.
|
||||
// The migration should be retry-safe, so running it
|
||||
// again should not change the state of the databases.
|
||||
err = MigrateGraphToSQL(ctx, sql.cfg, kvDB.db, sql.db)
|
||||
if !test.expNotRetrySafety {
|
||||
// The migration should be retry-safe, so
|
||||
// running it again should not change the state
|
||||
// of the databases.
|
||||
require.NoError(t, err)
|
||||
assertInSync(t, kvDB, sql, test.expGraphStats)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
assertInSync(t, kvDB, sql, test.expGraphStats)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user