use of org.apache.phoenix.hbase.index.covered.update.IndexedColumnGroup in project phoenix by apache.
the class NonTxIndexBuilder method addCurrentStateMutationsForBatch.
/**
* Add the necessary mutations for the pending batch on the local state. Handles rolling up through history to
* determine the index changes after applying the batch (for the case where the batch is back in time).
*
* @param updateMap
* to update with index mutations
* @param state
* current state of the table
* @param indexMetaData TODO
* @param batch
* to apply to the current state
* @return the minimum timestamp across all index columns requested. If {@link ColumnTracker#isNewestTime(long)}
* returns <tt>true</tt> on the returned timestamp, we know that this <i>was not a back-in-time update</i>.
* @throws IOException
*/
private long addCurrentStateMutationsForBatch(IndexUpdateManager updateMap, LocalTableState state, IndexMetaData indexMetaData) throws IOException {
// get the index updates for this current batch
Iterable<IndexUpdate> upserts = codec.getIndexUpserts(state, indexMetaData);
state.resetTrackedColumns();
/*
* go through all the pending updates. If we are sure that all the entries are the latest timestamp, we can just
* add the index updates and move on. However, if there are columns that we skip past (based on the timestamp of
* the batch), we need to roll back up the history. Regardless of whether or not they are the latest timestamp,
* the entries here are going to be correct for the current batch timestamp, so we add them to the updates. The
* only thing we really care about it if we need to roll up the history and fix it as we go.
*/
// timestamp of the next update we need to track
long minTs = ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP;
List<IndexedColumnGroup> columnHints = new ArrayList<IndexedColumnGroup>();
for (IndexUpdate update : upserts) {
// this is the one bit where we check the timestamps
final ColumnTracker tracker = update.getIndexedColumns();
long trackerTs = tracker.getTS();
// update the next min TS we need to track
if (trackerTs < minTs) {
minTs = tracker.getTS();
}
// track index hints for the next round. Hint if we need an update for that column for the
// next timestamp. These columns clearly won't need to update as we go through time as they
// already match the most recent possible thing.
boolean needsCleanup = false;
if (tracker.hasNewerTimestamps()) {
columnHints.add(tracker);
// this update also needs to be cleaned up at the next timestamp because it not the latest.
needsCleanup = true;
}
// only make the put if the index update has been setup
if (update.isValid()) {
byte[] table = update.getTableName();
Mutation mutation = update.getUpdate();
updateMap.addIndexUpdate(table, mutation);
// only make the cleanup if we made a put and need cleanup
if (needsCleanup) {
// there is a TS for the interested columns that is greater than the columns in the
// put. Therefore, we need to issue a delete at the same timestamp
Delete d = new Delete(mutation.getRow());
d.setTimestamp(tracker.getTS());
updateMap.addIndexUpdate(table, d);
}
}
}
return minTs;
}
Aggregations