mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr.git
synced 2025-10-23 08:22:12 +00:00
db: flush after changing schema version
Flush the cache after changing the version, to make the scenario less likely that after an unclean shutdown the DB gets restored with the right table layout but wrong version. When that happens, osmo-hlr tries to upgrade the database layout again and fails with errors like "duplicate column name". Related: SYS#7394 Change-Id: I5943a1cb3447c038c6e7972f68f9656b73a9248b
This commit is contained in:
9
src/db.c
9
src/db.c
@@ -595,6 +595,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
int rc;
|
||||
bool has_sqlite_config_sqllog = false;
|
||||
int version;
|
||||
bool version_changed = false;
|
||||
|
||||
LOGP(DDB, LOGL_NOTICE, "using database: %s\n", fname);
|
||||
LOGP(DDB, LOGL_INFO, "Compiled against SQLite3 lib version %s\n", SQLITE_VERSION);
|
||||
@@ -672,6 +673,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
goto out_free;
|
||||
}
|
||||
version = CURRENT_SCHEMA_VERSION;
|
||||
version_changed = true;
|
||||
}
|
||||
|
||||
LOGP(DDB, LOGL_NOTICE, "Database '%s' has HLR DB schema version %d\n", dbc->fname, version);
|
||||
@@ -686,6 +688,7 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
}
|
||||
LOGP(DDB, LOGL_NOTICE, "Database '%s' has been upgraded to HLR DB schema version %d\n",
|
||||
dbc->fname, version+1);
|
||||
version_changed = true;
|
||||
}
|
||||
|
||||
if (version != CURRENT_SCHEMA_VERSION) {
|
||||
@@ -702,6 +705,12 @@ struct db_context *db_open(void *ctx, const char *fname, bool enable_sqlite_logg
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
/* Flush the cache after changing the version, to make the scenario
|
||||
* less likely that after an unclean shutdown the DB gets restored
|
||||
* with the right table layout but wrong version (SYS#7394). */
|
||||
if (version_changed)
|
||||
sqlite3_db_cacheflush(dbc->db);
|
||||
|
||||
/* prepare all SQL statements */
|
||||
for (i = 0; i < ARRAY_SIZE(dbc->stmt); i++) {
|
||||
rc = sqlite3_prepare_v2(dbc->db, stmt_sql[i], -1,
|
||||
|
Reference in New Issue
Block a user