Scanner scanner;
if (offline) {
scanner = new OfflineMetadataScanner();
} else {
scanner = new ScannerImpl(HdfsZooInstance.getInstance(), new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID()),
Constants.METADATA_TABLE_ID, Constants.NO_AUTHS);
}
scanner.setRange(Constants.METADATA_KEYSPACE);
ColumnFQ.fetch(scanner, Constants.METADATA_PREV_ROW_COLUMN);
scanner.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY);
Text colf = new Text();
Text colq = new Text();
boolean justLoc = false;
int count = 0;
for (Entry<Key,Value> entry : scanner) {
colf = entry.getKey().getColumnFamily(colf);
colq = entry.getKey().getColumnQualifier(colq);
count++;
String tableName = (new KeyExtent(entry.getKey().getRow(), (Text) null)).getTableId().toString();
TreeSet<KeyExtent> tablets = tables.get(tableName);
if (tablets == null) {
Set<Entry<String,TreeSet<KeyExtent>>> es = tables.entrySet();
for (Entry<String,TreeSet<KeyExtent>> entry2 : es) {
checkTable(entry2.getKey(), entry2.getValue(), patch);
}
tables.clear();
tablets = new TreeSet<KeyExtent>();
tables.put(tableName, tablets);
}
if (Constants.METADATA_PREV_ROW_COLUMN.equals(colf, colq)) {
KeyExtent tabletKe = new KeyExtent(entry.getKey().getRow(), entry.getValue());
tablets.add(tabletKe);
justLoc = false;
} else if (colf.equals(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY)) {
if (justLoc) {
System.out.println("Problem at key " + entry.getKey());
sawProblems = true;
if (patch) {
Writer t = MetadataTable.getMetadataTable(new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID()));
Key k = entry.getKey();
Mutation m = new Mutation(k.getRow());
m.putDelete(k.getColumnFamily(), k.getColumnQualifier());
try {
t.update(m);