-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix:save points causing server to run out of resources #1409
Conversation
✅ Build pgjdbc 1.0.108 completed (commit 0f0cfc14f8 by @davecramer) |
&& getAutoSave() == AutoSave.ALWAYS | ||
&& getTransactionState() == TransactionState.OPEN) { | ||
try { | ||
sendOneQuery(releaseAutoSave, SimpleQuery.NO_PARAMETERS, 1, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davecramer , does that imply network roundtrip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it does. I guess this is why you wanted to do this every 1000 times instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see what I can do...
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private void releaseSavePoint(boolean autosave, int flags) throws SQLException { | ||
if (autosave | ||
&& (flags & QueryExecutor.QUERY_SUPPRESS_BEGIN) == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After changing the check for the QUERY_SUPPRESS_BEGIN to 0 the changes fix the issue. Otherwise the savepoint is never released
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly that doesn't pass the test suite...
@vlsi so looking at this it appears we send a savepoint before commit which could be removed. |
✅ Build pgjdbc 1.0.109 completed (commit 24e8317379 by @davecramer) |
Codecov Report
@@ Coverage Diff @@
## master #1409 +/- ##
============================================
+ Coverage 68.71% 68.76% +0.05%
- Complexity 3892 3913 +21
============================================
Files 179 179
Lines 16397 16436 +39
Branches 2668 2676 +8
============================================
+ Hits 11267 11303 +36
Misses 3881 3881
- Partials 1249 1252 +3 |
✅ Build pgjdbc 1.0.110 completed (commit 372829a69e by @davecramer) |
This implementation breaks the whole Savepoint feature for the driver. The PGSQL documentation states "RELEASE SAVEPOINT also destroys all savepoints that were established after the named savepoint was established". The following test demonstrates the issue: @Test
public void testPgsqlJdbcSavepoint() throws Exception {
Connection conn = TestUtil.openDB();
BaseConnection baseConnection = conn.unwrap(BaseConnection.class);
baseConnection.setAutosave(AutoSave.ALWAYS);
baseConnection.setAutoCommit(false);
TestUtil.createTable(conn, "rollbacktest", "a int, str text");
int iterations = 1000;
for (int i = 0; i < iterations; i++) {
long startTime = System.nanoTime();
Statement statement = conn.createStatement();
statement.executeUpdate("insert into rollbacktest(a, str) values (" + i + ", '" + UUID.randomUUID() + "')");
statement.close();
if (i == 5) {
Statement savePoint = conn.createStatement();
savePoint.executeUpdate("SAVEPOINT NEW_SAVEPOINT");
savePoint.close();
}
long timeElapsed = System.nanoTime() - startTime;
System.out.println(i + "/" + iterations + " took " + timeElapsed / 1000000 + "ms ");
}
Statement savePoint = conn.createStatement();
savePoint.executeUpdate("ROLLBACK TO NEW_SAVEPOINT");
savePoint.close();
} |
@fb-datax good catch |
@davecramer |
What if the approach was to do the "release" /before/ creating the 1000th savepoint? |
@bokken Unfortunately releasing all of them also releases SAVEPOINTS set by setSavePoint. |
@davecramer, could we limit to the "auto save" workflow (i.e. no manual calls to setSavePoint)? That really seems to be the problematic workflow. Where a user has auto save, and then proceeds to execute thousands of things in a single transaction. |
@bokken in theory, How do you propose we disable setSavePoint? Throw an exception ? |
❌ Build pgjdbc 1.0.111 failed (commit bc23e7cd0a by @davecramer) |
I am not suggesting we disable setSavePoint, I am suggesting that we stop automatically releasing savepoints once setSavePoint has been explicitly called. |
And perhaps the explicit call to setSavePoint releases any/all automatic savepoints first, giving a clean baseline. |
❌ Build pgjdbc 1.0.120 failed (commit cf826a70c0 by @davecramer) |
❌ Build pgjdbc 1.0.121 failed (commit 296f436b94 by @davecramer) |
❌ Build pgjdbc 1.0.122 failed (commit 3d0c3f23bb by @davecramer) |
✅ Build pgjdbc 1.0.123 completed (commit 3003bc1473 by @davecramer) |
I think this seems reasonable... I'll work on implementing this. |
✅ Build pgjdbc 1.0.124 completed (commit f56a2d4d85 by @davecramer) |
❌ Build pgjdbc 1.0.125 failed (commit 2e452067cc by @davecramer) |
✅ Build pgjdbc 1.0.126 completed (commit afcc9fc6ff by @davecramer) |
✅ Build pgjdbc 1.0.128 completed (commit 11f1b33637 by @davecramer) |
✅ Build pgjdbc 1.0.129 completed (commit 0f1f333f86 by @davecramer) |
✅ Build pgjdbc 1.0.137 completed (commit 8ca9c98001 by @davecramer) |
…p server resources (shared buffers)
…vePoints property.
aca6059
to
95478df
Compare
✅ Build pgjdbc 1.0.138 completed (commit 2338accbdf by @davecramer) |
@@ -111,6 +116,7 @@ public String getSql(ReturnColumns cols) { | |||
} | |||
|
|||
private final AutoSave autoSave; | |||
private final CleanSavePoint cleanSavePoint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davecramer , As far as I can tell, you create a field, but this field seems to be unused.
Fixes #1407
All Submissions:
New Feature Submissions:
Changes to Existing Features: