Help needed regarding DSA based in-memory index!

From: Gaddam Sai Ram <gaddamsairam(dot)n(at)zohocorp(dot)com>
To: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Cc: "thomasmunro" <thomas(dot)munro(at)enterprisedb(dot)com>
Subject: Help needed regarding DSA based in-memory index!
Date: 2017-10-24 13:54:19
Message-ID: 15f4ea99b34.e69a4e1b633.8937474039794097334@zohocorp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Munro,

Thanks for cautioning us about possible memory leaks(during error cases) incase of long-lived DSA segements(have a look in below thread for more details).

https://www.postgresql.org/message-id/CAEepm%3D3c4WAtSQG4tAF7Y_VCnO5cKh7KuFYZhpKbwGQOF%3DdZ4A%40mail.gmail.com

Actually we are following an approach to avoid this DSA memory leaks. Let me explain our implementation and please validate and correct us in-case we miss anything.

Implementation:

Basically we have to put our index data into memory (Index Column Value Vs Ctid) which we get in aminsert callback function.

Coming to the implementation, in aminsert Callback function,

We Switch to CurTransactionContext

Cache the DMLs of a transaction into dlist(global per process)

Even if different clients work parallel, it won't be a problem because every client gets one dlist in separate process and it'll have it's own CurTransactionContext

We have registered transaction callback (using RegisterXactCallback() function). And during event pre-commit(XACT_EVENT_PRE_COMMIT), we populate all the transaction specific DMLs (from dlist) into our in-memory index(DSA) obviously inside PG_TRY/PG_CATCH block.

In case we got some errors(because of dsa_allocate() or something else) while processing dlist(while populating in-memory index), we cleanup the DSA memory in PG_CATCH block that is allocated/used till that point.

During other error cases, typically transactions gets aborted and PRE_COMMIT event is not called and hence we don't touch DSA at that time. Hence no need to bother about leaks.

Even sub transaction case is handled with sub transaction callbacks.

CurTransactionContext(dlist basically) is automatically cleared after that particular transaction.

I want to know if this approach is good and works well in all cases. Kindly provide your feedback on this.


Regards

G. Sai Ram

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2017-10-24 13:55:35 Re: Remove secondary checkpoint
Previous Message Tom Lane 2017-10-24 13:50:12 Re: Remove secondary checkpoint