Search in sources :

Example 1 with CommitException

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);
    }
}
Also used : CommitException(org.apache.phoenix.execute.CommitException) PreparedStatement(java.sql.PreparedStatement)

Example 2 with CommitException

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();
    }
}
Also used : CommitException(org.apache.phoenix.execute.CommitException) Connection(java.sql.Connection) Test(org.junit.Test)

Example 3 with CommitException

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();
            }
        }
    }
}
Also used : CommitException(org.apache.phoenix.execute.CommitException) Connection(java.sql.Connection) Properties(java.util.Properties)

Example 4 with CommitException

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();
    }
}
Also used : CommitException(org.apache.phoenix.execute.CommitException) Connection(java.sql.Connection) Test(org.junit.Test)

Example 5 with CommitException

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);
    }
}
Also used : CommitException(org.apache.phoenix.execute.CommitException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

CommitException (org.apache.phoenix.execute.CommitException)6 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)2 Test (org.junit.Test)2 ResultSet (java.sql.ResultSet)1 Properties (java.util.Properties)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 PhoenixStatement (org.apache.phoenix.jdbc.PhoenixStatement)1 PMetaData (org.apache.phoenix.schema.PMetaData)1 PTableKey (org.apache.phoenix.schema.PTableKey)1