static void SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn);
static bool SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn);
+/*
+ * Memory context reset callback for clearing the array of running transactions
+ * and subtransactions.
+ */
+static void
+SnapBuildResetRunningXactsCallback(void *arg)
+{
+ NInitialRunningXacts = 0;
+ InitialRunningXacts = NULL;
+}
+
/*
* Allocate a new snapshot builder.
*
MemoryContext context;
MemoryContext oldcontext;
SnapBuild *builder;
+ MemoryContextCallback *mcallback;
/* allocate memory in own context, to have better accountability */
context = AllocSetContextCreate(CurrentMemoryContext,
builder->building_full_snapshot = need_full_snapshot;
builder->initial_consistent_point = initial_consistent_point;
+ mcallback = palloc0(sizeof(MemoryContextCallback));
+ mcallback->func = SnapBuildResetRunningXactsCallback;
+ MemoryContextRegisterResetCallback(CurrentMemoryContext, mcallback);
+
MemoryContextSwitchTo(oldcontext);
/* The initial running transactions array must be empty. */
/* other resources are deallocated via memory context reset */
MemoryContextDelete(context);
-
- /* InitialRunningXacts is freed along with the context */
- NInitialRunningXacts = 0;
- InitialRunningXacts = NULL;
}
/*