From 3dd02580e324d04ebfe999779978b4aa0f999ccd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Dec 2010 13:25:20 +0000 Subject: [PATCH] * I forgot to catch SQLiteBusy in registerValidPaths(). So registerValidPaths() now handles busy errors and registerValidPath() is simply a wrapper around it. --- src/libstore/local-store.cc | 67 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 32c7a53305..56d05c7bb5 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -463,7 +463,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info) SQLiteStmtUse use(stmtRegisterValidPath); stmtRegisterValidPath.bind(info.path); stmtRegisterValidPath.bind("sha256:" + printHash(info.hash)); - stmtRegisterValidPath.bind(info.registrationTime); + stmtRegisterValidPath.bind(info.registrationTime == 0 ? time(0) : info.registrationTime); if (info.deriver != "") stmtRegisterValidPath.bind(info.deriver); else @@ -506,31 +506,6 @@ void LocalStore::addReference(unsigned long long referrer, unsigned long long re } -void LocalStore::registerValidPath(const ValidPathInfo & info) -{ - assert(info.hash.type == htSHA256); - ValidPathInfo info2(info); - if (info2.registrationTime == 0) info2.registrationTime = time(0); - - while (1) { - try { - SQLiteTxn txn(db); - - unsigned long long id = addValidPath(info2); - - foreach (PathSet::const_iterator, i, info2.references) - addReference(id, queryValidPathId(*i)); - - txn.commit(); - break; - } catch (SQLiteBusy & e) { - /* Retry; the `txn' destructor will roll back the current - transaction. */ - } - } -} - - void LocalStore::registerFailedPath(const Path & path) { if (hasPathFailed(path)) return; @@ -896,22 +871,40 @@ Hash LocalStore::queryPathHash(const Path & path) } +void LocalStore::registerValidPath(const ValidPathInfo & info) +{ + ValidPathInfos infos; + infos.push_back(info); + registerValidPaths(infos); +} + + void LocalStore::registerValidPaths(const ValidPathInfos & infos) { - SQLiteTxn txn(db); + while (1) { + try { + SQLiteTxn txn(db); - foreach (ValidPathInfos::const_iterator, i, infos) - /* !!! Maybe the registration info should be updated if the - path is already valid. */ - if (!isValidPath(i->path)) addValidPath(*i); + foreach (ValidPathInfos::const_iterator, i, infos) { + assert(i->hash.type == htSHA256); + /* !!! Maybe the registration info should be updated if the + path is already valid. */ + if (!isValidPath(i->path)) addValidPath(*i); + } - foreach (ValidPathInfos::const_iterator, i, infos) { - unsigned long long referrer = queryValidPathId(i->path); - foreach (PathSet::iterator, j, i->references) - addReference(referrer, queryValidPathId(*j)); + foreach (ValidPathInfos::const_iterator, i, infos) { + unsigned long long referrer = queryValidPathId(i->path); + foreach (PathSet::iterator, j, i->references) + addReference(referrer, queryValidPathId(*j)); + } + + txn.commit(); + break; + } catch (SQLiteBusy & e) { + /* Retry; the `txn' destructor will roll back the current + transaction. */ + } } - - txn.commit(); }