Search in sources :

Example 1 with CachedLocalTable

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

the class IndexBuildManager method getIndexUpdates.

public void getIndexUpdates(ListMultimap<HTableInterfaceReference, Pair<Mutation, byte[]>> indexUpdates, MiniBatchOperationInProgress<Mutation> miniBatchOp, Collection<? extends Mutation> mutations, IndexMetaData indexMetaData) throws Throwable {
    // notify the delegate that we have started processing a batch
    this.delegate.batchStarted(miniBatchOp, indexMetaData);
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(mutations, (PhoenixIndexMetaData) indexMetaData, this.regionCoprocessorEnvironment.getRegion());
    // Avoid the Object overhead of the executor when it's not actually parallelizing anything.
    for (Mutation m : mutations) {
        Collection<Pair<Mutation, byte[]>> updates = delegate.getIndexUpdate(m, indexMetaData, cachedLocalTable);
        for (Pair<Mutation, byte[]> update : updates) {
            indexUpdates.put(new HTableInterfaceReference(new ImmutableBytesPtr(update.getSecond())), new Pair<>(update.getFirst(), m.getRow()));
        }
    }
}
Also used : HTableInterfaceReference(org.apache.phoenix.hbase.index.table.HTableInterfaceReference) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Mutation(org.apache.hadoop.hbase.client.Mutation) Pair(org.apache.hadoop.hbase.util.Pair)

Example 2 with CachedLocalTable

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

the class LocalTableStateTest method testCorrectRollback.

/**
 * Test that we correctly rollback the state of keyvalue
 * @throws Exception
 */
@Test
@SuppressWarnings("unchecked")
public void testCorrectRollback() throws Exception {
    Put m = new Put(row);
    m.addColumn(fam, qual, ts, val);
    // setup mocks
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Region region = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    final byte[] stored = Bytes.toBytes("stored-value");
    final KeyValue storedKv = new KeyValue(row, fam, qual, ts, Type.Put, stored);
    storedKv.setSequenceId(2);
    HashMap<ImmutableBytesPtr, List<Cell>> rowKeyPtrToCells = new HashMap<ImmutableBytesPtr, List<Cell>>();
    rowKeyPtrToCells.put(new ImmutableBytesPtr(row), Collections.singletonList((Cell) storedKv));
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(rowKeyPtrToCells);
    LocalTableState table = new LocalTableState(cachedLocalTable, m);
    // add the kvs from the mutation
    KeyValue kv = KeyValueUtil.ensureKeyValue(m.get(fam, qual).get(0));
    kv.setSequenceId(0);
    table.addPendingUpdates(kv);
    // setup the lookup
    ColumnReference col = new ColumnReference(fam, qual);
    table.setCurrentTimestamp(ts);
    // check that the value is there
    Pair<CoveredDeleteScanner, IndexUpdate> p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    Scanner s = p.getFirst();
    assertEquals("Didn't get the pending mutation's value first", kv, s.next());
    // rollback that value
    table.rollback(Arrays.asList(kv));
    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    s = p.getFirst();
    assertEquals("Didn't correctly rollback the row - still found it!", null, s.next());
}
Also used : CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) KeyValue(org.apache.hadoop.hbase.KeyValue) HashMap(java.util.HashMap) CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Put(org.apache.hadoop.hbase.client.Put) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Region(org.apache.hadoop.hbase.regionserver.Region) List(java.util.List) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Cell(org.apache.hadoop.hbase.Cell) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test)

Example 3 with CachedLocalTable

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

the class LocalTableStateTest method testCorrectOrderingWithLazyLoadingColumns.

@SuppressWarnings("unchecked")
@Test
public void testCorrectOrderingWithLazyLoadingColumns() throws Exception {
    Put m = new Put(row);
    m.addColumn(fam, qual, ts, val);
    // setup mocks
    Configuration conf = new Configuration(false);
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Mockito.when(env.getConfiguration()).thenReturn(conf);
    Region region = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    final byte[] stored = Bytes.toBytes("stored-value");
    KeyValue kv = new KeyValue(row, fam, qual, ts, Type.Put, stored);
    kv.setSequenceId(0);
    HashMap<ImmutableBytesPtr, List<Cell>> rowKeyPtrToCells = new HashMap<ImmutableBytesPtr, List<Cell>>();
    rowKeyPtrToCells.put(new ImmutableBytesPtr(row), Collections.singletonList((Cell) kv));
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(rowKeyPtrToCells);
    LocalTableState table = new LocalTableState(cachedLocalTable, m);
    // add the kvs from the mutation
    table.addPendingUpdates(m.get(fam, qual));
    // setup the lookup
    ColumnReference col = new ColumnReference(fam, qual);
    table.setCurrentTimestamp(ts);
    // check that our value still shows up first on scan, even though this is a lazy load
    Pair<CoveredDeleteScanner, IndexUpdate> p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    Scanner s = p.getFirst();
    assertEquals("Didn't get the pending mutation's value first", m.get(fam, qual).get(0), s.next());
}
Also used : CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Put(org.apache.hadoop.hbase.client.Put) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Region(org.apache.hadoop.hbase.regionserver.Region) List(java.util.List) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Cell(org.apache.hadoop.hbase.Cell) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test)

Example 4 with CachedLocalTable

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

the class NonTxIndexBuilderTest method testManyVersions.

/**
 * Tests getting an index update for a mutation with 200 versions Before, the issue PHOENIX-3807
 * was causing this test to take >90 seconds, so here we set a timeout of 5 seconds
 */
@Test(timeout = 10000)
public void testManyVersions() throws IOException {
    // when doing a rebuild, we are replaying mutations so we want to ignore newer mutations
    // see LocalTable#getCurrentRowState()
    Mockito.when(mockIndexMetaData.getReplayWrite()).thenReturn(ReplayWrite.INDEX_ONLY);
    MultiMutation mutation = getMultipleVersionMutation(200);
    currentRowCells = mutation.getFamilyCellMap().get(FAM);
    Collection<? extends Mutation> mutations = IndexManagementUtil.flattenMutationsByTimestamp(Collections.singletonList(mutation));
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(mutations, this.mockIndexMetaData, this.indexBuilder.getEnv().getRegion());
    Collection<Pair<Mutation, byte[]>> indexUpdates = Lists.newArrayList();
    for (Mutation m : IndexManagementUtil.flattenMutationsByTimestamp(Collections.singletonList(mutation))) {
        indexUpdates.addAll(indexBuilder.getIndexUpdate(m, mockIndexMetaData, cachedLocalTable));
    }
    assertNotEquals(0, indexUpdates.size());
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Mutation(org.apache.hadoop.hbase.client.Mutation) MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 5 with CachedLocalTable

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

the class LocalTableStateTest method testNoScannerForImmutableRows.

@Test
public void testNoScannerForImmutableRows() throws Exception {
    IndexMetaData indexMetaData = new IndexMetaData() {

        @Override
        public ReplayWrite getReplayWrite() {
            return null;
        }

        @Override
        public boolean requiresPriorRowState(Mutation m) {
            return false;
        }

        @Override
        public int getClientVersion() {
            return ScanUtil.UNKNOWN_CLIENT_VERSION;
        }
    };
    Put m = new Put(row);
    m.addColumn(fam, qual, ts, val);
    // setup mocks
    Configuration conf = new Configuration(false);
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Mockito.when(env.getConfiguration()).thenReturn(conf);
    Region region = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(null);
    LocalTableState table = new LocalTableState(cachedLocalTable, m);
    // add the kvs from the mutation
    table.addPendingUpdates(m.get(fam, qual));
    // setup the lookup
    ColumnReference col = new ColumnReference(fam, qual);
    table.setCurrentTimestamp(ts);
    // check that our value still shows up first on scan, even though this is a lazy load
    Pair<CoveredDeleteScanner, IndexUpdate> p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    Scanner s = p.getFirst();
    assertEquals("Didn't get the pending mutation's value first", m.get(fam, qual).get(0), s.next());
}
Also used : CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) Configuration(org.apache.hadoop.conf.Configuration) CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) Put(org.apache.hadoop.hbase.client.Put) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Region(org.apache.hadoop.hbase.regionserver.Region) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Mutation(org.apache.hadoop.hbase.client.Mutation) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test)

Aggregations

CachedLocalTable (org.apache.phoenix.hbase.index.covered.data.CachedLocalTable)9 Test (org.junit.Test)7 Put (org.apache.hadoop.hbase.client.Put)6 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)6 Mutation (org.apache.hadoop.hbase.client.Mutation)5 Pair (org.apache.hadoop.hbase.util.Pair)5 Cell (org.apache.hadoop.hbase.Cell)4 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)4 Region (org.apache.hadoop.hbase.regionserver.Region)4 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)4 Scanner (org.apache.phoenix.hbase.index.scanner.Scanner)4 CoveredDeleteScanner (org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner)4 HashMap (java.util.HashMap)3 List (java.util.List)3 KeyValue (org.apache.hadoop.hbase.KeyValue)3 MultiMutation (org.apache.phoenix.hbase.index.MultiMutation)3 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)3 Configuration (org.apache.hadoop.conf.Configuration)2 ArrayList (java.util.ArrayList)1 IndexMetaData (org.apache.phoenix.hbase.index.covered.IndexMetaData)1