Skip to content

Commit

Permalink
HBASE-7583 [snapshots] Fixes and cleanups (Matteo Bertozzi)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445853 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jmhsieh committed Feb 13, 2013
1 parent 8a67938 commit f70ed5a
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ private HFileArchiver() {
public static void archiveRegion(Configuration conf, FileSystem fs, HRegionInfo info)
throws IOException {
Path rootDir = FSUtils.getRootDir(conf);
archiveRegion(conf, fs, rootDir, HTableDescriptor.getTableDir(rootDir, info.getTableName()),
archiveRegion(fs, rootDir, HTableDescriptor.getTableDir(rootDir, info.getTableName()),
HRegion.getRegionDir(rootDir, info));
}


/**
* Remove an entire region from the table directory via archiving the region's hfiles.
* @param conf the configuration to use
* @param fs {@link FileSystem} from which to remove the region
* @param rootdir {@link Path} to the root directory where hbase files are stored (for building
* the archive path)
Expand All @@ -87,8 +85,7 @@ public static void archiveRegion(Configuration conf, FileSystem fs, HRegionInfo
* operations could not complete.
* @throws IOException if the request cannot be completed
*/
public static boolean archiveRegion(Configuration conf, FileSystem fs,
Path rootdir, Path tableDir, Path regionDir)
public static boolean archiveRegion(FileSystem fs, Path rootdir, Path tableDir, Path regionDir)
throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("ARCHIVING region " + regionDir.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public HFileLink(final Path rootDir, final Path archiveDir, final Path path) {
this.tempPath = new Path(new Path(rootDir, HConstants.HBASE_TEMP_DIRECTORY), hfilePath);
this.originPath = new Path(rootDir, hfilePath);
this.archivePath = new Path(archiveDir, hfilePath);
setLocations(originPath, archivePath, this.tempPath);
setLocations(originPath, tempPath, archivePath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private void checkTempDir(final Path tmpdir, final Configuration c, final FileSy
// if not the cleaner will take care of them.
for (Path tabledir: FSUtils.getTableDirs(fs, tmpdir)) {
for (Path regiondir: FSUtils.getRegionDirs(fs, tabledir)) {
HFileArchiver.archiveRegion(c, fs, this.rootdir, tabledir, regiondir);
HFileArchiver.archiveRegion(fs, this.rootdir, tabledir, regiondir);
}
}
if (!fs.delete(tmpdir, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ protected void handleTableOperation(List<HRegionInfo> regions)
FileSystem fs = mfs.getFileSystem();
for (HRegionInfo hri: regions) {
LOG.debug("Deleting region " + hri.getRegionNameAsString() + " from FS");
HFileArchiver.archiveRegion(masterServices.getConfiguration(), fs, mfs.getRootDir(),
HFileArchiver.archiveRegion(fs, mfs.getRootDir(),
tempTableDir, new Path(tempTableDir, hri.getEncodedName()));
}

// 7. Delete table from FS (temp directory)
fs.delete(tempTableDir, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ protected List<HRegionInfo> handleCreateHdfsRegions(final Path tableRootDir, fin
RestoreSnapshotHelper.RestoreMetaChanges metaChanges = restoreHelper.restoreHdfsRegions();

// Clone operation should not have stuff to restore or remove
Preconditions.checkArgument(metaChanges.getRegionsToRestore() == null,
Preconditions.checkArgument(!metaChanges.hasRegionsToRestore(),
"A clone should not have regions to restore");
Preconditions.checkArgument(metaChanges.getRegionsToRemove() == null,
Preconditions.checkArgument(!metaChanges.hasRegionsToRemove(),
"A clone should not have regions to remove");

// At this point the clone is complete. Next step is enabling the table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocati
}

// 3. write the table info to disk
LOG.info("Starting to copy tableinfo for offline snapshot:\n" + snapshot);
LOG.info("Starting to copy tableinfo for offline snapshot: " + SnapshotDescriptionUtils.toString(snapshot));
TableInfoCopyTask tableInfo = new TableInfoCopyTask(this.monitor, snapshot, fs,
FSUtils.getRootDir(conf));
tableInfo.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private void verifyRegion(FileSystem fs, Path snapshotDir, HRegionInfo region) t
Path archived = new Path(archivedCfDir, fileName);
if (!fs.exists(file) && !file.equals(archived)) {
throw new CorruptedSnapshotException("Can't find hfile: " + hfile.getPath()
+ " in the real (" + archivedCfDir + ") or archive (" + archivedCfDir
+ " in the real (" + realCfDir + ") or archive (" + archivedCfDir
+ ") directory for the primary table.", snapshot);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {

// 3. Applies changes to .META.
hris.clear();
hris.addAll(metaChanges.getRegionsToAdd());
hris.addAll(metaChanges.getRegionsToRestore());
if (metaChanges.hasRegionsToAdd()) hris.addAll(metaChanges.getRegionsToAdd());
if (metaChanges.hasRegionsToRestore()) hris.addAll(metaChanges.getRegionsToRestore());
List<HRegionInfo> hrisToRemove = metaChanges.getRegionsToRemove();
MetaEditor.mutateRegions(catalogTracker, hrisToRemove, hris);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@ private synchronized void snapshotEnabledTable(SnapshotDescription snapshot)
try {
if (this.master.getMasterFileSystem().getFileSystem().delete(workingDir, true)) {
LOG.warn("Couldn't delete working directory (" + workingDir + " for snapshot:"
+ snapshot);
+ SnapshotDescriptionUtils.toString(snapshot));
}
} catch (IOException e1) {
LOG.warn("Couldn't delete working directory (" + workingDir + " for snapshot:" + snapshot);
LOG.warn("Couldn't delete working directory (" + workingDir + " for snapshot:" +
SnapshotDescriptionUtils.toString(snapshot));
}
// fail the snapshot
throw new SnapshotCreationException("Could not build snapshot handler", e, snapshot);
Expand Down Expand Up @@ -494,7 +495,7 @@ public void takeSnapshot(SnapshotDescription snapshot) throws HBaseSnapshotExcep
else if (assignmentMgr.getZKTable().isDisabledTable(snapshot.getTable())) {
LOG.debug("Table is disabled, running snapshot entirely on master.");
snapshotDisabledTable(snapshot);
LOG.debug("Started snapshot: " + snapshot);
LOG.debug("Started snapshot: " + SnapshotDescriptionUtils.toString(snapshot));
} else {
LOG.error("Can't snapshot table '" + snapshot.getTable()
+ "', isn't open or closed, we don't know what to do!");
Expand Down Expand Up @@ -534,11 +535,12 @@ private synchronized void snapshotDisabledTable(SnapshotDescription snapshot)
Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir);
try {
if (this.master.getMasterFileSystem().getFileSystem().delete(workingDir, true)) {
LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:"
+ snapshot);
LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
SnapshotDescriptionUtils.toString(snapshot));
}
} catch (IOException e1) {
LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" + snapshot);
LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
SnapshotDescriptionUtils.toString(snapshot));
}
// fail the snapshot
throw new SnapshotCreationException("Could not build snapshot handler", e, snapshot);
Expand Down Expand Up @@ -612,7 +614,8 @@ synchronized void cloneSnapshot(final SnapshotDescription snapshot,
this.executorService.submit(handler);
restoreHandlers.put(tableName, handler);
} catch (Exception e) {
String msg = "Couldn't clone the snapshot=" + snapshot + " on table=" + tableName;
String msg = "Couldn't clone the snapshot=" + SnapshotDescriptionUtils.toString(snapshot) +
" on table=" + tableName;
LOG.error(msg, e);
throw new RestoreSnapshotException(msg, e);
}
Expand Down Expand Up @@ -702,7 +705,8 @@ private synchronized void restoreSnapshot(final SnapshotDescription snapshot,
this.executorService.submit(handler);
restoreHandlers.put(hTableDescriptor.getNameAsString(), handler);
} catch (Exception e) {
String msg = "Couldn't restore the snapshot=" + snapshot + " on table=" + tableName;
String msg = "Couldn't restore the snapshot=" + SnapshotDescriptionUtils.toString(snapshot) +
" on table=" + tableName;
LOG.error(msg, e);
throw new RestoreSnapshotException(msg, e);
}
Expand Down Expand Up @@ -751,12 +755,14 @@ public boolean isRestoringTable(final SnapshotDescription snapshot) throws IOExc

// check to see if we are done
if (sentinel.isFinished()) {
LOG.debug("Restore snapshot=" + snapshot + " has completed. Notifying the client.");
LOG.debug("Restore snapshot=" + SnapshotDescriptionUtils.toString(snapshot) +
" has completed. Notifying the client.");
return false;
}

if (LOG.isDebugEnabled()) {
LOG.debug("Sentinel is not yet finished with restoring snapshot=" + snapshot);
LOG.debug("Sentinel is not yet finished with restoring snapshot=" +
SnapshotDescriptionUtils.toString(snapshot));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4306,11 +4306,11 @@ public static HRegion merge(HRegion a, HRegion b)
}

// delete out the 'A' region
HFileArchiver.archiveRegion(a.getBaseConf(), fs,
FSUtils.getRootDir(a.getBaseConf()), a.getTableDir(), a.getRegionDir());
HFileArchiver.archiveRegion(fs, FSUtils.getRootDir(a.getBaseConf()),
a.getTableDir(), a.getRegionDir());
// delete out the 'B' region
HFileArchiver.archiveRegion(a.getBaseConf(), fs,
FSUtils.getRootDir(b.getBaseConf()), b.getTableDir(), b.getRegionDir());
HFileArchiver.archiveRegion(fs, FSUtils.getRootDir(b.getBaseConf()),
b.getTableDir(), b.getRegionDir());

LOG.info("merge completed. New region is " + dstRegion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public static class RestoreMetaChanges {
private List<HRegionInfo> regionsToRemove = null;
private List<HRegionInfo> regionsToAdd = null;

/**
* @return true if there're new regions
*/
public boolean hasRegionsToAdd() {
return this.regionsToAdd != null && this.regionsToAdd.size() > 0;
}

/**
* Returns the list of new regions added during the on-disk restore.
* The caller is responsible to add the regions to META.
Expand All @@ -207,6 +214,13 @@ public List<HRegionInfo> getRegionsToAdd() {
return this.regionsToAdd;
}

/**
* @return true if there're regions to restore
*/
public boolean hasRegionsToRestore() {
return this.regionsToRestore != null && this.regionsToRestore.size() > 0;
}

/**
* Returns the list of 'restored regions' during the on-disk restore.
* The caller is responsible to add the regions to META if not present.
Expand All @@ -216,6 +230,13 @@ public List<HRegionInfo> getRegionsToRestore() {
return this.regionsToRestore;
}

/**
* @return true if there're regions to remove
*/
public boolean hasRegionsToRemove() {
return this.regionsToRemove != null && this.regionsToRemove.size() > 0;
}

/**
* Returns the list of regions removed during the on-disk restore.
* The caller is responsible to remove the regions from META.
Expand Down

0 comments on commit f70ed5a

Please sign in to comment.