Search in sources :

Example 36 with MetaDataMutationResult

use of org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult in project phoenix by apache.

the class MutationState method validate.

private long validate(TableRef tableRef, Map<ImmutableBytesPtr, RowMutationState> rowKeyToColumnMap) throws SQLException {
    Long scn = connection.getSCN();
    MetaDataClient client = new MetaDataClient(connection);
    long serverTimeStamp = tableRef.getTimeStamp();
    // If we're auto committing, we've already validated the schema when we got the ColumnResolver,
    // so no need to do it again here.
    PTable table = tableRef.getTable();
    MetaDataMutationResult result = client.updateCache(table.getSchemaName().getString(), table.getTableName().getString());
    PTable resolvedTable = result.getTable();
    if (resolvedTable == null) {
        throw new TableNotFoundException(table.getSchemaName().getString(), table.getTableName().getString());
    }
    // Always update tableRef table as the one we've cached may be out of date since when we executed
    // the UPSERT VALUES call and updated in the cache before this.
    tableRef.setTable(resolvedTable);
    List<PTable> indexes = resolvedTable.getIndexes();
    for (PTable idxTtable : indexes) {
        // our failure mode is block writes on index failure.
        if (idxTtable.getIndexState() == PIndexState.ACTIVE && idxTtable.getIndexDisableTimestamp() > 0) {
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.INDEX_FAILURE_BLOCK_WRITE).setSchemaName(table.getSchemaName().getString()).setTableName(table.getTableName().getString()).build().buildException();
        }
    }
    long timestamp = result.getMutationTime();
    if (timestamp != QueryConstants.UNSET_TIMESTAMP) {
        serverTimeStamp = timestamp;
        if (result.wasUpdated()) {
            List<PColumn> columns = Lists.newArrayListWithExpectedSize(table.getColumns().size());
            for (Map.Entry<ImmutableBytesPtr, RowMutationState> rowEntry : rowKeyToColumnMap.entrySet()) {
                RowMutationState valueEntry = rowEntry.getValue();
                if (valueEntry != null) {
                    Map<PColumn, byte[]> colValues = valueEntry.getColumnValues();
                    if (colValues != PRow.DELETE_MARKER) {
                        for (PColumn column : colValues.keySet()) {
                            if (!column.isDynamic())
                                columns.add(column);
                        }
                    }
                }
            }
            for (PColumn column : columns) {
                if (column != null) {
                    resolvedTable.getColumnFamily(column.getFamilyName().getString()).getPColumnForColumnName(column.getName().getString());
                }
            }
        }
    }
    return scn == null ? serverTimeStamp == QueryConstants.UNSET_TIMESTAMP ? HConstants.LATEST_TIMESTAMP : serverTimeStamp : scn;
}
Also used : MetaDataClient(org.apache.phoenix.schema.MetaDataClient) PhoenixIndexBuilder(org.apache.phoenix.index.PhoenixIndexBuilder) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) PTable(org.apache.phoenix.schema.PTable) PColumn(org.apache.phoenix.schema.PColumn) TableNotFoundException(org.apache.phoenix.schema.TableNotFoundException) PLong(org.apache.phoenix.schema.types.PLong) MetaDataMutationResult(org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult) Map(java.util.Map)

Aggregations

MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)36 Mutation (org.apache.hadoop.hbase.client.Mutation)20 MutationCode (org.apache.phoenix.coprocessor.MetaDataProtocol.MutationCode)15 PLong (org.apache.phoenix.schema.types.PLong)11 MutationState (org.apache.phoenix.execute.MutationState)10 PTable (org.apache.phoenix.schema.PTable)10 PUnsignedLong (org.apache.phoenix.schema.types.PUnsignedLong)9 IOException (java.io.IOException)8 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)8 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)8 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)8 MetaDataResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse)8 MetaDataService (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService)8 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)8 PhoenixIndexBuilder (org.apache.phoenix.index.PhoenixIndexBuilder)8 TableNotFoundException (org.apache.phoenix.schema.TableNotFoundException)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)7