* Split the database upgrade into multiple transactions to prevent

Berkeley DB from running out of locks.
This commit is contained in:
Eelco Dolstra 2005-12-15 16:53:21 +00:00
parent 11a8dc76d6
commit b1eed6b586

View file

@ -1012,6 +1012,8 @@ static void upgradeStore07()
(and properly spelled) `referrer' table. */ (and properly spelled) `referrer' table. */
static void upgradeStore09() static void upgradeStore09()
{ {
/* !!! we should disallow concurrent upgrades */
printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)..."); printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
if (!pathExists(nixDBPath + "/referers")) return; if (!pathExists(nixDBPath + "/referers")) return;
@ -1024,6 +1026,8 @@ static void upgradeStore09()
Paths referersKeys; Paths referersKeys;
nixDB.enumTable(txn, dbReferers, referersKeys); nixDB.enumTable(txn, dbReferers, referersKeys);
int n = 0;
for (Paths::iterator i = referersKeys.begin(); for (Paths::iterator i = referersKeys.begin();
i != referersKeys.end(); ++i) i != referersKeys.end(); ++i)
{ {
@ -1032,13 +1036,18 @@ static void upgradeStore09()
for (Paths::iterator j = referers.begin(); for (Paths::iterator j = referers.begin();
j != referers.end(); ++j) j != referers.end(); ++j)
nixDB.setString(txn, dbReferrers, addPrefix(*i, *j), ""); nixDB.setString(txn, dbReferrers, addPrefix(*i, *j), "");
if (++n % 1000 == 0) {
txn.commit();
txn.begin(nixDB);
cerr << "|";
}
cerr << "."; cerr << ".";
} }
cerr << "\n";
txn.commit(); txn.commit();
cerr << "\n";
nixDB.closeTable(dbReferers); nixDB.closeTable(dbReferers);
nixDB.deleteTable("referers"); nixDB.deleteTable("referers");