From 3e628986a13cac1b074aa0adae9ee6a8d0d76f8d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 19 Dec 2023 17:23:35 -0500 Subject: [PATCH] Removed metapage logging [skip ci] --- src/hnsw.h | 2 +- src/hnswbuild.c | 2 +- src/hnswinsert.c | 4 ++-- src/hnswutils.c | 18 ++++++++++++++---- src/hnswvacuum.c | 6 +++--- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/hnsw.h b/src/hnsw.h index efbc2cb..65df93d 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -332,7 +332,7 @@ HnswElement HnswInitElementFromBlock(BlockNumber blkno, OffsetNumber offno); void HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, bool existing); HnswElement HnswFindDuplicate(HnswElement e); HnswCandidate *HnswEntryCandidate(HnswElement em, Datum q, Relation rel, FmgrInfo *procinfo, Oid collation, bool loadVec); -void HnswUpdateMetaPage(Relation index, int updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum); +void HnswUpdateMetaPage(Relation index, int updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum, bool building); void HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m); void HnswAddHeapTid(HnswElement element, ItemPointer heaptid); void HnswInitNeighbors(HnswElement element, int m); diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 2586ccc..2058168 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -207,7 +207,7 @@ CreateElementPages(HnswBuildState * buildstate) /* Commit */ UnlockReleaseBuffer(buf); - HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_ALWAYS, buildstate->entryPoint, insertPage, forkNum); + HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_ALWAYS, buildstate->entryPoint, insertPage, forkNum, true); pfree(etup); pfree(ntup); diff --git a/src/hnswinsert.c b/src/hnswinsert.c index fbc1414..bcb3b5c 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -514,14 +514,14 @@ WriteElement(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement elem /* Update insert page if needed */ if (BlockNumberIsValid(newInsertPage)) - HnswUpdateMetaPage(index, 0, NULL, newInsertPage, MAIN_FORKNUM); + HnswUpdateMetaPage(index, 0, NULL, newInsertPage, MAIN_FORKNUM, building); /* Update neighbors */ HnswUpdateNeighborPages(index, procinfo, collation, element, m, false, building); /* Update metapage if needed */ if (entryPoint == NULL || element->level > entryPoint->level) - HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_GREATER, element, InvalidBlockNumber, MAIN_FORKNUM); + HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_GREATER, element, InvalidBlockNumber, MAIN_FORKNUM, building); } /* diff --git a/src/hnswutils.c b/src/hnswutils.c index a79f626..0421e11 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -379,7 +379,7 @@ HnswUpdateMetaPageInfo(Page page, int updateEntry, HnswElement entryPoint, Block * Update the metapage */ void -HnswUpdateMetaPage(Relation index, int updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum) +HnswUpdateMetaPage(Relation index, int updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum, bool building) { Buffer buf; Page page; @@ -387,12 +387,22 @@ HnswUpdateMetaPage(Relation index, int updateEntry, HnswElement entryPoint, Bloc buf = ReadBufferExtended(index, forkNum, HNSW_METAPAGE_BLKNO, RBM_NORMAL, NULL); LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); - state = GenericXLogStart(index); - page = GenericXLogRegisterBuffer(state, buf, 0); + if (building) + { + state = NULL; + page = BufferGetPage(buf); + } + else + { + state = GenericXLogStart(index); + page = GenericXLogRegisterBuffer(state, buf, 0); + } HnswUpdateMetaPageInfo(page, updateEntry, entryPoint, insertPage); - HnswCommitBuffer(buf, state); + if (!building) + GenericXLogFinish(state); + UnlockReleaseBuffer(buf); } /* diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c index 1c01704..f11c362 100644 --- a/src/hnswvacuum.c +++ b/src/hnswvacuum.c @@ -286,7 +286,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate) * point is outdated and empty, the entry point will be empty * until an element is repaired. */ - HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_ALWAYS, highestPoint, InvalidBlockNumber, MAIN_FORKNUM); + HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_ALWAYS, highestPoint, InvalidBlockNumber, MAIN_FORKNUM, false); } else { @@ -419,7 +419,7 @@ RepairGraph(HnswVacuumState * vacuumstate) * was replaced and highest point was outdated. */ if (entryPoint == NULL || element->level > entryPoint->level) - HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_GREATER, element, InvalidBlockNumber, MAIN_FORKNUM); + HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_GREATER, element, InvalidBlockNumber, MAIN_FORKNUM, false); /* Release lock */ UnlockPage(index, HNSW_UPDATE_LOCK, lockmode); @@ -564,7 +564,7 @@ MarkDeleted(HnswVacuumState * vacuumstate) } /* Update insert page last, after everything has been marked as deleted */ - HnswUpdateMetaPage(index, 0, NULL, insertPage, MAIN_FORKNUM); + HnswUpdateMetaPage(index, 0, NULL, insertPage, MAIN_FORKNUM, false); } /*