|  | 
| 20 | 20 | 
 | 
| 21 | 21 | import java.io.IOException; | 
| 22 | 22 | import java.util.ArrayList; | 
| 23 |  | -import java.util.Arrays; | 
| 24 | 23 | import java.util.List; | 
| 25 |  | -import java.util.stream.Collectors; | 
| 26 |  | -import org.apache.hadoop.fs.FileStatus; | 
| 27 | 24 | import org.apache.hadoop.fs.FileSystem; | 
| 28 | 25 | import org.apache.hadoop.fs.Path; | 
| 29 | 26 | import org.apache.hadoop.hbase.MetaTableAccessor; | 
|  | 
| 52 | 49 | import org.slf4j.Logger; | 
| 53 | 50 | import org.slf4j.LoggerFactory; | 
| 54 | 51 | 
 | 
|  | 52 | +import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils; | 
|  | 53 | + | 
| 55 | 54 | import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; | 
| 56 | 55 | import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; | 
| 57 | 56 | import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos; | 
| 58 | 57 | import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.DeleteTableState; | 
| 59 |  | -import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils; | 
| 60 | 58 | 
 | 
| 61 | 59 | @InterfaceAudience.Private | 
| 62 | 60 | public class DeleteTableProcedure | 
| @@ -278,92 +276,59 @@ protected static void deleteFromFs(final MasterProcedureEnv env, | 
| 278 | 276 |       final boolean archive) throws IOException { | 
| 279 | 277 |     final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem(); | 
| 280 | 278 |     final FileSystem fs = mfs.getFileSystem(); | 
| 281 |  | -    final Path tempdir = mfs.getTempDir(); | 
| 282 | 279 | 
 | 
| 283 | 280 |     final Path tableDir = CommonFSUtils.getTableDir(mfs.getRootDir(), tableName); | 
| 284 |  | -    final Path tempTableDir = CommonFSUtils.getTableDir(tempdir, tableName); | 
| 285 | 281 | 
 | 
| 286 | 282 |     if (fs.exists(tableDir)) { | 
| 287 |  | -      // Ensure temp exists | 
| 288 |  | -      if (!fs.exists(tempdir) && !fs.mkdirs(tempdir)) { | 
| 289 |  | -        throw new IOException("HBase temp directory '" + tempdir + "' creation failure."); | 
| 290 |  | -      } | 
| 291 |  | - | 
| 292 |  | -      // Ensure parent exists | 
| 293 |  | -      if (!fs.exists(tempTableDir.getParent()) && !fs.mkdirs(tempTableDir.getParent())) { | 
| 294 |  | -        throw new IOException("HBase temp directory '" + tempdir + "' creation failure."); | 
|  | 283 | +      // Archive regions from FS (temp directory) | 
|  | 284 | +      if (archive) { | 
|  | 285 | +        List<Path> regionDirList = new ArrayList<>(); | 
|  | 286 | +        for (RegionInfo region : regions) { | 
|  | 287 | +          if (RegionReplicaUtil.isDefaultReplica(region)) { | 
|  | 288 | +            regionDirList.add(FSUtils.getRegionDirFromTableDir(tableDir, region)); | 
|  | 289 | +            List<RegionInfo> mergeRegions = MetaTableAccessor | 
|  | 290 | +              .getMergeRegions(env.getMasterServices().getConnection(), region.getRegionName()); | 
|  | 291 | +            if (!CollectionUtils.isEmpty(mergeRegions)) { | 
|  | 292 | +              mergeRegions.stream().forEach( | 
|  | 293 | +                r -> regionDirList.add(FSUtils.getRegionDirFromTableDir(tableDir, r))); | 
|  | 294 | +            } | 
|  | 295 | +          } | 
|  | 296 | +        } | 
|  | 297 | +        HFileArchiver | 
|  | 298 | +          .archiveRegions(env.getMasterConfiguration(), fs, mfs.getRootDir(), tableDir, | 
|  | 299 | +            regionDirList); | 
|  | 300 | +        if (!regionDirList.isEmpty()) { | 
|  | 301 | +          LOG.debug("Archived {} regions", tableName); | 
|  | 302 | +        } | 
| 295 | 303 |       } | 
| 296 | 304 | 
 | 
| 297 |  | -      if (fs.exists(tempTableDir)) { | 
| 298 |  | -        // TODO | 
| 299 |  | -        // what's in this dir? something old? probably something manual from the user... | 
| 300 |  | -        // let's get rid of this stuff... | 
| 301 |  | -        FileStatus[] files = fs.listStatus(tempTableDir); | 
| 302 |  | -        if (files != null && files.length > 0) { | 
| 303 |  | -          List<Path> regionDirList = Arrays.stream(files) | 
| 304 |  | -            .filter(FileStatus::isDirectory) | 
| 305 |  | -            .map(FileStatus::getPath) | 
| 306 |  | -            .collect(Collectors.toList()); | 
| 307 |  | -          HFileArchiver.archiveRegions(env.getMasterConfiguration(), fs, mfs.getRootDir(), | 
| 308 |  | -            tempTableDir, regionDirList); | 
| 309 |  | -        } | 
| 310 |  | -        fs.delete(tempTableDir, true); | 
|  | 305 | +      // Archive mob data | 
|  | 306 | +      Path mobTableDir = | 
|  | 307 | +        CommonFSUtils.getTableDir(new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME), tableName); | 
|  | 308 | +      Path regionDir = new Path(mobTableDir, MobUtils.getMobRegionInfo(tableName).getEncodedName()); | 
|  | 309 | +      if (fs.exists(regionDir)) { | 
|  | 310 | +        HFileArchiver.archiveRegion(fs, mfs.getRootDir(), mobTableDir, regionDir); | 
| 311 | 311 |       } | 
| 312 | 312 | 
 | 
| 313 |  | -      // Move the table in /hbase/.tmp | 
| 314 |  | -      if (!fs.rename(tableDir, tempTableDir)) { | 
| 315 |  | -        throw new IOException("Unable to move '" + tableDir + "' to temp '" + tempTableDir + "'"); | 
|  | 313 | +      // Delete table directory from FS | 
|  | 314 | +      if (!fs.delete(tableDir, true) && fs.exists(tableDir)) { | 
|  | 315 | +        throw new IOException("Couldn't delete " + tableDir); | 
| 316 | 316 |       } | 
| 317 |  | -    } | 
| 318 | 317 | 
 | 
| 319 |  | -    // Archive regions from FS (temp directory) | 
| 320 |  | -    if (archive) { | 
| 321 |  | -      List<Path> regionDirList = new ArrayList<>(); | 
| 322 |  | -      for (RegionInfo region : regions) { | 
| 323 |  | -        if (RegionReplicaUtil.isDefaultReplica(region)) { | 
| 324 |  | -          regionDirList.add(FSUtils.getRegionDirFromTableDir(tempTableDir, region)); | 
| 325 |  | -          List<RegionInfo> mergeRegions = MetaTableAccessor | 
| 326 |  | -              .getMergeRegions(env.getMasterServices().getConnection(), region.getRegionName()); | 
| 327 |  | -          if (!CollectionUtils.isEmpty(mergeRegions)) { | 
| 328 |  | -            mergeRegions.stream() | 
| 329 |  | -                .forEach(r -> regionDirList.add(FSUtils.getRegionDirFromTableDir(tempTableDir, r))); | 
| 330 |  | -          } | 
|  | 318 | +      // Delete the table directory where the mob files are saved | 
|  | 319 | +      if (mobTableDir != null && fs.exists(mobTableDir)) { | 
|  | 320 | +        if (!fs.delete(mobTableDir, true)) { | 
|  | 321 | +          throw new IOException("Couldn't delete mob dir " + mobTableDir); | 
| 331 | 322 |         } | 
| 332 | 323 |       } | 
| 333 |  | -      HFileArchiver.archiveRegions(env.getMasterConfiguration(), fs, mfs.getRootDir(), tempTableDir, | 
| 334 |  | -        regionDirList); | 
| 335 |  | -      if (!regionDirList.isEmpty()) { | 
| 336 |  | -        LOG.debug("Archived {} regions", tableName); | 
| 337 |  | -      } | 
| 338 |  | -    } | 
| 339 |  | - | 
| 340 |  | -    // Archive mob data | 
| 341 |  | -    Path mobTableDir = | 
| 342 |  | -      CommonFSUtils.getTableDir(new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME), tableName); | 
| 343 |  | -    Path regionDir = | 
| 344 |  | -            new Path(mobTableDir, MobUtils.getMobRegionInfo(tableName).getEncodedName()); | 
| 345 |  | -    if (fs.exists(regionDir)) { | 
| 346 |  | -      HFileArchiver.archiveRegion(fs, mfs.getRootDir(), mobTableDir, regionDir); | 
| 347 |  | -    } | 
| 348 |  | - | 
| 349 |  | -    // Delete table directory from FS (temp directory) | 
| 350 |  | -    if (!fs.delete(tempTableDir, true) && fs.exists(tempTableDir)) { | 
| 351 |  | -      throw new IOException("Couldn't delete " + tempTableDir); | 
| 352 |  | -    } | 
| 353 | 324 | 
 | 
| 354 |  | -    // Delete the table directory where the mob files are saved | 
| 355 |  | -    if (mobTableDir != null && fs.exists(mobTableDir)) { | 
| 356 |  | -      if (!fs.delete(mobTableDir, true)) { | 
| 357 |  | -        throw new IOException("Couldn't delete mob dir " + mobTableDir); | 
|  | 325 | +      // Delete the directory on wal filesystem | 
|  | 326 | +      FileSystem walFs = mfs.getWALFileSystem(); | 
|  | 327 | +      Path tableWALDir = CommonFSUtils.getWALTableDir(env.getMasterConfiguration(), tableName); | 
|  | 328 | +      if (walFs.exists(tableWALDir) && !walFs.delete(tableWALDir, true)) { | 
|  | 329 | +        throw new IOException("Couldn't delete table dir on wal filesystem" + tableWALDir); | 
| 358 | 330 |       } | 
| 359 | 331 |     } | 
| 360 |  | - | 
| 361 |  | -    // Delete the directory on wal filesystem | 
| 362 |  | -    FileSystem walFs = mfs.getWALFileSystem(); | 
| 363 |  | -    Path tableWALDir = CommonFSUtils.getWALTableDir(env.getMasterConfiguration(), tableName); | 
| 364 |  | -    if (walFs.exists(tableWALDir) && !walFs.delete(tableWALDir, true)) { | 
| 365 |  | -      throw new IOException("Couldn't delete table dir on wal filesystem" + tableWALDir); | 
| 366 |  | -    } | 
| 367 | 332 |   } | 
| 368 | 333 | 
 | 
| 369 | 334 |   /** | 
|  | 
0 commit comments