[libpostgresql-jdbc-java] 06/07: Adjust the deadlock avoidance code for the V3 protocol to be concerned with many statements in a single execute call in addition to the existing worry about many statements from an executeBatch call. This doesn't prevent all possible deadlocks as the deadlock avoidance calculation was written for batch execution which should not be returning ResultSets. If many long queries that return significant results are issued with a single execute we will still deadlock.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:42 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_323
in repository libpostgresql-jdbc-java.
commit bf3c79eab5bfda27cdcf4a38ca36f8e701b2a2e5
Author: Kris Jurka <books at ejurka.com>
Date: Sat Oct 18 13:41:05 2008 +0000
Adjust the deadlock avoidance code for the V3 protocol to be concerned
with many statements in a single execute call in addition to the
existing worry about many statements from an executeBatch call. This
doesn't prevent all possible deadlocks as the deadlock avoidance
calculation was written for batch execution which should not be
returning ResultSets. If many long queries that return significant
results are issued with a single execute we will still deadlock.
---
org/postgresql/core/v3/QueryExecutorImpl.java | 62 ++++++++++++++++++---------
1 file changed, 42 insertions(+), 20 deletions(-)
diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java
index 513baf5..ecf2f76 100644
--- a/org/postgresql/core/v3/QueryExecutorImpl.java
+++ b/org/postgresql/core/v3/QueryExecutorImpl.java
@@ -4,7 +4,7 @@
* Copyright (c) 2004, Open Cloud Limited.
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.6 2008/01/28 10:10:11 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.7 2008/05/20 00:04:49 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -181,7 +181,9 @@ public class QueryExecutorImpl implements QueryExecutor {
try
{
handler = sendQueryPreamble(handler, flags);
- sendQuery((V3Query)query, (V3ParameterList)parameters, maxRows, fetchSize, flags);
+ ErrorTrackingResultHandler trackingHandler = new ErrorTrackingResultHandler(handler);
+ queryCount = 0;
+ sendQuery((V3Query)query, (V3ParameterList)parameters, maxRows, fetchSize, flags, trackingHandler);
sendSync();
processResults(handler, flags);
}
@@ -312,31 +314,21 @@ public class QueryExecutorImpl implements QueryExecutor {
try
{
- int queryCount = 0;
-
handler = sendQueryPreamble(handler, flags);
ErrorTrackingResultHandler trackingHandler = new ErrorTrackingResultHandler(handler);
+ queryCount = 0;
for (int i = 0; i < queries.length; ++i)
{
- ++queryCount;
- if (queryCount >= MAX_BUFFERED_QUERIES)
- {
- sendSync();
- processResults(trackingHandler, flags);
-
- // If we saw errors, don't send anything more.
- if (trackingHandler.hasErrors())
- break;
-
- queryCount = 0;
- }
-
V3Query query = (V3Query)queries[i];
V3ParameterList parameters = (V3ParameterList)parameterLists[i];
if (parameters == null)
parameters = SimpleQuery.NO_PARAMETERS;
- sendQuery(query, parameters, maxRows, fetchSize, flags);
+
+ sendQuery(query, parameters, maxRows, fetchSize, flags, trackingHandler);
+
+ if (trackingHandler.hasErrors())
+ break;
}
if (!trackingHandler.hasErrors())
@@ -600,19 +592,43 @@ public class QueryExecutorImpl implements QueryExecutor {
/*
* Send a query to the backend.
*/
- private void sendQuery(V3Query query, V3ParameterList parameters, int maxRows, int fetchSize, int flags) throws IOException, SQLException {
+ private void sendQuery(V3Query query, V3ParameterList parameters, int maxRows, int fetchSize, int flags, ErrorTrackingResultHandler trackingHandler) throws IOException, SQLException {
// Now the query itself.
SimpleQuery[] subqueries = query.getSubqueries();
SimpleParameterList[] subparams = parameters.getSubparams();
if (subqueries == null)
{
- sendOneQuery((SimpleQuery)query, (SimpleParameterList)parameters, maxRows, fetchSize, flags);
+ ++queryCount;
+ if (queryCount >= MAX_BUFFERED_QUERIES)
+ {
+ sendSync();
+ processResults(trackingHandler, flags);
+
+ queryCount = 0;
+ }
+
+ // If we saw errors, don't send anything more.
+ if (!trackingHandler.hasErrors())
+ sendOneQuery((SimpleQuery)query, (SimpleParameterList)parameters, maxRows, fetchSize, flags);
}
else
{
for (int i = 0; i < subqueries.length; ++i)
{
+ ++queryCount;
+ if (queryCount >= MAX_BUFFERED_QUERIES)
+ {
+ sendSync();
+ processResults(trackingHandler, flags);
+
+ // If we saw errors, don't send anything more.
+ if (trackingHandler.hasErrors())
+ break;
+
+ queryCount = 0;
+ }
+
// In the situation where parameters is already
// NO_PARAMETERS it cannot know the correct
// number of array elements to return in the
@@ -1616,6 +1632,12 @@ public class QueryExecutorImpl implements QueryExecutor {
private final PGStream pgStream;
private final boolean allowEncodingChanges;
+ /**
+ * The number of queries executed so far without processing any results.
+ * Used to avoid deadlocks, see MAX_BUFFERED_QUERIES.
+ */
+ private int queryCount;
+
private final SimpleQuery beginTransactionQuery = new SimpleQuery(new String[] { "BEGIN" });
;
private final static SimpleQuery EMPTY_QUERY = new SimpleQuery(new String[] { "" });
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list