Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd

Поиск
Список
Период
Сортировка
От Andy Fan
Тема Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd
Дата
Msg-id CAKU4AWpoTmGpR0o-qfrAxBndGnfCoNVPQYa2vBC_-u=UAhhYWA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
Hi,

During my recent work,  I need some new stuff attached to Relation.  Rather than adding
some new data structures,  I added it to Relation directly.  Like relation->balabala.  Then
I initialize it during ExecutorRun,  like  table_tuple_insert.. and destroy it at ExecutorEnd.

The above solution works based on 2 assumptions at least: 
1.  During the ExecutorRun & ExecutorEnd,  the relcache will never by invalidated, if not
the old relation->balabala will be lost.  I assume this is correct since I didn't see any places
where we handle such changes in Executor code. 
2.  We need to consider the ExuecotRun raised error,  we need to destroy the balabala resource
as well.  so I added it to the RelationClose function.  

So the overall design works like this:

xxx_table_tuple_insert(Relation rel, ...)
{
   if (rel->balabala == NULL)
        rel->balabala = allocate_bala_resource(rel);  // Allocate the memory xCtx which is under TopTransactionContext.
   do_task_with(rel->balabala); 
}

at the end of the executor,  I run

release_bala_resource(Relation rel)
{
   if (rel->balabala == NULL)
         return;
   do_the_real_task();
   MemoryContextDelete(rel->bala->memctx); 
   rel->balabala = NULL
}

For the failed cases:

RelationClose(..)
{
   if (RelationHasReferenceCountZero(relation))
         release_bala_resource(relation); 
}

Will my suluation work?

--
Best Regards
Andy Fan

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bharath Rupireddy
Дата:
Сообщение: Re: Synchronizing slots from primary to standby
Следующее
От: Antonin Houska
Дата:
Сообщение: Re: XTS cipher mode for cluster file encryption