public static void cloneTable( Instance instance, String srcTableId, String tableId, VolumeManager volumeManager) throws Exception { Connector conn = instance.getConnector( SystemCredentials.get().getPrincipal(), SystemCredentials.get().getToken()); BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig()); while (true) { try { initializeClone(srcTableId, tableId, conn, bw); // the following loop looks changes in the file that occurred during the copy.. if files // were dereferenced then they could have been GCed while (true) { int rewrites = checkClone(srcTableId, tableId, conn, bw); if (rewrites == 0) break; } bw.flush(); break; } catch (TabletIterator.TabletDeletedException tde) { // tablets were merged in the src table bw.flush(); // delete what we have cloned and try again deleteTable(tableId, false, SystemCredentials.get(), null); log.debug( "Tablets merged in table " + srcTableId + " while attempting to clone, trying again"); UtilWaitThread.sleep(100); } } // delete the clone markers and create directory entries Scanner mscanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY); mscanner.setRange(new KeyExtent(new Text(tableId), null, null).toMetadataRange()); mscanner.fetchColumnFamily(ClonedColumnFamily.NAME); int dirCount = 0; for (Entry<Key, Value> entry : mscanner) { Key k = entry.getKey(); Mutation m = new Mutation(k.getRow()); m.putDelete(k.getColumnFamily(), k.getColumnQualifier()); String dir = volumeManager.choose(ServerConstants.getTablesDirs()) + "/" + tableId + new String(FastFormat.toZeroPaddedString(dirCount++, 8, 16, "/c-".getBytes())); TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value(dir.getBytes())); bw.addMutation(m); } bw.close(); }