Search in sources :

Example 6 with Scanner

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);
    }
}
Also used : Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) 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 7 with Scanner

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());
}
Also used : Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) ValueGetter(org.apache.phoenix.hbase.index.ValueGetter) Pair(org.apache.hadoop.hbase.util.Pair)

Example 8 with Scanner

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));
}
Also used : Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) ColumnTracker(org.apache.phoenix.hbase.index.covered.update.ColumnTracker) Pair(org.apache.hadoop.hbase.util.Pair)

Aggregations

Scanner (org.apache.phoenix.hbase.index.scanner.Scanner)8 List (java.util.List)5 Put (org.apache.hadoop.hbase.client.Put)5 Scan (org.apache.hadoop.hbase.client.Scan)4 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)4 Region (org.apache.hadoop.hbase.regionserver.Region)4 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)4 LocalHBaseState (org.apache.phoenix.hbase.index.covered.data.LocalHBaseState)4 LocalTable (org.apache.phoenix.hbase.index.covered.data.LocalTable)4 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)4 Test (org.junit.Test)4 KeyValue (org.apache.hadoop.hbase.KeyValue)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2 Pair (org.apache.hadoop.hbase.util.Pair)2 IndexUpdate (org.apache.phoenix.hbase.index.covered.IndexUpdate)2 LocalTableState (org.apache.phoenix.hbase.index.covered.LocalTableState)2 Delete (org.apache.hadoop.hbase.client.Delete)1