use of org.apache.phoenix.execute.CommitException in project phoenix by apache.
the class MutableIndexFailureIT method updateTableAgain.
private void updateTableAgain(Connection conn, boolean commitShouldFail) throws SQLException {
// Verify UPSERT on data table still work after index is disabled
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
stmt.setString(1, "a3");
stmt.setString(2, "x3");
stmt.setString(3, "3");
stmt.execute();
try {
conn.commit();
if (commitShouldFail && !localIndex && this.throwIndexWriteFailure) {
fail();
}
} catch (CommitException e) {
if (!commitShouldFail || !this.throwIndexWriteFailure) {
throw e;
}
exceptions.add(e);
}
}
use of org.apache.phoenix.execute.CommitException in project phoenix by apache.
the class IndexUsageIT method testExpressionThrowsException.
@Test
public void testExpressionThrowsException() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String dataTableName = generateUniqueName();
String indexName = generateUniqueName();
try {
String ddl = "CREATE TABLE " + dataTableName + " (k1 INTEGER PRIMARY KEY, k2 INTEGER)";
conn.createStatement().execute(ddl);
ddl = "CREATE INDEX " + indexName + " on " + dataTableName + "(k1/k2)";
conn.createStatement().execute(ddl);
// upsert should succeed
conn.createStatement().execute("UPSERT INTO " + dataTableName + " VALUES(1,1)");
conn.commit();
// divide by zero should fail
conn.createStatement().execute("UPSERT INTO " + dataTableName + " VALUES(1,0)");
conn.commit();
fail();
} catch (CommitException e) {
} finally {
conn.close();
}
}
use of org.apache.phoenix.execute.CommitException in project phoenix by apache.
the class MutableIndexFailureIT method replayMutations.
private void replayMutations() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
for (int i = 0; i < exceptions.size(); i++) {
CommitException e = exceptions.get(i);
long ts = e.getServerTimestamp();
props.setProperty(PhoenixRuntime.REPLAY_AT_ATTRIB, Long.toString(ts));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
if (i == 0) {
updateTable(conn, false);
} else if (i == 1) {
updateTableAgain(conn, false);
} else {
fail();
}
}
}
}
use of org.apache.phoenix.execute.CommitException in project phoenix by apache.
the class IndexExpressionIT method testExpressionThrowsException.
@Test
public void testExpressionThrowsException() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String dataTableName = generateUniqueName();
String indexName = generateUniqueName();
try {
String ddl = "CREATE TABLE " + dataTableName + " (k1 INTEGER PRIMARY KEY, k2 INTEGER)";
conn.createStatement().execute(ddl);
ddl = "CREATE INDEX " + indexName + " on " + dataTableName + "(k1/k2)";
conn.createStatement().execute(ddl);
// upsert should succeed
conn.createStatement().execute("UPSERT INTO " + dataTableName + " VALUES(1,1)");
conn.commit();
// divide by zero should fail
conn.createStatement().execute("UPSERT INTO " + dataTableName + " VALUES(1,0)");
conn.commit();
fail();
} catch (CommitException e) {
} finally {
conn.close();
}
}
use of org.apache.phoenix.execute.CommitException in project phoenix by apache.
the class MutableIndexFailureIT method updateTable.
private void updateTable(Connection conn, boolean commitShouldFail) throws SQLException {
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + fullTableName + " VALUES(?,?,?)");
// Insert new row
stmt.setString(1, "d");
stmt.setString(2, "d");
stmt.setString(3, "4");
stmt.execute();
// Update existing row
stmt.setString(1, "a");
stmt.setString(2, "x2");
stmt.setString(3, "2");
stmt.execute();
// Delete existing row
stmt = conn.prepareStatement("DELETE FROM " + fullTableName + " WHERE k=?");
stmt.setString(1, "b");
stmt.execute();
// Set to fail after the DELETE, since transactional tables will write
// uncommitted data when the DELETE is executed.
FailingRegionObserver.FAIL_WRITE = true;
try {
FailingRegionObserver.FAIL_NEXT_WRITE = localIndex && transactional;
conn.commit();
if (commitShouldFail && (!localIndex || transactional) && this.throwIndexWriteFailure) {
fail();
}
} catch (CommitException e) {
if (!commitShouldFail || !this.throwIndexWriteFailure) {
throw e;
}
exceptions.add(e);
}
}
Aggregations