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);
}
}
}
}
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();
}
}
Aggregations