Skip to content

Commit 28637ce

Browse files
committed
Don't capture hard errors for old cagg format
If an error occurs inside the deserialization function for continuous aggregates, we are using the old numeric format and this was captured inside `inner_agg_deserialize` and the format was "repaired". However, this captured hard errors as well, which can cause cascading errors if execution continues after the error. This commit fixes that by capturing data exception errors, internal error (which is the default for elog()) and protocol error (c.f. `pq_getmsgint64` used by `numeric_deserialize`), but re-throwing all other errors.
1 parent 4653c72 commit 28637ce

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tsl/src/partialize_finalize.c

+20
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,27 @@ inner_agg_deserialize(FACombineFnMeta *combine_meta, bytea *volatile serialized_
276276
}
277277
PG_CATCH();
278278
{
279+
const int sqlerrcode = geterrcode();
279280
CurrentMemoryContext = oldcontext;
281+
282+
/*
283+
* If we get a data exception category error or a protocol
284+
* violation or an internal error (which is generated by default
285+
* when using elog()), the format is wrong and we can attempt to
286+
* repair it by switching to a different function for
287+
* deserializing.
288+
*
289+
* If the error is an insufficient resources category we should
290+
* *not* continue executing.
291+
*
292+
* Errors in other categories are not expected, but we cannot do
293+
* anything with them anyway, so just re-throw them too.
294+
*/
295+
if (ERRCODE_TO_CATEGORY(sqlerrcode) != ERRCODE_DATA_EXCEPTION &&
296+
sqlerrcode != ERRCODE_PROTOCOL_VIOLATION && sqlerrcode != ERRCODE_INTERNAL_ERROR)
297+
{
298+
PG_RE_THROW();
299+
}
280300
FlushErrorState();
281301
/* attempt to repair the serialized partial */
282302
serialized_partial =

0 commit comments

Comments
 (0)