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