@Test public void replaceRelatives() throws Exception { AccumuloClient c = createMock(AccumuloClient.class); VolumeManager fs = createMock(VolumeManager.class); expect(fs.exists(anyObject())).andReturn(true).anyTimes(); SortedMap<Key,Value> map = new TreeMap<>(); map.put(new Key("1b;row_000050", "file", "../1b/default_tablet/A000001c.rf"), new Value("1")); map.put(new Key("1b;row_000050", "file", "../1b/default_tablet/F000001m.rf"), new Value("2")); map.put(new Key("1b;row_000050", "file", "../1b/t-000008t/F000004x.rf"), new Value("3")); map.put(new Key("1b;row_000050", "file", "/t-000008t/F0000054.rf"), new Value("4")); map.put(new Key("1b<", "file", "../1b/default_tablet/A000001c.rf"), new Value("1")); map.put(new Key("1b<", "file", "../1b/default_tablet/F000001m.rf"), new Value("2")); map.put(new Key("1b<", "file", "../1b/t-000008t/F000004x.rf"), new Value("3")); map.put(new Key("1b<", "file", "/t-000008t/F0000054.rf"), new Value("4")); map.put(new Key("1b<", "file", "hdfs: new Value("5")); map.put(new Key("1b<", "file", "hdfs: new Value("5")); List<Mutation> expected = new ArrayList<>(); expected.add(replaceMut("1b;row_000050", "file:/accumulo/tables/1b/default_tablet/A000001c.rf", "1", "../1b/default_tablet/A000001c.rf")); expected.add(replaceMut("1b;row_000050", "file:/accumulo/tables/1b/default_tablet/F000001m.rf", "2", "../1b/default_tablet/F000001m.rf")); expected.add(replaceMut("1b;row_000050", "file:/accumulo/tables/1b/t-000008t/F000004x.rf", "3", "../1b/t-000008t/F000004x.rf")); expected.add(replaceMut("1b;row_000050", "file:/accumulo/tables/1b/t-000008t/F0000054.rf", "4", "/t-000008t/F0000054.rf")); expected.add(replaceMut("1b<", "file:/accumulo/tables/1b/default_tablet/A000001c.rf", "1", "../1b/default_tablet/A000001c.rf")); expected.add(replaceMut("1b<", "file:/accumulo/tables/1b/default_tablet/F000001m.rf", "2", "../1b/default_tablet/F000001m.rf")); expected.add(replaceMut("1b<", "file:/accumulo/tables/1b/t-000008t/F000004x.rf", "3", "../1b/t-000008t/F000004x.rf")); expected.add(replaceMut("1b<", "file:/accumulo/tables/1b/t-000008t/F0000054.rf", "4", "/t-000008t/F0000054.rf")); List<Mutation> results = new ArrayList<>(); setupMocks(c, fs, map, results); Upgrader9to10.replaceRelativePaths(c, fs, tableName, volumeUpgrade); verifyPathsReplaced(expected, results); }
public static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName, String upgradeProperty) { try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY); BatchWriter writer = c.createBatchWriter(tableName)) { scanner.fetchColumnFamily(DataFileColumnFamily.NAME); for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); String metaEntry = key.getColumnQualifier().toString(); if (!metaEntry.contains(":")) { if (upgradeProperty == null || upgradeProperty.isBlank()) { throw new IllegalArgumentException( "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey()); } Path relPath = resolveRelativePath(metaEntry, key); Path absPath = new Path(upgradeProperty, relPath); if (fs.exists(absPath)) { log.debug("Changing Tablet File path from {} to {}", metaEntry, absPath); Mutation m = new Mutation(key.getRow()); m.at().family(key.getColumnFamily()).qualifier(absPath.toString()) .visibility(key.getColumnVisibility()).put(entry.getValue()); m.at().family(key.getColumnFamily()).qualifier(key.getColumnQualifierData().toArray()) .visibility(key.getColumnVisibility()).delete(); writer.addMutation(m); } else { throw new IllegalArgumentException( "Relative Tablet file " + relPath + " not found at " + absPath); } } } } catch (MutationsRejectedException | TableNotFoundException e) { throw new IllegalStateException(e); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }
Upgrader9to10 implements Upgrader { public static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName, String upgradeProperty) { try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY); BatchWriter writer = c.createBatchWriter(tableName)) { scanner.fetchColumnFamily(DataFileColumnFamily.NAME); for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); String metaEntry = key.getColumnQualifier().toString(); if (!metaEntry.contains(":")) { if (upgradeProperty == null || upgradeProperty.isBlank()) { throw new IllegalArgumentException( "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey()); } Path relPath = resolveRelativePath(metaEntry, key); Path absPath = new Path(upgradeProperty, relPath); if (fs.exists(absPath)) { log.debug("Changing Tablet File path from {} to {}", metaEntry, absPath); Mutation m = new Mutation(key.getRow()); m.at().family(key.getColumnFamily()).qualifier(absPath.toString()) .visibility(key.getColumnVisibility()).put(entry.getValue()); m.at().family(key.getColumnFamily()).qualifier(key.getColumnQualifierData().toArray()) .visibility(key.getColumnVisibility()).delete(); writer.addMutation(m); } else { throw new IllegalArgumentException( "Relative Tablet file " + relPath + " not found at " + absPath); } } } } catch (MutationsRejectedException | TableNotFoundException e) { throw new IllegalStateException(e); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } } }
Upgrader9to10 implements Upgrader { public static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName, String upgradeProperty) { try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY); BatchWriter writer = c.createBatchWriter(tableName)) { scanner.fetchColumnFamily(DataFileColumnFamily.NAME); for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); String metaEntry = key.getColumnQualifier().toString(); if (!metaEntry.contains(":")) { if (upgradeProperty == null || upgradeProperty.isBlank()) { throw new IllegalArgumentException( "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey()); } Path relPath = resolveRelativePath(metaEntry, key); Path absPath = new Path(upgradeProperty, relPath); if (fs.exists(absPath)) { log.debug("Changing Tablet File path from {} to {}", metaEntry, absPath); Mutation m = new Mutation(key.getRow()); m.at().family(key.getColumnFamily()).qualifier(absPath.toString()) .visibility(key.getColumnVisibility()).put(entry.getValue()); m.at().family(key.getColumnFamily()).qualifier(key.getColumnQualifierData().toArray()) .visibility(key.getColumnVisibility()).delete(); writer.addMutation(m); } else { throw new IllegalArgumentException( "Relative Tablet file " + relPath + " not found at " + absPath); } } } } catch (MutationsRejectedException | TableNotFoundException e) { throw new IllegalStateException(e); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }  }
Upgrader9to10 implements Upgrader { public static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName, String upgradeProperty) { try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY); BatchWriter writer = c.createBatchWriter(tableName)) { scanner.fetchColumnFamily(DataFileColumnFamily.NAME); for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); String metaEntry = key.getColumnQualifier().toString(); if (!metaEntry.contains(":")) { if (upgradeProperty == null || upgradeProperty.isBlank()) { throw new IllegalArgumentException( "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey()); } Path relPath = resolveRelativePath(metaEntry, key); Path absPath = new Path(upgradeProperty, relPath); if (fs.exists(absPath)) { log.debug("Changing Tablet File path from {} to {}", metaEntry, absPath); Mutation m = new Mutation(key.getRow()); m.at().family(key.getColumnFamily()).qualifier(absPath.toString()) .visibility(key.getColumnVisibility()).put(entry.getValue()); m.at().family(key.getColumnFamily()).qualifier(key.getColumnQualifierData().toArray()) .visibility(key.getColumnVisibility()).delete(); writer.addMutation(m); } else { throw new IllegalArgumentException( "Relative Tablet file " + relPath + " not found at " + absPath); } } } } catch (MutationsRejectedException | TableNotFoundException e) { throw new IllegalStateException(e); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }  @Override void upgradeZookeeper(ServerContext ctx); @Override void upgradeRoot(ServerContext ctx); @Override void upgradeMetadata(ServerContext ctx); void upgradeFileDeletes(ServerContext ctx, Ample.DataLevel level); void upgradeDirColumns(ServerContext ctx, Ample.DataLevel level); static String upgradeDirColumn(String dir); static void upgradeRelativePaths(ServerContext ctx, Ample.DataLevel level); static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName,
      String upgradeProperty); static boolean checkForRelativePaths(AccumuloClient client, VolumeManager fs,
      String tableName, String upgradeProperty); }
Upgrader9to10 implements Upgrader { public static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName, String upgradeProperty) { try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY); BatchWriter writer = c.createBatchWriter(tableName)) { scanner.fetchColumnFamily(DataFileColumnFamily.NAME); for (Entry<Key,Value> entry : scanner) { Key key = entry.getKey(); String metaEntry = key.getColumnQualifier().toString(); if (!metaEntry.contains(":")) { if (upgradeProperty == null || upgradeProperty.isBlank()) { throw new IllegalArgumentException( "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey()); } Path relPath = resolveRelativePath(metaEntry, key); Path absPath = new Path(upgradeProperty, relPath); if (fs.exists(absPath)) { log.debug("Changing Tablet File path from {} to {}", metaEntry, absPath); Mutation m = new Mutation(key.getRow()); m.at().family(key.getColumnFamily()).qualifier(absPath.toString()) .visibility(key.getColumnVisibility()).put(entry.getValue()); m.at().family(key.getColumnFamily()).qualifier(key.getColumnQualifierData().toArray()) .visibility(key.getColumnVisibility()).delete(); writer.addMutation(m); } else { throw new IllegalArgumentException( "Relative Tablet file " + relPath + " not found at " + absPath); } } } } catch (MutationsRejectedException | TableNotFoundException e) { throw new IllegalStateException(e); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }  @Override void upgradeZookeeper(ServerContext ctx); @Override void upgradeRoot(ServerContext ctx); @Override void upgradeMetadata(ServerContext ctx); void upgradeFileDeletes(ServerContext ctx, Ample.DataLevel level); void upgradeDirColumns(ServerContext ctx, Ample.DataLevel level); static String upgradeDirColumn(String dir); static void upgradeRelativePaths(ServerContext ctx, Ample.DataLevel level); static void replaceRelativePaths(AccumuloClient c, VolumeManager fs, String tableName,
      String upgradeProperty); static boolean checkForRelativePaths(AccumuloClient client, VolumeManager fs,
      String tableName, String upgradeProperty); static final String ZROOT_TABLET_LOCATION; static final String ZROOT_TABLET_FUTURE_LOCATION; static final String ZROOT_TABLET_LAST_LOCATION; static final String ZROOT_TABLET_WALOGS; static final String ZROOT_TABLET_CURRENT_LOGS; static final String ZROOT_TABLET_PATH; static final Value UPGRADED; static final String OLD_DELETE_PREFIX; static final long CANDIDATE_BATCH_SIZE; }