use of org.apache.phoenix.hbase.index.scanner.Scanner in project phoenix by apache.
the class CoveredColumnIndexCodec method getIndexUpdateForGroup.
/**
* @param group
* @param state
* @return the update that should be made to the table
*/
private IndexUpdate getIndexUpdateForGroup(ColumnGroup group, TableState state, IndexMetaData indexMetaData) {
List<CoveredColumn> refs = group.getColumns();
try {
Pair<Scanner, IndexUpdate> stateInfo = ((LocalTableState) state).getIndexedColumnsTableState(refs, false, false, indexMetaData);
Scanner kvs = stateInfo.getFirst();
Pair<Integer, List<ColumnEntry>> columns = getNextEntries(refs, kvs, state.getCurrentRowKey());
// make sure we close the scanner
kvs.close();
if (columns.getFirst().intValue() == 0) {
return stateInfo.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());
Put p = new Put(rowKey, state.getCurrentTimestamp());
// add the columns to the put
addColumnsToPut(p, columns.getSecond());
// update the index info
IndexUpdate update = stateInfo.getSecond();
update.setTable(Bytes.toBytes(group.getTable()));
update.setUpdate(p);
return update;
} catch (IOException e) {
throw new RuntimeException("Unexpected exception when getting state for columns: " + refs);
}
}
use of org.apache.phoenix.hbase.index.scanner.Scanner in project phoenix by apache.
the class LocalTableState method getIndexUpdateState.
@Override
public Pair<ValueGetter, IndexUpdate> getIndexUpdateState(Collection<? extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean returnNullScannerIfRowNotFound, IndexMetaData indexMetaData) throws IOException {
Pair<Scanner, IndexUpdate> pair = getIndexedColumnsTableState(indexedColumns, ignoreNewerMutations, returnNullScannerIfRowNotFound, indexMetaData);
ValueGetter valueGetter = IndexManagementUtil.createGetterFromScanner(pair.getFirst(), getCurrentRowKey());
return new Pair<ValueGetter, IndexUpdate>(valueGetter, pair.getSecond());
}
use of org.apache.phoenix.hbase.index.scanner.Scanner in project phoenix by apache.
the class LocalTableState method getIndexedColumnsTableState.
/**
* Get a scanner on the columns that are needed by the index.
* <p>
* The returned scanner is already pre-seeked to the first {@link KeyValue} that matches the given
* columns with a timestamp earlier than the timestamp to which the table is currently set (the
* current state of the table for which we need to build an update).
* <p>
* If none of the passed columns matches any of the columns in the pending update (as determined
* by {@link ColumnReference#matchesFamily(byte[])} and
* {@link ColumnReference#matchesQualifier(byte[])}, then an empty scanner will be returned. This
* is because it doesn't make sense to build index updates when there is no change in the table
* state for any of the columns you are indexing.
* <p>
* <i>NOTE:</i> This method should <b>not</b> be used during
* {@link IndexCodec#getIndexDeletes(TableState, BatchState)} as the pending update will not yet have been
* applied - you are merely attempting to cleanup the current state and therefore do <i>not</i>
* need to track the indexed columns.
* <p>
* As a side-effect, we update a timestamp for the next-most-recent timestamp for the columns you
* request - you will never see a column with the timestamp we are tracking, but the next oldest
* timestamp for that column.
* @param indexedColumns the columns to that will be indexed
* @param ignoreNewerMutations ignore mutations newer than m when determining current state. Useful
* when replaying mutation state for partial index rebuild where writes succeeded to the data
* table, but not to the index table.
* @param indexMetaData TODO
* @return an iterator over the columns and the {@link IndexUpdate} that should be passed back to
* the builder. Even if no update is necessary for the requested columns, you still need
* to return the {@link IndexUpdate}, just don't set the update for the
* {@link IndexUpdate}.
* @throws IOException
*/
public Pair<Scanner, IndexUpdate> getIndexedColumnsTableState(Collection<? extends ColumnReference> indexedColumns, boolean ignoreNewerMutations, boolean returnNullScannerIfRowNotFound, IndexMetaData indexMetaData) throws IOException {
ensureLocalStateInitialized(indexedColumns, ignoreNewerMutations, indexMetaData);
// filter out things with a newer timestamp and track the column references to which it applies
ColumnTracker tracker = new ColumnTracker(indexedColumns);
synchronized (this.trackedColumns) {
// we haven't seen this set of columns before, so we need to create a new tracker
if (!this.trackedColumns.contains(tracker)) {
this.trackedColumns.add(tracker);
}
}
Scanner scanner = this.scannerBuilder.buildIndexedColumnScanner(indexedColumns, tracker, ts, returnNullScannerIfRowNotFound);
return new Pair<Scanner, IndexUpdate>(scanner, new IndexUpdate(tracker));
}
Aggregations