/** * Sweeps the mob files on one column family. It deletes the unused mob files and merges the small * mob files into bigger ones. * * @param tableName The current table name in string format. * @param familyName The column family name. * @return 0 if success, 2 if job aborted with an exception, 3 if unable to start due to other * compaction,4 if mr job was unsuccessful * @throws IOException * @throws InterruptedException * @throws ClassNotFoundException * @throws KeeperException * @throws ServiceException */ int sweepFamily(String tableName, String familyName) throws IOException, InterruptedException, ClassNotFoundException, KeeperException, ServiceException { Configuration conf = getConf(); // make sure the target HBase exists. HBaseAdmin.checkHBaseAvailable(conf); Connection connection = ConnectionFactory.createConnection(getConf()); Admin admin = connection.getAdmin(); try { FileSystem fs = FileSystem.get(conf); TableName tn = TableName.valueOf(tableName); HTableDescriptor htd = admin.getTableDescriptor(tn); HColumnDescriptor family = htd.getFamily(Bytes.toBytes(familyName)); if (family == null || !family.isMobEnabled()) { throw new IOException("Column family " + familyName + " is not a MOB column family"); } SweepJob job = new SweepJob(conf, fs); // Run the sweeping return job.sweep(tn, family); } catch (Exception e) { System.err.println("Job aborted due to exception " + e); return 2; // job failed } finally { try { admin.close(); } catch (IOException e) { System.out.println("Failed to close the HBaseAdmin: " + e.getMessage()); } try { connection.close(); } catch (IOException e) { System.out.println("Failed to close the connection: " + e.getMessage()); } } }
/** * Restore the table descriptor back to pre-add * * @param env MasterProcedureEnv * @throws IOException */ private void restoreTableDescriptor(final MasterProcedureEnv env) throws IOException { HTableDescriptor htd = env.getMasterServices().getTableDescriptors().get(tableName); if (htd.hasFamily(cfDescriptor.getName())) { // Remove the column family from file system and update the table descriptor to // the before-add-column-family-state MasterDDLOperationHelper.deleteColumnFamilyFromFileSystem( env, tableName, getRegionInfoList(env), cfDescriptor.getName(), cfDescriptor.isMobEnabled()); env.getMasterServices().getTableDescriptors().add(unmodifiedHTableDescriptor); // Make sure regions are opened after table descriptor is updated. reOpenAllRegionsIfTableIsOnline(env); } }
public void addMobRegion(HRegionInfo regionInfo, HColumnDescriptor[] hcds) throws IOException { // 0. Get the ManifestBuilder/RegionVisitor RegionVisitor visitor = createRegionVisitor(desc); // 1. dump region meta info into the snapshot directory LOG.debug("Storing mob region '" + regionInfo + "' region-info for snapshot."); Object regionData = visitor.regionOpen(regionInfo); monitor.rethrowException(); // 2. iterate through all the stores in the region LOG.debug("Creating references for mob files"); Path mobRegionPath = MobUtils.getMobRegionPath(conf, regionInfo.getTable()); for (HColumnDescriptor hcd : hcds) { // 2.1. build the snapshot reference for the store if it's a mob store if (!hcd.isMobEnabled()) { continue; } Object familyData = visitor.familyOpen(regionData, hcd.getName()); monitor.rethrowException(); Path storePath = MobUtils.getMobFamilyPath(mobRegionPath, hcd.getNameAsString()); List<StoreFileInfo> storeFiles = getStoreFiles(storePath); if (storeFiles == null) { if (LOG.isDebugEnabled()) { LOG.debug("No mob files under family: " + hcd.getNameAsString()); } continue; } addReferenceFiles(visitor, regionData, familyData, storeFiles, true); visitor.familyClose(regionData, familyData); } visitor.regionClose(regionData); }