@Test public void testExclusiveOnlyMode() throws Throwable { final long exclusiveOnlyDurationMs = 30 * 1000; ServerConfiguration.set(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION, exclusiveOnlyDurationMs); StateLockManager stateLockManager = new StateLockManager(); stateLockManager.mastersStartedCallback(); for (int i = 0; i < 10; i++) { StateLockingThread sharedHolderThread = new StateLockingThread(stateLockManager, false); sharedHolderThread.start(); mExpected.expect(IllegalStateException.class); sharedHolderThread.waitUntilStateLockAcquired(); } StateLockingThread exclusiveHolderThread = new StateLockingThread(stateLockManager, true); exclusiveHolderThread.start(); exclusiveHolderThread.waitUntilStateLockAcquired(); exclusiveHolderThread.unlockExit(); exclusiveHolderThread.join(); }
public void mastersStartedCallback() { if (mExclusiveOnlyDeadlineMs == -1) { long exclusiveOnlyDurationMs = ServerConfiguration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION); mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs; if (exclusiveOnlyDurationMs > 0) { LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}", exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString()); } } }
StateLockManager { public void mastersStartedCallback() { if (mExclusiveOnlyDeadlineMs == -1) { long exclusiveOnlyDurationMs = ServerConfiguration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION); mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs; if (exclusiveOnlyDurationMs > 0) { LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}", exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString()); } } } }
StateLockManager { public void mastersStartedCallback() { if (mExclusiveOnlyDeadlineMs == -1) { long exclusiveOnlyDurationMs = ServerConfiguration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION); mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs; if (exclusiveOnlyDurationMs > 0) { LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}", exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString()); } } } StateLockManager(); }
StateLockManager { public void mastersStartedCallback() { if (mExclusiveOnlyDeadlineMs == -1) { long exclusiveOnlyDurationMs = ServerConfiguration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION); mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs; if (exclusiveOnlyDurationMs > 0) { LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}", exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString()); } } } StateLockManager(); void mastersStartedCallback(); LockResource lockShared(); LockResource lockExclusive(StateLockOptions lockOptions); boolean interruptCycleTicking(); }
StateLockManager { public void mastersStartedCallback() { if (mExclusiveOnlyDeadlineMs == -1) { long exclusiveOnlyDurationMs = ServerConfiguration.getMs(PropertyKey.MASTER_BACKUP_STATE_LOCK_EXCLUSIVE_DURATION); mExclusiveOnlyDeadlineMs = System.currentTimeMillis() + exclusiveOnlyDurationMs; if (exclusiveOnlyDurationMs > 0) { LOG.info("State-lock will remain in exclusive-only mode for {}ms until {}", exclusiveOnlyDurationMs, new Date(mExclusiveOnlyDeadlineMs).toString()); } } } StateLockManager(); void mastersStartedCallback(); LockResource lockShared(); LockResource lockExclusive(StateLockOptions lockOptions); boolean interruptCycleTicking();  }