Skip to content

Commit ea04de3

Browse files
author
Prathyusha Garre
committed
HBASE-29109 Downgrade to shared lock at the time of prepare snapshot itself
1 parent 279abdd commit ea04de3

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public abstract class TakeSnapshotHandler extends EventHandler
8888
protected final Path workingDir;
8989
private final MasterSnapshotVerifier verifier;
9090
protected final ForeignExceptionDispatcher monitor;
91-
private final LockManager.MasterLock tableLock;
91+
private LockManager.MasterLock tableLock;
9292
protected final MonitoredTask status;
9393
protected final TableName snapshotTable;
9494
protected final SnapshotManifest snapshotManifest;
@@ -167,16 +167,29 @@ public TakeSnapshotHandler prepare() throws Exception {
167167
if (this.tableLock.tryAcquire(this.lockAcquireTimeoutMs)) {
168168
try {
169169
this.htd = loadTableDescriptor(); // check that .tableinfo is present
170+
if (downgradeToSharedTableLock()) {
171+
// release the exclusive lock and hold the shared lock instead
172+
this.tableLock.release();
173+
this.tableLock = master.getLockManager().createMasterLock(snapshotTable, LockType.SHARED,
174+
this.getClass().getName() + ": take snapshot " + snapshot.getName());
175+
if (!this.tableLock.tryAcquire(this.lockAcquireTimeoutMs)) {
176+
throwLockNotAcquiredException();
177+
}
178+
}
170179
} catch (Exception e) {
171180
this.tableLock.release();
172181
throw e;
173182
}
174183
} else {
175-
LOG.error("Master lock could not be acquired in {} ms", lockAcquireTimeoutMs);
176-
throw new DoNotRetryIOException("Master lock could not be acquired");
184+
throwLockNotAcquiredException();
177185
}
178186
return this;
179187
}
188+
189+
private void throwLockNotAcquiredException() throws DoNotRetryIOException {
190+
LOG.error("Master lock could not be acquired in {} ms", lockAcquireTimeoutMs);
191+
throw new DoNotRetryIOException("Master lock could not be acquired");
192+
}
180193

181194
/**
182195
* Execute the core common portions of taking a snapshot. The {@link #snapshotRegions(List)} call
@@ -192,18 +205,6 @@ public void process() {
192205
MasterLock tableLockToRelease = this.tableLock;
193206
status.setStatus(msg);
194207
try {
195-
if (downgradeToSharedTableLock()) {
196-
// release the exclusive lock and hold the shared lock instead
197-
tableLockToRelease = master.getLockManager().createMasterLock(snapshotTable,
198-
LockType.SHARED, this.getClass().getName() + ": take snapshot " + snapshot.getName());
199-
tableLock.release();
200-
boolean isTableLockAcquired = tableLockToRelease.tryAcquire(this.lockAcquireTimeoutMs);
201-
if (!isTableLockAcquired) {
202-
LOG.error("Could not acquire shared lock on table {} in {} ms", snapshotTable,
203-
lockAcquireTimeoutMs);
204-
throw new IOException("Could not acquire shared lock on table " + snapshotTable);
205-
}
206-
}
207208
// If regions move after this meta scan, the region specific snapshot should fail, triggering
208209
// an external exception that gets captured here.
209210

0 commit comments

Comments
 (0)