use of org.apache.phoenix.hbase.index.covered.update.IndexUpdateManager in project phoenix by apache.
the class NonTxIndexBuilder method getIndexUpdate.
@Override
public Collection<Pair<Mutation, byte[]>> getIndexUpdate(Mutation mutation, IndexMetaData indexMetaData) throws IOException {
// create a state manager, so we can manage each batch
LocalTableState state = new LocalTableState(env, localTable, mutation);
// build the index updates for each group
IndexUpdateManager manager = new IndexUpdateManager(indexMetaData);
batchMutationAndAddUpdates(manager, state, mutation, indexMetaData);
if (LOG.isTraceEnabled()) {
LOG.trace("Found index updates for Mutation: " + mutation + "\n" + manager);
}
return manager.toMap();
}
use of org.apache.phoenix.hbase.index.covered.update.IndexUpdateManager in project phoenix by apache.
the class TestIndexUpdateManager method testCancelingUpdates.
/**
* When making updates we need to cancel out {@link Delete} and {@link Put}s for the same row.
* @throws Exception on failure
*/
@Test
public void testCancelingUpdates() throws Exception {
IndexUpdateManager manager = new IndexUpdateManager(mockIndexMetaData);
long ts1 = 10, ts2 = 11;
// at different timestamps, so both should be retained
Delete d = new Delete(row, ts1);
Put p = new Put(row, ts2);
manager.addIndexUpdate(table, d);
manager.addIndexUpdate(table, p);
List<Mutation> pending = new ArrayList<Mutation>();
pending.add(p);
pending.add(d);
validate(manager, pending);
// add a delete that should cancel out the put, leading to only one delete remaining
Delete d2 = new Delete(row, ts2);
manager.addIndexUpdate(table, d2);
pending.add(d);
validate(manager, pending);
// double-deletes of the same row only retain the existing one, which was already canceled out
// above
Delete d3 = new Delete(row, ts2);
manager.addIndexUpdate(table, d3);
pending.add(d);
validate(manager, pending);
// if there is just a put and a delete at the same ts, no pending updates should be returned
manager = new IndexUpdateManager(mockIndexMetaData);
manager.addIndexUpdate(table, d2);
manager.addIndexUpdate(table, p);
validate(manager, Collections.<Mutation>emptyList());
// different row insertions can be tricky too, if you don't get the base cases right
manager = new IndexUpdateManager(mockIndexMetaData);
manager.addIndexUpdate(table, p);
// this row definitely sorts after the current row
byte[] row1 = Bytes.toBytes("row1");
Put p1 = new Put(row1, ts1);
manager.addIndexUpdate(table, p1);
// this delete should completely cover the given put and both should be removed
Delete d4 = new Delete(row1, ts1);
manager.addIndexUpdate(table, d4);
pending.clear();
pending.add(p);
validate(manager, pending);
}
use of org.apache.phoenix.hbase.index.covered.update.IndexUpdateManager in project phoenix by apache.
the class TestIndexUpdateManager method testMutationComparator.
@Test
public void testMutationComparator() throws Exception {
IndexUpdateManager manager = new IndexUpdateManager(mockIndexMetaData);
Comparator<Mutation> comparator = manager.COMPARATOR;
Put p = new Put(row, 10);
// lexigraphically earlier should sort earlier
Put p1 = new Put(Bytes.toBytes("ro"), 10);
assertTrue("lexigraphically later sorting first, should be earlier first.", comparator.compare(p, p1) > 0);
p1 = new Put(Bytes.toBytes("row1"), 10);
assertTrue("lexigraphically later sorting first, should be earlier first.", comparator.compare(p1, p) > 0);
// larger ts sorts before smaller, for the same row
p1 = new Put(row, 11);
assertTrue("Smaller timestamp sorting first, should be larger first.", comparator.compare(p, p1) > 0);
// still true, even for deletes
Delete d = new Delete(row, 11);
assertTrue("Smaller timestamp sorting first, should be larger first.", comparator.compare(p, d) > 0);
// for the same row, t1, the delete should sort earlier
d = new Delete(row, 10);
assertTrue("Delete doesn't sort before put, for the same row and ts", comparator.compare(p, d) > 0);
// but for different rows, we still respect the row sorting.
d = new Delete(Bytes.toBytes("row1"), 10);
assertTrue("Delete doesn't sort before put, for the same row and ts", comparator.compare(p, d) < 0);
}
use of org.apache.phoenix.hbase.index.covered.update.IndexUpdateManager in project phoenix by apache.
the class CoveredColumnIndexer method getIndexUpdateForFilteredRows.
@Override
public Collection<Pair<Mutation, byte[]>> getIndexUpdateForFilteredRows(Collection<KeyValue> filtered, IndexMetaData indexMetaData) throws IOException {
// stores all the return values
IndexUpdateManager updateMap = new IndexUpdateManager(indexMetaData);
// batch the updates by row to make life easier and ordered
Collection<Batch> batches = batchByRow(filtered);
for (Batch batch : batches) {
Cell curKV = batch.getKvs().iterator().next();
Put p = new Put(curKV.getRowArray(), curKV.getRowOffset(), curKV.getRowLength());
for (Cell kv : batch.getKvs()) {
// we only need to cleanup Put entries
byte type = kv.getTypeByte();
Type t = KeyValue.Type.codeToType(type);
if (!t.equals(Type.Put)) {
continue;
}
// add the kv independently
p.add(kv);
}
// do the usual thing as for deletes
Collection<Batch> timeBatch = createTimestampBatchesFromMutation(p);
LocalTableState state = new LocalTableState(env, localTable, p);
for (Batch entry : timeBatch) {
//just set the timestamp on the table - it already has all the future state
state.setCurrentTimestamp(entry.getTimestamp());
this.addDeleteUpdatesToMap(updateMap, state, entry.getTimestamp(), indexMetaData);
}
}
return updateMap.toMap();
}
Aggregations