Search in sources :

Example 1 with IndexUpdate

use of org.apache.phoenix.hbase.index.covered.IndexUpdate in project phoenix by apache.

the class CoveredColumnIndexCodec method getIndexUpserts.

@Override
public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData indexMetaData) {
    List<IndexUpdate> updates = new ArrayList<IndexUpdate>();
    for (ColumnGroup group : groups) {
        IndexUpdate update = getIndexUpdateForGroup(group, state, indexMetaData);
        updates.add(update);
    }
    return updates;
}
Also used : IndexUpdate(org.apache.phoenix.hbase.index.covered.IndexUpdate) ArrayList(java.util.ArrayList)

Example 2 with IndexUpdate

use of org.apache.phoenix.hbase.index.covered.IndexUpdate in project phoenix by apache.

the class CoveredColumnIndexCodec method getDeleteForGroup.

/**
     * Get all the deletes necessary for a group of columns - logically, the cleanup the index table for a given index.
     * 
     * @param group
     *            index information
     * @return the cleanup for the given index, or <tt>null</tt> if no cleanup is necessary
     */
private IndexUpdate getDeleteForGroup(ColumnGroup group, TableState state, IndexMetaData indexMetaData) {
    List<CoveredColumn> refs = group.getColumns();
    try {
        Pair<Scanner, IndexUpdate> kvs = ((LocalTableState) state).getIndexedColumnsTableState(refs, false, false, indexMetaData);
        Pair<Integer, List<ColumnEntry>> columns = getNextEntries(refs, kvs.getFirst(), state.getCurrentRowKey());
        // make sure we close the scanner reference
        kvs.getFirst().close();
        // no change, just return the passed update
        if (columns.getFirst() == 0) {
            return kvs.getSecond();
        }
        // have all the column entries, so just turn it into a Delete for the row
        // convert the entries to the needed values
        byte[] rowKey = composeRowKey(state.getCurrentRowKey(), columns.getFirst(), columns.getSecond());
        Delete d = new Delete(rowKey);
        d.setTimestamp(state.getCurrentTimestamp());
        IndexUpdate update = kvs.getSecond();
        update.setUpdate(d);
        update.setTable(Bytes.toBytes(group.getTable()));
        return update;
    } catch (IOException e) {
        throw new RuntimeException("Unexpected exception when getting state for columns: " + refs);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) IOException(java.io.IOException) LocalTableState(org.apache.phoenix.hbase.index.covered.LocalTableState) IndexUpdate(org.apache.phoenix.hbase.index.covered.IndexUpdate) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with IndexUpdate

use of org.apache.phoenix.hbase.index.covered.IndexUpdate in project phoenix by apache.

the class PhoenixIndexCodec method getIndexUpserts.

@Override
public Iterable<IndexUpdate> getIndexUpserts(TableState state, IndexMetaData context) throws IOException {
    PhoenixIndexMetaData metaData = (PhoenixIndexMetaData) context;
    List<IndexMaintainer> indexMaintainers = metaData.getIndexMaintainers();
    if (indexMaintainers.get(0).isRowDeleted(state.getPendingUpdate())) {
        return Collections.emptyList();
    }
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ptr.set(state.getCurrentRowKey());
    List<IndexUpdate> indexUpdates = Lists.newArrayList();
    for (IndexMaintainer maintainer : indexMaintainers) {
        Pair<ValueGetter, IndexUpdate> statePair = state.getIndexUpdateState(maintainer.getAllColumns(), metaData.getReplayWrite() != null, false, context);
        ValueGetter valueGetter = statePair.getFirst();
        IndexUpdate indexUpdate = statePair.getSecond();
        indexUpdate.setTable(maintainer.isLocalIndex() ? tableName : maintainer.getIndexTableName());
        Put put = maintainer.buildUpdateMutation(KV_BUILDER, valueGetter, ptr, state.getCurrentTimestamp(), regionStartKey, regionEndKey);
        indexUpdate.setUpdate(put);
        indexUpdates.add(indexUpdate);
    }
    return indexUpdates;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) IndexUpdate(org.apache.phoenix.hbase.index.covered.IndexUpdate) Put(org.apache.hadoop.hbase.client.Put) ValueGetter(org.apache.phoenix.hbase.index.ValueGetter)

Example 4 with IndexUpdate

use of org.apache.phoenix.hbase.index.covered.IndexUpdate in project phoenix by apache.

the class PhoenixIndexCodec method getIndexDeletes.

@Override
public Iterable<IndexUpdate> getIndexDeletes(TableState state, IndexMetaData context) throws IOException {
    PhoenixIndexMetaData metaData = (PhoenixIndexMetaData) context;
    List<IndexMaintainer> indexMaintainers = metaData.getIndexMaintainers();
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ptr.set(state.getCurrentRowKey());
    List<IndexUpdate> indexUpdates = Lists.newArrayList();
    for (IndexMaintainer maintainer : indexMaintainers) {
        // For transactional tables, we use an index maintainer
        // to aid in rollback if there's a KeyValue column in the index. The alternative would be
        // to hold on to all uncommitted index row keys (even ones already sent to HBase) on the
        // client side.
        Set<ColumnReference> cols = Sets.newHashSet(maintainer.getAllColumns());
        cols.add(new ColumnReference(indexMaintainers.get(0).getDataEmptyKeyValueCF(), indexMaintainers.get(0).getEmptyKeyValueQualifier()));
        Pair<ValueGetter, IndexUpdate> statePair = state.getIndexUpdateState(cols, metaData.getReplayWrite() != null, true, context);
        ValueGetter valueGetter = statePair.getFirst();
        if (valueGetter != null) {
            IndexUpdate indexUpdate = statePair.getSecond();
            indexUpdate.setTable(maintainer.isLocalIndex() ? tableName : maintainer.getIndexTableName());
            Delete delete = maintainer.buildDeleteMutation(KV_BUILDER, valueGetter, ptr, state.getPendingUpdate(), state.getCurrentTimestamp(), regionStartKey, regionEndKey);
            indexUpdate.setUpdate(delete);
            indexUpdates.add(indexUpdate);
        }
    }
    return indexUpdates;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) IndexUpdate(org.apache.phoenix.hbase.index.covered.IndexUpdate) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) ValueGetter(org.apache.phoenix.hbase.index.ValueGetter)

Example 5 with IndexUpdate

use of org.apache.phoenix.hbase.index.covered.IndexUpdate in project phoenix by apache.

the class PhoenixTxIndexMutationGenerator method generateDeletes.

private void generateDeletes(PhoenixIndexMetaData indexMetaData, Collection<Pair<Mutation, byte[]>> indexUpdates, byte[] attribValue, TxTableState state) throws IOException {
    Iterable<IndexUpdate> deletes = codec.getIndexDeletes(state, indexMetaData);
    for (IndexUpdate delete : deletes) {
        if (delete.isValid()) {
            delete.getUpdate().setAttribute(PhoenixTransactionContext.TX_ROLLBACK_ATTRIBUTE_KEY, attribValue);
            indexUpdates.add(new Pair<Mutation, byte[]>(delete.getUpdate(), delete.getTableName()));
        }
    }
}
Also used : IndexUpdate(org.apache.phoenix.hbase.index.covered.IndexUpdate) Mutation(org.apache.hadoop.hbase.client.Mutation) MultiMutation(org.apache.phoenix.hbase.index.MultiMutation)

Aggregations

IndexUpdate (org.apache.phoenix.hbase.index.covered.IndexUpdate)11 ArrayList (java.util.ArrayList)4 Mutation (org.apache.hadoop.hbase.client.Mutation)4 MultiMutation (org.apache.phoenix.hbase.index.MultiMutation)4 LocalTableState (org.apache.phoenix.hbase.index.covered.LocalTableState)4 Delete (org.apache.hadoop.hbase.client.Delete)3 Put (org.apache.hadoop.hbase.client.Put)3 IOException (java.io.IOException)2 List (java.util.List)2 Result (org.apache.hadoop.hbase.client.Result)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 ValueGetter (org.apache.phoenix.hbase.index.ValueGetter)2 LocalHBaseState (org.apache.phoenix.hbase.index.covered.data.LocalHBaseState)2 Scanner (org.apache.phoenix.hbase.index.scanner.Scanner)2 Configuration (org.apache.hadoop.conf.Configuration)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)1 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)1 Test (org.junit.Test)1