[#1010223] Using Savepoints does not work with the ResultSet interface

View Trackers | Bugs | Download .csv | Monitor

Date:
2008-01-06 10:10
Priority:
3
State:
Open
Submitted by:
Lucas Madar (lucasmo)
Assigned to:
Nobody (None)
Category:
Group:
Summary:
Using Savepoints does not work with the ResultSet interface

Detailed description
If you have a complicated function that uses the ResultSet interface, PL/Java does not work correctly. Instead, an error is returned indicating that TopTransaction is not the owner of of a resource.

This is due to PL/Java not keeping track of memory context and resource owner information when using internal postgresql functions. I have a patch that seems to resolve this issue. However, I do not claim to be an expert; I figured this out by looking at the code and noticing that some of these functions can change the current context or resource owner.

Followup

Message
Date: 2008-02-01 07:00
Sender: Kris Jurka

I don't think your code is correct. Reading some code for other pls, I see this pattern:

MemoryContext oldcontext = CurrentMemoryContext;
ResourceOwner oldowner = CurrentResourceOwner;

BeginInternalSubTransaction(NULL);
/* Want to run inside function's memory context */
MemoryContextSwitchTo(oldcontext);

PG_TRY();
{
SPI_execute(...)

/* Commit the inner transaction, return to outer xact context */
ReleaseCurrentSubTransaction();
MemoryContextSwitchTo(oldcontext);
CurrentResourceOwner = oldowner;
}
PG_CATCH();
{
/* Abort the inner transaction */
RollbackAndReleaseCurrentSubTransaction();
MemoryContextSwitchTo(oldcontext);
CurrentResourceOwner = oldowner;
}

So the context/owner it is switching back to is that of before the sub transaction was started, not the context prior to subtransaction release.

In the pljava code, I think this means that we need to store the context and owner in the Savepoint object. Also PgSavepoint#_set switching to JavaMemoryContext is something to look at. I'm not sure if that's helping or hurting.

Attached Files:

Attachments:
pljava-savepointfix.patch

Changes:

Field Old Value Date By
File Added291: pljava-savepointfix.patch2008-01-06 10:10lucasmo
Powered By FusionForge