Improved locking code

This commit is contained in:
Andrew Kane
2024-01-08 09:05:12 -08:00
parent 520e274dde
commit 62ee33bb92

View File

@@ -432,21 +432,18 @@ BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
return; return;
/* Flush pages if needed */ /* Flush pages if needed */
HnswLockAcquire(hnswshared);
if (!graph->flushed && graph->memoryUsed >= graph->memoryTotal) if (!graph->flushed && graph->memoryUsed >= graph->memoryTotal)
{ {
HnswLockAcquire(hnswshared);
if (!hnswshared) if (!hnswshared)
ereport(NOTICE, ereport(NOTICE,
(errmsg("hnsw graph no longer fits into maintenance_work_mem after " INT64_FORMAT " tuples", (int64) graph->indtuples), (errmsg("hnsw graph no longer fits into maintenance_work_mem after " INT64_FORMAT " tuples", (int64) graph->indtuples),
errdetail("Building will take significantly more time."), errdetail("Building will take significantly more time."),
errhint("Increase maintenance_work_mem to speed up builds."))); errhint("Increase maintenance_work_mem to speed up builds.")));
if (!graph->flushed) FlushPages(buildstate);
FlushPages(buildstate);
HnswLockRelease(hnswshared);
} }
HnswLockRelease(hnswshared);
oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx); oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);