Search in sources :

Example 1 with FenceWait

use of org.apache.tephra.visibility.FenceWait in project phoenix by apache.

the class MutationState method commitDDLFence.

/**
     * Commit a write fence when creating an index so that we can detect
     * when a data table transaction is started before the create index
     * but completes after it. In this case, we need to rerun the data
     * table transaction after the index creation so that the index rows
     * are generated. See {@link #addDMLFence(PTable)} and TEPHRA-157
     * for more information.
     * @param dataTable the data table upon which an index is being added
     * @throws SQLException
     */
public void commitDDLFence(PTable dataTable) throws SQLException {
    if (dataTable.isTransactional()) {
        byte[] key = dataTable.getName().getBytes();
        boolean success = false;
        try {
            FenceWait fenceWait = VisibilityFence.prepareWait(key, connection.getQueryServices().getTransactionSystemClient());
            fenceWait.await(10000, TimeUnit.MILLISECONDS);
            success = true;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION).setRootCause(e).build().buildException();
        } catch (TimeoutException | TransactionFailureException e) {
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.TX_UNABLE_TO_GET_WRITE_FENCE).setSchemaName(dataTable.getSchemaName().getString()).setTableName(dataTable.getTableName().getString()).build().buildException();
        } finally {
            // TODO: seems like an autonomous tx capability in Tephra would be useful here.
            try {
                txContext.start();
                if (logger.isInfoEnabled() && success)
                    logger.info("Added write fence at ~" + getTransaction().getReadPointer());
            } catch (TransactionFailureException e) {
                throw TransactionUtil.getTransactionFailureException(e);
            }
        }
    }
}
Also used : TransactionFailureException(org.apache.tephra.TransactionFailureException) FenceWait(org.apache.tephra.visibility.FenceWait) PhoenixIndexBuilder(org.apache.phoenix.index.PhoenixIndexBuilder) SQLExceptionInfo(org.apache.phoenix.exception.SQLExceptionInfo) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with FenceWait

use of org.apache.tephra.visibility.FenceWait in project phoenix by apache.

the class TephraTransactionContext method commitDDLFence.

@Override
public void commitDDLFence(PTable dataTable, Logger logger) throws SQLException {
    byte[] key = dataTable.getName().getBytes();
    try {
        FenceWait fenceWait = VisibilityFence.prepareWait(key, txServiceClient);
        fenceWait.await(10000, TimeUnit.MILLISECONDS);
        if (logger.isInfoEnabled()) {
            logger.info("Added write fence at ~" + getCurrentTransaction().getReadPointer());
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.INTERRUPTED_EXCEPTION).setRootCause(e).build().buildException();
    } catch (TimeoutException | TransactionFailureException e) {
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.TX_UNABLE_TO_GET_WRITE_FENCE).setSchemaName(dataTable.getSchemaName().getString()).setTableName(dataTable.getTableName().getString()).build().buildException();
    }
}
Also used : TransactionFailureException(org.apache.tephra.TransactionFailureException) FenceWait(org.apache.tephra.visibility.FenceWait) SQLExceptionInfo(org.apache.phoenix.exception.SQLExceptionInfo) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)2 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)2 TransactionFailureException (org.apache.tephra.TransactionFailureException)2 FenceWait (org.apache.tephra.visibility.FenceWait)2 PhoenixIndexBuilder (org.apache.phoenix.index.PhoenixIndexBuilder)1