#include "storage/indexfsm.h"
#include "utils/memutils.h"
-const XLogRecPtr XLogRecPtrForTemp = {1, 1};
-
/* Working state for gistbuild and its callback */
typedef struct
{
PageSetTLI(page, ThisTimeLineID);
}
else
- PageSetLSN(page, XLogRecPtrForTemp);
+ PageSetLSN(page, GetXLogRecPtrForTemp());
UnlockReleaseBuffer(buffer);
{
for (ptr = dist; ptr; ptr = ptr->next)
{
- PageSetLSN(ptr->page, XLogRecPtrForTemp);
+ PageSetLSN(ptr->page, GetXLogRecPtrForTemp());
}
}
PageSetTLI(state->stack->page, ThisTimeLineID);
}
else
- PageSetLSN(state->stack->page, XLogRecPtrForTemp);
+ PageSetLSN(state->stack->page, GetXLogRecPtrForTemp());
if (state->stack->blkno == GIST_ROOT_BLKNO)
state->needInsertComplete = false;
PageSetTLI(page, ThisTimeLineID);
}
else
- PageSetLSN(page, XLogRecPtrForTemp);
+ PageSetLSN(page, GetXLogRecPtrForTemp());
END_CRIT_SECTION();
}
PG_RETURN_BYTEA_P(result);
PG_RETURN_NULL();
}
+
+/*
+ * Temporary GiST indexes are not WAL-logged, but we need LSNs to detect
+ * concurrent page splits anyway. GetXLogRecPtrForTemp() provides a fake
+ * sequence of LSNs for that purpose. Each call generates an LSN that is
+ * greater than any previous value returned by this function in the same
+ * session.
+ */
+XLogRecPtr
+GetXLogRecPtrForTemp(void)
+{
+ static XLogRecPtr counter = {0, 1};
+
+ counter.xrecoff++;
+ if (counter.xrecoff == 0)
+ {
+ counter.xlogid++;
+ counter.xrecoff++;
+ }
+ return counter;
+}
typedef GISTScanOpaqueData *GISTScanOpaque;
/* XLog stuff */
-extern const XLogRecPtr XLogRecPtrForTemp;
#define XLOG_GIST_PAGE_UPDATE 0x00
#define XLOG_GIST_NEW_ROOT 0x20
GISTENTRY *entry2, bool isnull2,
Datum *dst, bool *dstisnull);
+extern XLogRecPtr GetXLogRecPtrForTemp(void);
+
/* gistvacuum.c */
extern Datum gistbulkdelete(PG_FUNCTION_ARGS);
extern Datum gistvacuumcleanup(PG_FUNCTION_ARGS);