}
@Override
public Collection<Pair<Mutation, byte[]>> getIndexUpdate(Delete d) throws IOException {
// stores all the return values
IndexUpdateManager updateMap = new IndexUpdateManager();
// We have to figure out which kind of delete it is, since we need to do different things if its
// a general (row) delete, versus a delete of just a single column or family
Map<byte[], List<KeyValue>> families = d.getFamilyMap();
/*
* Option 1: its a row delete marker, so we just need to delete the most recent state for each
* group, as of the specified timestamp in the delete. This can happen if we have a single row
* update and it is part of a batch mutation (prepare doesn't happen until later... maybe a
* bug?). In a single delete, this delete gets all the column families appended, so the family
* map won't be empty by the time it gets here.
*/
if (families.size() == 0) {
LocalTableState state = new LocalTableState(env, localTable, d);
// get a consistent view of name
long now = d.getTimeStamp();
if (now == HConstants.LATEST_TIMESTAMP) {
now = EnvironmentEdgeManager.currentTimeMillis();
// update the delete's idea of 'now' to be consistent with the index
d.setTimestamp(now);
}
// get deletes from the codec
// we only need to get deletes and not add puts because this delete covers all columns
addDeleteUpdatesToMap(updateMap, state, now);
/*
* Update the current state for all the kvs in the delete. Generally, we would just iterate
* the family map, but since we go here, the family map is empty! Therefore, we need to fake a
* bunch of family deletes (just like hos HRegion#prepareDelete works). This is just needed
* for current version of HBase that has an issue where the batch update doesn't update the
* deletes before calling the hook.
*/
byte[] deleteRow = d.getRow();
for (byte[] family : this.env.getRegion().getTableDesc().getFamiliesKeys()) {
state.addPendingUpdates(new KeyValue(deleteRow, family, null, now,
KeyValue.Type.DeleteFamily));
}
} else {
// Option 2: Its actually a bunch single updates, which can have different timestamps.
// Therefore, we need to do something similar to the put case and batch by timestamp
batchMutationAndAddUpdates(updateMap, d);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Found index updates for Delete: " + d + "\n" + updateMap);
}
return updateMap.toMap();
}