use of org.apache.phoenix.schema.PTableRef in project phoenix by apache.
the class MutationState method shouldResubmitTransaction.
/**
* Determines whether indexes were added to mutated tables while the transaction was in progress.
* @return true if indexes were added and false otherwise.
* @throws SQLException
*/
private boolean shouldResubmitTransaction(Set<TableRef> txTableRefs) throws SQLException {
if (logger.isInfoEnabled())
logger.info("Checking for index updates as of " + getInitialWritePointer());
MetaDataClient client = new MetaDataClient(connection);
PMetaData cache = connection.getMetaDataCache();
boolean addedAnyIndexes = false;
boolean allImmutableTables = !txTableRefs.isEmpty();
for (TableRef tableRef : txTableRefs) {
PTable dataTable = tableRef.getTable();
List<PTable> oldIndexes;
PTableRef ptableRef = cache.getTableRef(dataTable.getKey());
oldIndexes = ptableRef.getTable().getIndexes();
// Always check at server for metadata change, as it's possible that the table is configured to not check for metadata changes
// but in this case, the tx manager is telling us it's likely that there has been a change.
MetaDataMutationResult result = client.updateCache(dataTable.getTenantId(), dataTable.getSchemaName().getString(), dataTable.getTableName().getString(), true);
long timestamp = TransactionUtil.getResolvedTime(connection, result);
tableRef.setTimeStamp(timestamp);
PTable updatedDataTable = result.getTable();
if (updatedDataTable == null) {
throw new TableNotFoundException(dataTable.getSchemaName().getString(), dataTable.getTableName().getString());
}
allImmutableTables &= updatedDataTable.isImmutableRows();
tableRef.setTable(updatedDataTable);
if (!addedAnyIndexes) {
// TODO: in theory we should do a deep equals check here, as it's possible
// that an index was dropped and recreated with the same name but different
// indexed/covered columns.
addedAnyIndexes = (!oldIndexes.equals(updatedDataTable.getIndexes()));
if (logger.isInfoEnabled())
logger.info((addedAnyIndexes ? "Updates " : "No updates ") + "as of " + timestamp + " to " + updatedDataTable.getName().getString() + " with indexes " + updatedDataTable.getIndexes());
}
}
if (logger.isInfoEnabled())
logger.info((addedAnyIndexes ? "Updates " : "No updates ") + "to indexes as of " + getInitialWritePointer() + " over " + (allImmutableTables ? " all immutable tables" : " some mutable tables"));
// If any indexes were added, then the conflict might be due to DDL/DML fence.
return allImmutableTables || addedAnyIndexes;
}
Aggregations