Lists: | pgsql-hackers |
---|
From: | Nikhil Sontakke <nikkhils(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | xml_is_document and selective pg_re_throw |
Date: | 2012-06-12 11:18:45 |
Message-ID: | CANgU5ZcgN0dDFPCbm6TY9SZTfgCMGjL3RKqnEZALHQOWV-mVaA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
Consider:
SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
And I was looking at xml_is_document() source code. It calls xml_parse
which throws an error with code set to ERRCODE_INVALID_XML_DOCUMENT. The
catch block of xml_parse then rethrows.
Now xml_is_document does a selective rethrow only if the error is not
ERRCODE_INVALID_XML_DOCUMENT. I can understand that this function does this
to return true/false, but doesn't this behavior of not propagating the
error up all the way dangerous? InterruptHoldoffCount inconsistencies for
instance?
A better way would have been to modify xml_parse to take an additional
boolean argument "to_rethrow" and not to rethrow if that is false?
Thoughts?
Regards,
Nikhils
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Nikhil Sontakke <nikkhils(at)gmail(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: xml_is_document and selective pg_re_throw |
Date: | 2012-06-12 16:27:57 |
Message-ID: | 18314.1339518477@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Nikhil Sontakke <nikkhils(at)gmail(dot)com> writes:
> Consider:
> SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
> And I was looking at xml_is_document() source code. It calls xml_parse
> which throws an error with code set to ERRCODE_INVALID_XML_DOCUMENT. The
> catch block of xml_parse then rethrows.
> Now xml_is_document does a selective rethrow only if the error is not
> ERRCODE_INVALID_XML_DOCUMENT. I can understand that this function does this
> to return true/false, but doesn't this behavior of not propagating the
> error up all the way dangerous? InterruptHoldoffCount inconsistencies for
> instance?
No, I don't see any particular risk there. The places that might throw
ERRCODE_INVALID_XML_DOCUMENT are sufficiently few (as in, exactly one,
in this usage) that we can have reasonable confidence we know what the
system state is when we catch that error.
> A better way would have been to modify xml_parse to take an additional
> boolean argument "to_rethrow" and not to rethrow if that is false?
We could do that, but it would greatly complicate xml_parse IMO, since
it still needs its own PG_TRY block to handle other error cases, and
only one of those error cases ought to optionally return failure instead
of re-throwing.
regards, tom lane
From: | Nikhil Sontakke <nikkhils(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: xml_is_document and selective pg_re_throw |
Date: | 2012-06-13 06:57:02 |
Message-ID: | CANgU5ZcsxWpEixWiMZc6nNN7QEJ01e1qv9G8qNSJKQzwgMZ5VA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> No, I don't see any particular risk there. The places that might throw
> ERRCODE_INVALID_XML_DOCUMENT are sufficiently few (as in, exactly one,
> in this usage) that we can have reasonable confidence we know what the
> system state is when we catch that error.
>
>
Hmmm, I was writing some code in which I happened to hold a LWLock when
this function was called. The first catch/rethrow cleaned up the
InterruptHoldoffCount value. A subsequent release of that LWLock tripped up
the (Assert(InterruptHoldoffCount > 0);) inside RESUME_INTERRUPTS().
I know holding an lwlock like this might not be a good idea, but this
behavior just got me thinking about other probable issues.
Regards,
Nikhils
> > A better way would have been to modify xml_parse to take an additional
> > boolean argument "to_rethrow" and not to rethrow if that is false?
>
> We could do that, but it would greatly complicate xml_parse IMO, since
> it still needs its own PG_TRY block to handle other error cases, and
> only one of those error cases ought to optionally return failure instead
> of re-throwing.
>
> regards, tom lane
>