Skip to content

Commit ee2f823

Browse files
sguggilambusbey
authored andcommitted
HBASE-24740 Enable journal logging for HBase snapshot operation (apache#2104)
Signed-off-by: Bharath Vissapragada <[email protected]> (cherry picked from commit 430602a) (cherry picked from commit 4e5ec22) Change-Id: Ibe837047e9f93c608ec13972a9f6b1ac3622c92f
1 parent 3b642d0 commit ee2f823

4 files changed

Lines changed: 43 additions & 10 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,26 @@ private void takeSnapshotInternal(SnapshotDescription snapshot) throws IOExcepti
651651
TableName snapshotTable = TableName.valueOf(snapshot.getTable());
652652
if (master.getTableStateManager().isTableState(snapshotTable,
653653
TableState.State.ENABLED)) {
654-
LOG.debug("Table enabled, starting distributed snapshot.");
654+
if (LOG.isDebugEnabled()) {
655+
LOG.debug("Table enabled, starting distributed snapshots for {}",
656+
ClientSnapshotDescriptionUtils.toString(snapshot));
657+
}
655658
snapshotEnabledTable(snapshot);
656-
LOG.debug("Started snapshot: " + ClientSnapshotDescriptionUtils.toString(snapshot));
659+
if (LOG.isDebugEnabled()) {
660+
LOG.debug("Started snapshot: {}", ClientSnapshotDescriptionUtils.toString(snapshot));
661+
}
657662
}
658663
// For disabled table, snapshot is created by the master
659664
else if (master.getTableStateManager().isTableState(snapshotTable,
660665
TableState.State.DISABLED)) {
661-
LOG.debug("Table is disabled, running snapshot entirely on master.");
666+
if (LOG.isDebugEnabled()) {
667+
LOG.debug("Table is disabled, running snapshot entirely on master for {}",
668+
ClientSnapshotDescriptionUtils.toString(snapshot));
669+
}
662670
snapshotDisabledTable(snapshot);
663-
LOG.debug("Started snapshot: " + ClientSnapshotDescriptionUtils.toString(snapshot));
671+
if (LOG.isDebugEnabled()) {
672+
LOG.debug("Started snapshot: {}", ClientSnapshotDescriptionUtils.toString(snapshot));
673+
}
664674
} else {
665675
LOG.error("Can't snapshot table '" + snapshot.getTable()
666676
+ "', isn't open or closed, we don't know what to do!");

hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/TakeSnapshotHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public TakeSnapshotHandler(SnapshotDescription snapshot, final MasterServices ma
125125
this.snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir);
126126
this.workingDirFs = this.workingDir.getFileSystem(this.conf);
127127
this.monitor = new ForeignExceptionDispatcher(snapshot.getName());
128-
this.snapshotManifest = SnapshotManifest.create(conf, rootFs, workingDir, snapshot, monitor);
129128

130129
this.tableLock = master.getLockManager().createMasterLock(
131130
snapshotTable, LockType.EXCLUSIVE,
@@ -136,6 +135,9 @@ public TakeSnapshotHandler(SnapshotDescription snapshot, final MasterServices ma
136135
// update the running tasks
137136
this.status = TaskMonitor.get().createStatus(
138137
"Taking " + snapshot.getType() + " snapshot on table: " + snapshotTable);
138+
this.status.enableStatusJournal(true);
139+
this.snapshotManifest =
140+
SnapshotManifest.create(conf, rootFs, workingDir, snapshot, monitor, status);
139141
}
140142

141143
private TableDescriptor loadTableDescriptor()
@@ -249,6 +251,9 @@ public void process() {
249251
} catch (IOException e) {
250252
LOG.error("Couldn't delete snapshot working directory:" + workingDir);
251253
}
254+
if (LOG.isDebugEnabled()) {
255+
LOG.debug("Table snapshot journal : \n" + status.prettyPrintJournal());
256+
}
252257
tableLockToRelease.release();
253258
}
254259
}

hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/MonitoredTaskImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void enableStatusJournal(boolean includeCurrentStatus) {
259259
if (journal == null) {
260260
journal = new ArrayList<StatusJournalEntry>();
261261
}
262-
if (includeCurrentStatus) {
262+
if (includeCurrentStatus && status != null) {
263263
journal.add(new StatusJournalEntryImpl(status, statusTime));
264264
}
265265
}

hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotManifest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.hadoop.hbase.client.TableDescriptor;
4040
import org.apache.hadoop.hbase.errorhandling.ForeignExceptionSnare;
4141
import org.apache.hadoop.hbase.mob.MobUtils;
42+
import org.apache.hadoop.hbase.monitoring.MonitoredTask;
4243
import org.apache.hadoop.hbase.regionserver.HRegion;
4344
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
4445
import org.apache.hadoop.hbase.regionserver.HStore;
@@ -84,6 +85,7 @@ public final class SnapshotManifest {
8485
private final FileSystem rootFs;
8586
private final FileSystem workingDirFs;
8687
private int manifestSizeLimit;
88+
private final MonitoredTask statusTask;
8789

8890
/**
8991
*
@@ -97,12 +99,13 @@ public final class SnapshotManifest {
9799
*/
98100
private SnapshotManifest(final Configuration conf, final FileSystem rootFs,
99101
final Path workingDir, final SnapshotDescription desc,
100-
final ForeignExceptionSnare monitor) throws IOException {
102+
final ForeignExceptionSnare monitor, final MonitoredTask statusTask) throws IOException {
101103
this.monitor = monitor;
102104
this.desc = desc;
103105
this.workingDir = workingDir;
104106
this.conf = conf;
105107
this.rootFs = rootFs;
108+
this.statusTask = statusTask;
106109
this.workingDirFs = this.workingDir.getFileSystem(this.conf);
107110
this.manifestSizeLimit = conf.getInt(SNAPSHOT_MANIFEST_SIZE_LIMIT_CONF_KEY, 64 * 1024 * 1024);
108111
}
@@ -123,7 +126,14 @@ private SnapshotManifest(final Configuration conf, final FileSystem rootFs,
123126
public static SnapshotManifest create(final Configuration conf, final FileSystem fs,
124127
final Path workingDir, final SnapshotDescription desc,
125128
final ForeignExceptionSnare monitor) throws IOException {
126-
return new SnapshotManifest(conf, fs, workingDir, desc, monitor);
129+
return create(conf, fs, workingDir, desc, monitor, null);
130+
131+
}
132+
133+
public static SnapshotManifest create(final Configuration conf, final FileSystem fs,
134+
final Path workingDir, final SnapshotDescription desc, final ForeignExceptionSnare monitor,
135+
final MonitoredTask statusTask) throws IOException {
136+
return new SnapshotManifest(conf, fs, workingDir, desc, monitor, statusTask);
127137

128138
}
129139

@@ -138,7 +148,7 @@ public static SnapshotManifest create(final Configuration conf, final FileSystem
138148
*/
139149
public static SnapshotManifest open(final Configuration conf, final FileSystem fs,
140150
final Path workingDir, final SnapshotDescription desc) throws IOException {
141-
SnapshotManifest manifest = new SnapshotManifest(conf, fs, workingDir, desc, null);
151+
SnapshotManifest manifest = new SnapshotManifest(conf, fs, workingDir, desc, null, null);
142152
manifest.load();
143153
return manifest;
144154
}
@@ -455,6 +465,12 @@ public List<SnapshotRegionManifest> getRegionManifests() {
455465
return this.regionManifests;
456466
}
457467

468+
private void setStatusMsg(String msg) {
469+
if (this.statusTask != null) {
470+
statusTask.setStatus(msg);
471+
}
472+
}
473+
458474
/**
459475
* Get all the Region Manifest from the snapshot.
460476
* This is an helper to get a map with the region encoded name
@@ -478,7 +494,7 @@ public void consolidate() throws IOException {
478494
new FSTableDescriptors(conf, workingDirFs, rootDir)
479495
.createTableDescriptorForTableDirectory(workingDir, htd, false);
480496
} else {
481-
LOG.debug("Convert to Single Snapshot Manifest");
497+
LOG.debug("Convert to Single Snapshot Manifest for {}", this.desc.getName());
482498
convertToV2SingleManifest();
483499
}
484500
}
@@ -491,6 +507,7 @@ private void convertToV2SingleManifest() throws IOException {
491507
// Try to load v1 and v2 regions
492508
List<SnapshotRegionManifest> v1Regions, v2Regions;
493509
ThreadPoolExecutor tpool = createExecutor("SnapshotManifestLoader");
510+
setStatusMsg("Loading Region manifests for " + this.desc.getName());
494511
try {
495512
v1Regions = SnapshotManifestV1.loadRegionManifests(conf, tpool, workingDirFs,
496513
workingDir, desc);
@@ -514,6 +531,7 @@ private void convertToV2SingleManifest() throws IOException {
514531
// Once the data-manifest is written, the snapshot can be considered complete.
515532
// Currently snapshots are written in a "temporary" directory and later
516533
// moved to the "complated" snapshot directory.
534+
setStatusMsg("Writing data manifest for " + this.desc.getName());
517535
SnapshotDataManifest dataManifest = dataManifestBuilder.build();
518536
writeDataManifest(dataManifest);
519537
this.regionManifests = dataManifest.getRegionManifestsList();

0 commit comments

Comments
 (0)