init: bound the notarizations LOCK wait by wall-clock time

The wait for another process to release notarizations/LOCK counted 1 s
sleeps, so the time spent probing and a loaded machine stretched the
"up to 30 s" to 33-34 s. Wait against a GetTimeMillis() deadline instead,
and report the measured elapsed time in the "released after" and "still
could not be taken after" lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 12:21:55 -05:00
co-authored by Claude Opus 5.5
parent 8f70f494b3
commit 2bc4a70eb8
+7 -6
View File
@@ -170,12 +170,12 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe)
std::string strError;
bool fWaited = false; // the bounded wait for the lock has been used up
bool fProbedFree = false; // the probe right before the last open attempt found the lock free
int nWaited = 0;
int64_t nWaitStart = 0;
while (true) {
try {
NotarizationDB* pdb = new NotarizationDB(NOTARIZATION_DB_CACHE_BYTES, false, fWipe);
if (fWaited)
LogPrintf("%s: notarizations/LOCK released after %d s; notarizations DB opened\n", __func__, nWaited);
LogPrintf("%s: notarizations/LOCK released after %d s; notarizations DB opened\n", __func__, (GetTimeMillis() - nWaitStart) / 1000);
else if (fProbedFree)
LogPrintf("%s: notarizations DB opened on retry (notarizations/LOCK was released after the first attempt)\n", __func__);
return pdb;
@@ -191,9 +191,10 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe)
LogPrintf("%s: notarizations DB failed to open (%s): notarizations/LOCK could not be taken (%s); waiting for a previous dragonxd to release notarizations/LOCK (up to %d s)\n",
__func__, strError, lockStatus.ToString(), NOTARIZATION_LOCK_WAIT_SECONDS);
fWaited = true;
while (nWaited < NOTARIZATION_LOCK_WAIT_SECONDS && !ShutdownRequested()) {
MilliSleep(1000);
nWaited++;
nWaitStart = GetTimeMillis();
const int64_t nDeadline = nWaitStart + NOTARIZATION_LOCK_WAIT_SECONDS * 1000LL;
while (GetTimeMillis() < nDeadline && !ShutdownRequested()) {
MilliSleep(std::min<int64_t>(1000, std::max<int64_t>(1, nDeadline - GetTimeMillis())));
lockStatus = ProbeLevelDBLock(ndir);
if (lockStatus.ok())
break;
@@ -201,7 +202,7 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe)
}
if (!lockStatus.ok()) {
LogPrintf("%s: notarizations/LOCK still could not be taken after %d s (%s); using an in-memory notarizations DB for this run (on-disk notarizations DB left untouched)\n",
__func__, nWaited, lockStatus.ToString());
__func__, (GetTimeMillis() - nWaitStart) / 1000, lockStatus.ToString());
return new NotarizationDB(NOTARIZATION_DB_CACHE_BYTES, true, false);
}
}