public void deleteFamilyFromFS(HRegionInfo region, byte[] familyName) throws IOException { // archive family store files Path tableDir = new Path(rootdir, region.getTableNameAsString()); HFileArchiver.archiveFamily(fs, conf, region, tableDir, familyName); // delete the family folder Path familyDir = new Path(tableDir, new Path(region.getEncodedName(), Bytes.toString(familyName))); if (fs.delete(familyDir, true) == false) { throw new IOException("Could not delete family " + Bytes.toString(familyName) + " from FileSystem for region " + region.getRegionNameAsString() + "(" + region.getEncodedName() + ")"); } }
/** * Remove the region family from disk, archiving the store files. * * @param familyName Column Family Name * @throws IOException if an error occours during the archiving */ public void deleteFamily(final String familyName) throws IOException { // archive family store files HFileArchiver.archiveFamily(fs, conf, regionInfo, tableDir, Bytes.toBytes(familyName)); // delete the family folder Path familyDir = getStoreDir(familyName); if (fs.exists(familyDir) && !deleteDir(familyDir)) throw new IOException( "Could not delete family " + familyName + " from FileSystem for region " + regionInfo.getRegionNameAsString() + "(" + regionInfo.getEncodedName() + ")"); }
/** * Restore region by removing files not in the snapshot and adding the missing ones from the * snapshot. */ private void restoreRegion(HRegionInfo regionInfo) throws IOException { Path snapshotRegionDir = new Path(snapshotDir, regionInfo.getEncodedName()); Map<String, List<String>> snapshotFiles = SnapshotReferenceUtil.getRegionHFileReferences(fs, snapshotRegionDir); Path regionDir = new Path(tableDir, regionInfo.getEncodedName()); String tableName = tableDesc.getNameAsString(); // Restore families present in the table for (Path familyDir : FSUtils.getFamilyDirs(fs, regionDir)) { byte[] family = Bytes.toBytes(familyDir.getName()); Set<String> familyFiles = getTableRegionFamilyFiles(familyDir); List<String> snapshotFamilyFiles = snapshotFiles.remove(familyDir.getName()); if (snapshotFamilyFiles != null) { List<String> hfilesToAdd = new LinkedList<String>(); for (String hfileName : snapshotFamilyFiles) { if (familyFiles.contains(hfileName)) { // HFile already present familyFiles.remove(hfileName); } else { // HFile missing hfilesToAdd.add(hfileName); } } // Restore Missing files for (String hfileName : hfilesToAdd) { LOG.trace( "Adding HFileLink " + hfileName + " to region=" + regionInfo.getEncodedName() + " table=" + tableName); restoreStoreFile(familyDir, regionInfo, hfileName); } // Remove hfiles not present in the snapshot for (String hfileName : familyFiles) { Path hfile = new Path(familyDir, hfileName); LOG.trace( "Removing hfile=" + hfile + " from region=" + regionInfo.getEncodedName() + " table=" + tableName); HFileArchiver.archiveStoreFile(fs, regionInfo, conf, tableDir, family, hfile); } } else { // Family doesn't exists in the snapshot LOG.trace( "Removing family=" + Bytes.toString(family) + " from region=" + regionInfo.getEncodedName() + " table=" + tableName); HFileArchiver.archiveFamily(fs, conf, regionInfo, tableDir, family); fs.delete(familyDir, true); } } // Add families not present in the table for (Map.Entry<String, List<String>> familyEntry : snapshotFiles.entrySet()) { Path familyDir = new Path(regionDir, familyEntry.getKey()); if (!fs.mkdirs(familyDir)) { throw new IOException("Unable to create familyDir=" + familyDir); } for (String hfileName : familyEntry.getValue()) { LOG.trace("Adding HFileLink " + hfileName + " to table=" + tableName); restoreStoreFile(familyDir, regionInfo, hfileName); } } }