From 3b67fc6488ac10ca13561d9032f59951f82203e6 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 29 Jun 2016 18:37:02 +0200 Subject: SYSDB: Remove the timestamps cache on update When the cache is upgraded, we want to avoid upgrading the timestamps cache, because it was only introduced recently in Beta, so it doesn't make senes to write complex code to change the format. This patch rather removes the cache during upgrade, it will be recreated with later lookups anyway. Reviewed-by: Sumit Bose --- src/db/sysdb_init.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c index fc7e13ac1..b713a65d3 100644 --- a/src/db/sysdb_init.c +++ b/src/db/sysdb_init.c @@ -612,6 +612,22 @@ done: return ret; } +static errno_t remove_ts_cache(struct sysdb_ctx *sysdb) +{ + errno_t ret; + + if (sysdb->ldb_ts_file == NULL) { + return EOK; + } + + ret = unlink(sysdb->ldb_ts_file); + if (ret != EOK && errno != ENOENT) { + return errno; + } + + return EOK; +} + static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb, struct sss_domain_info *domain, struct sysdb_dom_upgrade_ctx *upgrade_ctx) @@ -644,6 +660,18 @@ static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb, goto done; } + /* To be on the safe side, nuke the timestamp cache on upgrades. + * This is just a one-time performance hit after an upgrade + */ + ret = remove_ts_cache(sysdb); + if (ret != EOK) { + DEBUG(SSSDBG_MINOR_FAILURE, + "Could not delete the timestamp ldb file (%d) (%s)\n", + ret, sss_strerror(ret)); + return ret; + } + + /* The version should now match SYSDB_VERSION. * If not, it means we didn't match any of the * known older versions. The DB might be @@ -755,9 +783,8 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb, "The timestamps cache could not be opened. " "Throwing away the database and opening a new one\n"); - ret = unlink(sysdb->ldb_ts_file); - if (ret != EOK && errno != ENOENT) { - ret = errno; + ret = remove_ts_cache(sysdb); + if (ret != EOK) { DEBUG(SSSDBG_MINOR_FAILURE, "Could not delete the timestamp ldb file (%d) (%s)\n", ret, sss_strerror(ret)); -- cgit