You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/12/17 20:51:58 UTC

[GitHub] [accumulo] keith-turner commented on a change in pull request #1461: Add code to replace relative paths on upgrade. #1397

keith-turner commented on a change in pull request #1461: Add code to replace relative paths on upgrade. #1397
URL: https://github.com/apache/accumulo/pull/1461#discussion_r359011592
 
 

 ##########
 File path: server/master/src/main/java/org/apache/accumulo/master/upgrade/Upgrader9to10.java
 ##########
 @@ -500,4 +506,127 @@ public void upgradeDirColumns(ServerContext ctx, Ample.DataLevel level) {
   public static String upgradeDirColumn(String dir) {
     return new Path(dir).getName();
   }
+
+  /**
+   * Remove all file entries containing relative paths and replace them with absolute URI paths.
+   */
+  public static void upgradeRelativePaths(ServerContext ctx, Ample.DataLevel level) {
+    String tableName = level.metaTable();
+    AccumuloClient c = ctx;
+    Configuration hadoopConf = ctx.getHadoopConf();
+    String volumeProp = ctx.getConfiguration().get(Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE);
+
+    // first pass check for relative paths - if any, check existence of the file path
+    // constructed from the upgrade property + relative path
+    if (!checkForRelativePaths(c, hadoopConf, tableName, volumeProp)) {
+      log.info("No relative paths found in {} during upgrade.", tableName);
+      return;
+    } else {
+      log.info("Relative Tablet File paths exist in {}, replacing with absolute using {}",
+          tableName, volumeProp);
+    }
+
+    // second pass, create atomic mutations to replace the relative path
+    replaceRelativePaths(c, hadoopConf, tableName, volumeProp);
+  }
+
+  /**
+   * Replace relative paths but only if the constructed absolute path exists on FileSystem
+   */
+  public static void replaceRelativePaths(AccumuloClient c, Configuration hadoopConf,
+      String tableName, String volumeProp) {
+    try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY);
+        BatchWriter writer = c.createBatchWriter(tableName)) {
+      FileSystem fs = FileSystem.get(hadoopConf);
+
+      scanner.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);
+      for (Entry<Key,Value> entry : scanner) {
+        Key key = entry.getKey();
+        Text filePath = key.getColumnQualifier();
+        if (!filePath.toString().contains(":")) {
+          // found relative paths so get the property used to build the absolute paths
+          if (volumeProp == null || volumeProp.isBlank()) {
+            throw new IllegalArgumentException(
+                "Missing required property " + Property.INSTANCE_VOLUMES_UPGRADE_RELATIVE.getKey());
+          }
+          String metaEntry = key.getColumnQualifier().toString();
+          Path relPath = resolveRelativePath(metaEntry, key);
+          Path absPath = new Path(volumeProp, relPath);
+          if (fs.exists(absPath)) {
 
 Review comment:
   Why do existence check again?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services