@@ -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,17 +167,30 @@ 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 }
180188
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+ }
193+
181194 /**
182195 * Execute the core common portions of taking a snapshot. The {@link #snapshotRegions(List)} call
183196 * should get implemented for each snapshot flavor.
@@ -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