Revert "Added version to reduce stale reads and writes and prepare for optimistic locking"

This reverts commit ef1209eaf4.
This commit is contained in:
Andrew Kane
2023-08-21 02:47:27 -07:00
parent 1301706d30
commit 02f4e0ec8b
4 changed files with 6 additions and 16 deletions

View File

@@ -85,7 +85,6 @@ typedef struct HnswNeighborArray HnswNeighborArray;
typedef struct HnswElementData typedef struct HnswElementData
{ {
List *heaptids; List *heaptids;
uint8 version;
uint8 level; uint8 level;
uint8 deleted; uint8 deleted;
HnswNeighborArray *neighbors; HnswNeighborArray *neighbors;
@@ -186,9 +185,9 @@ typedef HnswPageOpaqueData * HnswPageOpaque;
typedef struct HnswElementTupleData typedef struct HnswElementTupleData
{ {
uint8 type; uint8 type;
uint8 version;
uint8 level; uint8 level;
uint8 deleted; uint8 deleted;
uint8 unused;
ItemPointerData heaptids[HNSW_HEAPTIDS]; ItemPointerData heaptids[HNSW_HEAPTIDS];
ItemPointerData neighbortid; ItemPointerData neighbortid;
uint16 unused2; uint16 unused2;
@@ -200,7 +199,7 @@ typedef HnswElementTupleData * HnswElementTuple;
typedef struct HnswNeighborTupleData typedef struct HnswNeighborTupleData
{ {
uint8 type; uint8 type;
uint8 version; uint8 unused;
uint16 count; uint16 count;
ItemPointerData indextids[FLEXIBLE_ARRAY_MEMBER]; ItemPointerData indextids[FLEXIBLE_ARRAY_MEMBER];
} HnswNeighborTupleData; } HnswNeighborTupleData;

View File

@@ -359,11 +359,8 @@ HnswUpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswE
/* Calculate index for update */ /* Calculate index for update */
startIdx = (hc->element->level - lc) * m; startIdx = (hc->element->level - lc) * m;
/* TODO Skip when deleting */ /* Check for existing connection */
/* TODO Resolve issue with connections from element neighbor tuple */ if (checkExisting && ConnectionExists(e, ntup, startIdx, lm))
if (ntup->version != hc->element->version)
idx = -1;
else if (checkExisting && ConnectionExists(e, ntup, startIdx, lm))
idx = -1; idx = -1;
else if (idx == -2) else if (idx == -2)
{ {
@@ -477,7 +474,7 @@ HnswAddDuplicate(Relation index, HnswElement element, HnswElement dup)
} }
/* Either being deleted or we lost our chance to another backend */ /* Either being deleted or we lost our chance to another backend */
if (i == 0 || i == HNSW_HEAPTIDS || etup->version != dup->version) if (i == 0 || i == HNSW_HEAPTIDS)
{ {
GenericXLogAbort(state); GenericXLogAbort(state);
UnlockReleaseBuffer(buf); UnlockReleaseBuffer(buf);

View File

@@ -160,7 +160,6 @@ HnswInitElement(ItemPointer heaptid, int m, double ml, int maxLevel)
element->heaptids = NIL; element->heaptids = NIL;
HnswAddHeapTid(element, heaptid); HnswAddHeapTid(element, heaptid);
element->version = 1;
element->level = level; element->level = level;
element->deleted = 0; element->deleted = 0;
@@ -289,7 +288,6 @@ void
HnswSetElementTuple(HnswElementTuple etup, HnswElement element) HnswSetElementTuple(HnswElementTuple etup, HnswElement element)
{ {
etup->type = HNSW_ELEMENT_TUPLE_TYPE; etup->type = HNSW_ELEMENT_TUPLE_TYPE;
etup->version = element->version;
etup->level = element->level; etup->level = element->level;
etup->deleted = 0; etup->deleted = 0;
for (int i = 0; i < HNSW_HEAPTIDS; i++) for (int i = 0; i < HNSW_HEAPTIDS; i++)
@@ -311,7 +309,6 @@ HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m)
int idx = 0; int idx = 0;
ntup->type = HNSW_NEIGHBOR_TUPLE_TYPE; ntup->type = HNSW_NEIGHBOR_TUPLE_TYPE;
ntup->version = e->version;
for (int lc = e->level; lc >= 0; lc--) for (int lc = e->level; lc >= 0; lc--)
{ {
@@ -351,7 +348,7 @@ LoadNeighborsFromPage(HnswElement element, Relation index, Page page)
HnswInitNeighbors(element, m); HnswInitNeighbors(element, m);
/* Ensure expected neighbors */ /* Ensure expected neighbors */
if (ntup->version != element->version || ntup->count != neighborCount) if (ntup->count != neighborCount)
return; return;
for (int i = 0; i < neighborCount; i++) for (int i = 0; i < neighborCount; i++)
@@ -404,7 +401,6 @@ HnswLoadNeighbors(HnswElement element, Relation index)
void void
HnswLoadElementFromTuple(HnswElement element, HnswElementTuple etup, bool loadHeaptids, bool loadVec) HnswLoadElementFromTuple(HnswElement element, HnswElementTuple etup, bool loadHeaptids, bool loadVec)
{ {
element->version = etup->version;
element->level = etup->level; element->level = etup->level;
element->deleted = etup->deleted; element->deleted = etup->deleted;
element->neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid); element->neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);

View File

@@ -485,12 +485,10 @@ MarkDeleted(HnswVacuumState * vacuumstate)
ntup = (HnswNeighborTuple) PageGetItem(npage, PageGetItemId(npage, neighborOffno)); ntup = (HnswNeighborTuple) PageGetItem(npage, PageGetItemId(npage, neighborOffno));
/* Overwrite element */ /* Overwrite element */
etup->version++;
etup->deleted = 1; etup->deleted = 1;
MemSet(&etup->vec.x, 0, etup->vec.dim * sizeof(float)); MemSet(&etup->vec.x, 0, etup->vec.dim * sizeof(float));
/* Overwrite neighbors */ /* Overwrite neighbors */
ntup->version = etup->version;
for (int i = 0; i < ntup->count; i++) for (int i = 0; i < ntup->count; i++)
ItemPointerSetInvalid(&ntup->indextids[i]); ItemPointerSetInvalid(&ntup->indextids[i]);