Hi all, When working on a decoder plugin, I have been pointed that it is incorrect to write changes in an output plugin while not being in the memory context where changes are written. In pg_decode_change@test_decoding.c, we do the following: old = MemoryContextSwitchTo(data->context); OutputPluginPrepareWrite(ctx, true); [...] MemoryContextSwitchTo(old); MemoryContextReset(data->context); OutputPluginWrite(ctx, true);
Wouldn't it be better to call OutputPluginWrite before switching back to the old context? The attached patch for test_decoding does so. Comments welcome. Regards, -- Michael
From 9bd2e09433573fbfd85105fca2c6862dba383eab Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@otacoo.com> Date: Thu, 15 May 2014 09:01:28 +0900 Subject: [PATCH] Write changes of test_decoding while being in the data context OutputPluginWrite was being called after switching to the old memory context. This seems incorrect as the changes are written in a specific memory context. --- contrib/test_decoding/test_decoding.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c index 5ce052b..903b15b 100644 --- a/contrib/test_decoding/test_decoding.c +++ b/contrib/test_decoding/test_decoding.c @@ -400,8 +400,10 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, Assert(false); } + /* Write changes while in the context of the data */ + OutputPluginWrite(ctx, true); + + /* Switch back to old context */ MemoryContextSwitchTo(old); MemoryContextReset(data->context); - - OutputPluginWrite(ctx, true); } -- 1.9.3
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers