From d87549c1c7bb6f85ff0a019b33b315ace0013e6b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Dec 2005 19:14:38 +0000 Subject: [PATCH] * Automatically delete the old referers table. --- src/libstore/db.cc | 28 ++++++++++++++++++++++++---- src/libstore/db.hh | 2 ++ src/libstore/store.cc | 6 +++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/libstore/db.cc b/src/libstore/db.cc index 74c933d0e..7ded82ef1 100644 --- a/src/libstore/db.cc +++ b/src/libstore/db.cc @@ -292,11 +292,12 @@ void Database::close() try { for (map::iterator i = tables.begin(); - i != tables.end(); i++) + i != tables.end(); ) { - Db * db = i->second; - db->close(DB_NOSYNC); - delete db; + map::iterator j = i; + ++j; + closeTable(i->first); + i = j; } /* Do a checkpoint every 128 kilobytes, or every 5 minutes. */ @@ -336,6 +337,25 @@ TableId Database::openTable(const string & tableName, bool sorted) } +void Database::closeTable(TableId table) +{ + try { + Db * db = getDb(table); + db->close(DB_NOSYNC); + delete db; + tables.erase(table); + } catch (DbException e) { rethrow(e); } +} + + +void Database::deleteTable(const string & table) +{ + try { + env->dbremove(0, table.c_str(), 0, DB_AUTO_COMMIT); + } catch (DbException e) { rethrow(e); } +} + + bool Database::queryString(const Transaction & txn, TableId table, const string & key, string & data) { diff --git a/src/libstore/db.hh b/src/libstore/db.hh index b7ebd4467..dd7d76b8c 100644 --- a/src/libstore/db.hh +++ b/src/libstore/db.hh @@ -65,6 +65,8 @@ public: void close(); TableId openTable(const string & table, bool sorted = false); + void closeTable(TableId table); + void deleteTable(const string & table); bool queryString(const Transaction & txn, TableId table, const string & key, string & data); diff --git a/src/libstore/store.cc b/src/libstore/store.cc index fbbf12269..db12ba2d5 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -1034,8 +1034,12 @@ static void upgradeStore09() nixDB.setString(txn, dbReferrers, addPrefix(*i, *j), ""); cerr << "."; } - + cerr << "\n"; txn.commit(); + + nixDB.closeTable(dbReferers); + + nixDB.deleteTable("referers"); }