apply worker misses closing partition leaves

Поиск
Список
Период
Сортировка
Искать

apply worker misses closing partition leaves

От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Вложения:
Dear hackers,
(CC: David, who is a committer for 39dcfda)

While working on the parallel apply, I found that 013_partition.pl raises WARNINGs
like [1]. Per my research it happened after the 39dcfda. The warning indicates the
partition leaf opened by the worker is not expressly closed.

IIUC, it can happen if partition leaves have after triggers. The apply worker
has to obtain ResultRelInfo for the relation in
finish_edata()->AfterTriggerEndQuery()->ExecGetTriggerResultRel(), and it firstly
checks the cached result in EState::es_opened_result_relations.
The commit 39dcfda made the condition for re-use the cache stricter (requires
matching rootRelInfo as well) and the apply worker could not match the condition.
In this case the relation would be opened but nobody close: the resource
owner finally handles it.

IIUC, the difference between normal and partition leaves is how they are cached
in es_tuple_routing_result_relations. Normal relations are stored with
ResultRelInfo::ri_RootResultRelInfo = NULL, and partition ones have valid value.
afterTriggerInvokeEvents() always passes rootRelInfo = NULL, so only leaves
miss the cache.

I'm not familiar with codes around triggers. But if we try to fix on logical
replication side, relations opened for triggers can be closed in finish_edata().
See attached.

[1]:
```
2026-08-17 18:12:41.780 JST logical replication apply worker[150182] WARNING:  resource was not closed: relation "tab1_2_2"
2026-08-17 18:12:41.780 JST logical replication apply worker[150182] CONTEXT:  processing remote data for replication origin "pg_16438" during message type "COMMIT" in transaction 707, finished at 0/017E3E50
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Re: apply worker misses closing partition leaves

От:
David Rowley <dgrowleyml@gmail.com>
Дата:
Вложения:
On Mon, 24 Aug 2026 at 22:33, Zhijie Hou (Fujitsu)
 wrote:
> The fix looks good to me. I just noticed one nit in the test:
>
> +       ok(!$node->log_contains(qr/resource was not closed/),
> +               'unclosed resources on ' . $node->name);
>
> I think the test message should be: "no unclosed resources on".

Sorry, I must be missing something here. You want the message that
complains when there *is* a resource leak WARNING say "no unclosed
resources on $server"?

Maybe if that message is confusing, then it might be better to write
"resource leak detected on $server".  Is that any better?

David


FAQ