From 3a99616968a7ffcc8f51bda7a781d3233aa9b428 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 9 Feb 2005 14:37:24 +0000 Subject: [PATCH] * Commit more often to prevent out-of-memory errors. --- src/libstore/db.cc | 16 ++++++++++++---- src/libstore/db.hh | 1 + src/libstore/store.cc | 9 +++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libstore/db.cc b/src/libstore/db.cc index 4a815a5f9..82211bd1d 100644 --- a/src/libstore/db.cc +++ b/src/libstore/db.cc @@ -33,11 +33,9 @@ Transaction::Transaction() Transaction::Transaction(Database & db) + : txn(0) { - db.requireEnv(); - try { - db.env->txn_begin(0, &txn, 0); - } catch (DbException e) { rethrow(e); } + begin(db); } @@ -47,6 +45,16 @@ Transaction::~Transaction() } +void Transaction::begin(Database & db) +{ + assert(txn == 0); + db.requireEnv(); + try { + db.env->txn_begin(0, &txn, 0); + } catch (DbException e) { rethrow(e); } +} + + void Transaction::commit() { if (!txn) throw Error("commit called on null transaction"); diff --git a/src/libstore/db.hh b/src/libstore/db.hh index d566fdad1..841836492 100644 --- a/src/libstore/db.hh +++ b/src/libstore/db.hh @@ -27,6 +27,7 @@ public: Transaction(Database & _db); ~Transaction(); + void begin(Database & db); void abort(); void commit(); diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 5516dc801..f73e993b8 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -824,6 +824,7 @@ static void upgradeStore() PathSet validPaths(validPaths2.begin(), validPaths2.end()); cerr << "hashing paths..."; + int n = 0; for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) { checkInterrupt(); string s; @@ -832,10 +833,18 @@ static void upgradeStore() Hash hash = hashPath(htSHA256, *i); setHash(txn, *i, hash); cerr << "."; + if (++n % 1000 == 0) { + txn.commit(); + txn.begin(nixDB); + } } } cerr << "\n"; + txn.commit(); + + txn.begin(nixDB); + cerr << "processing closures..."; for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) { checkInterrupt();