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