scanner.setRange(scanRange);
Constants.METADATA_PREV_ROW_COLUMN.fetch(scanner);
Constants.METADATA_TIME_COLUMN.fetch(scanner);
Constants.METADATA_DIRECTORY_COLUMN.fetch(scanner);
scanner.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);
Mutation m = new Mutation(stopRow);
String maxLogicalTime = null;
for (Entry<Key,Value> entry : scanner) {
Key key = entry.getKey();
Value value = entry.getValue();
if (key.getColumnFamily().equals(Constants.METADATA_DATAFILE_COLUMN_FAMILY)) {
m.put(key.getColumnFamily(), key.getColumnQualifier(), value);
fileCount++;
} else if (Constants.METADATA_PREV_ROW_COLUMN.hasColumns(key) && firstPrevRowValue == null) {
log.debug("prevRow entry for lowest tablet is " + value);
firstPrevRowValue = new Value(value);
} else if (Constants.METADATA_TIME_COLUMN.hasColumns(key)) {
maxLogicalTime = TabletTime.maxMetadataTime(maxLogicalTime, value.toString());
} else if (Constants.METADATA_DIRECTORY_COLUMN.hasColumns(key)) {
if (!range.isMeta())
bw.addMutation(MetadataTable.createDeleteMutation(range.getTableId().toString(), entry.getValue().toString()));
}
}
// read the logical time from the last tablet in the merge range, it is not included in
// the loop above
scanner = conn.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
Range last = new Range(stopRow);
if (range.isMeta())
last = last.clip(Constants.METADATA_ROOT_TABLET_KEYSPACE);
scanner.setRange(last);
Constants.METADATA_TIME_COLUMN.fetch(scanner);
for (Entry<Key,Value> entry : scanner) {
if (Constants.METADATA_TIME_COLUMN.hasColumns(entry.getKey())) {
maxLogicalTime = TabletTime.maxMetadataTime(maxLogicalTime, entry.getValue().toString());
}
}
if (maxLogicalTime != null)
Constants.METADATA_TIME_COLUMN.put(m, new Value(maxLogicalTime.getBytes(Constants.UTF8)));
if (!m.getUpdates().isEmpty()) {
bw.addMutation(m);
}
bw.flush();
log.debug("Moved " + fileCount + " files to " + stop);
if (firstPrevRowValue == null) {
log.debug("tablet already merged");
return;
}
stop.setPrevEndRow(KeyExtent.decodePrevEndRow(firstPrevRowValue));
Mutation updatePrevRow = stop.getPrevRowUpdateMutation();
log.debug("Setting the prevRow for last tablet: " + stop);
bw.addMutation(updatePrevRow);
bw.flush();
deleteTablets(scanRange, bw, conn);
// Clean-up the last chopped marker
m = new Mutation(stopRow);
Constants.METADATA_CHOPPED_COLUMN.putDelete(m);
bw.addMutation(m);
bw.flush();
} catch (Exception ex) {