throw new AccumuloException(ex);
}
}
private void mergeMetadataRecords(MergeInfo info) throws AccumuloException {
KeyExtent range = info.getRange();
log.debug("Merging metadata for " + range);
KeyExtent stop = getHighTablet(range);
log.debug("Highest tablet is " + stop);
Value firstPrevRowValue = null;
Text stopRow = stop.getMetadataEntry();
Text start = range.getPrevEndRow();
if (start == null) {
start = new Text();
}
Range scanRange = new Range(KeyExtent.getMetadataEntry(range.getTableId(), start), false, stopRow, false);
if (range.isMeta())
scanRange = scanRange.clip(Constants.METADATA_ROOT_TABLET_KEYSPACE);
BatchWriter bw = null;
try {
long fileCount = 0;
Connector conn = getConnector();
// Make file entries in highest tablet
bw = conn.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
Scanner scanner = conn.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
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);