-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9219] docdb - Ignore intents from aborted subtransactions during re…
…ads and writes of the same transaction Summary: This revision add support for client-side tracking of aborted subtransactions, transmission of this metadata to docdb, and consideration of this metadata when processing intents for reads and writes. This revision *does not* ensure that aborted intents are not applied after transaction commit, so "ROLLBACK TO SAVEPOINT" cannot yet be safely used and remains guarded by default. This revision also implements some basic java test coverage of some of the savepoint functionality implemented so far, but is by no means exhaustive. These tests were meant to merely demonstrate basic functionality that has been implemented in previous revisions newly in this one. Test Plan: ybd --java-test 'org.yb.pgsql.TestPgSavepoints' ybd --cxx-test util_uint_set-test Reviewers: mbautin, sergei Reviewed By: sergei Subscribers: ybase, bogdan Differential Revision: https://phabricator.dev.yugabyte.com/D12331
- Loading branch information
1 parent
d989326
commit c8eb974
Showing
21 changed files
with
608 additions
and
54 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgSavepoints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (c) YugaByte, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
|
||
package org.yb.pgsql; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yb.util.YBTestRunnerNonTsanOnly; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.OptionalInt; | ||
|
||
import static org.yb.AssertionWrappers.*; | ||
|
||
@RunWith(value=YBTestRunnerNonTsanOnly.class) | ||
public class TestPgSavepoints extends BasePgSQLTest { | ||
private static final Logger LOG = LoggerFactory.getLogger(TestPgSavepoints.class); | ||
|
||
private void createTable() throws SQLException { | ||
try (Statement statement = connection.createStatement()) { | ||
statement.execute("CREATE TABLE t (k INT, v INT)"); | ||
} | ||
} | ||
|
||
private OptionalInt getSingleValue(Connection c, int k) throws SQLException { | ||
String query = String.format("SELECT * FROM t WHERE k = %d", k); | ||
try (ResultSet rs = c.createStatement().executeQuery(query)) { | ||
if (!rs.next()) { | ||
return OptionalInt.empty(); | ||
} | ||
Row row = Row.fromResultSet(rs); | ||
LOG.info(row.toString()); | ||
assertFalse("Found more than one result", rs.next()); | ||
return OptionalInt.of(row.getInt(1)); | ||
} | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getTServerFlags() { | ||
// TODO(savepoints) -- enable by default. | ||
Map<String, String> flags = super.getTServerFlags(); | ||
flags.put("enable_pg_savepoints", "true"); | ||
return flags; | ||
} | ||
|
||
@Test | ||
public void testSavepointCreation() throws Exception { | ||
createTable(); | ||
|
||
try (Connection conn = getConnectionBuilder() | ||
.withAutoCommit(AutoCommit.DISABLED) | ||
.connect()) { | ||
Statement statement = conn.createStatement(); | ||
statement.execute("INSERT INTO t VALUES (1, 2)"); | ||
statement.execute("SAVEPOINT a"); | ||
statement.execute("INSERT INTO t VALUES (3, 4)"); | ||
statement.execute("SAVEPOINT b"); | ||
|
||
assertEquals(getSingleValue(conn, 1), OptionalInt.of(2)); | ||
assertEquals(getSingleValue(conn, 3), OptionalInt.of(4)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSavepointRollback() throws Exception { | ||
createTable(); | ||
|
||
try (Connection conn = getConnectionBuilder() | ||
.withAutoCommit(AutoCommit.DISABLED) | ||
.connect()) { | ||
Statement statement = conn.createStatement(); | ||
statement.execute("INSERT INTO t VALUES (1, 2)"); | ||
statement.execute("SAVEPOINT a"); | ||
statement.execute("INSERT INTO t VALUES (3, 4)"); | ||
statement.execute("ROLLBACK TO a"); | ||
|
||
assertEquals(getSingleValue(conn, 1), OptionalInt.of(2)); | ||
assertEquals(getSingleValue(conn, 3), OptionalInt.empty()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSavepointUpdateAbortedRow() throws Exception { | ||
createTable(); | ||
|
||
try (Connection conn = getConnectionBuilder() | ||
.withAutoCommit(AutoCommit.DISABLED) | ||
.connect()) { | ||
Statement statement = conn.createStatement(); | ||
statement.execute("INSERT INTO t VALUES (1, 2)"); | ||
statement.execute("SAVEPOINT a"); | ||
statement.execute("INSERT INTO t VALUES (3, 4)"); | ||
statement.execute("ROLLBACK TO a"); | ||
statement.execute("UPDATE t SET v = 5 WHERE k = 3"); | ||
assertEquals(statement.getUpdateCount(), 0); | ||
|
||
assertEquals(getSingleValue(conn, 1), OptionalInt.of(2)); | ||
assertEquals(getSingleValue(conn, 3), OptionalInt.empty()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAbortsIntentOfReleasedSavepoint() throws Exception { | ||
createTable(); | ||
|
||
try (Connection conn = getConnectionBuilder() | ||
.withAutoCommit(AutoCommit.DISABLED) | ||
.connect()) { | ||
Statement statement = conn.createStatement(); | ||
statement.execute("SAVEPOINT a"); | ||
statement.execute("SAVEPOINT b"); | ||
statement.execute("INSERT INTO t VALUES (3, 4)"); | ||
statement.execute("RELEASE SAVEPOINT b"); | ||
statement.execute("ROLLBACK TO a"); | ||
|
||
assertEquals(getSingleValue(conn, 3), OptionalInt.empty()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.