@Override public Set<LockToken> refresh(Set<LockToken> lockTokenV2s) throws InterruptedException { return timelockService.refreshLockLeases(lockTokenV2s); } }
private boolean immutableTsLockIsValid() { return !timelockService.refreshLockLeases(ImmutableSet.of(immutableTsLock)).isEmpty(); } }
private void refreshLocks() { try { Set<LockToken> toRefresh = ImmutableSet.copyOf(tokensToRefresh); if (toRefresh.isEmpty()) { return; } Set<LockToken> refreshed = timelockService.refreshLockLeases(toRefresh); tokensToRefresh.removeAll(Sets.difference(toRefresh, refreshed)); } catch (Throwable error) { log.warn("Error while refreshing locks. Trying again on next iteration", error); } }
@Override public Set<LockToken> refreshLockLeases( Set<LockToken> tokens) { return executeWithRecord(() -> timelockService.refreshLockLeases(tokens)); }
@Override public Set<LockToken> refreshLockLeases(Set<LockToken> tokens) { return executeOnTimeLock(() -> delegate.refreshLockLeases(tokens)); }
/** * Refreshes external and commit locks. * @return set of locks that could not be refreshed */ private Set<LockToken> refreshCommitAndImmutableTsLocks(@Nullable LockToken commitLocksToken) { Set<LockToken> toRefresh = Sets.newHashSet(); if (commitLocksToken != null) { toRefresh.add(commitLocksToken); } immutableTimestampLock.ifPresent(toRefresh::add); if (toRefresh.isEmpty()) { return ImmutableSet.of(); } return Sets.difference(toRefresh, timelockService.refreshLockLeases(toRefresh)).immutableCopy(); }
@Test public void refreshDelegates() { timelock.refreshLockLeases(TOKENS); verify(delegate).refreshLockLeases(TOKENS); verifyNoMoreInteractions(refresher); }
@Before public void setUp() { Set<LockToken> lockTokens = ImmutableSet.of(lockToken); when(timelockService.refreshLockLeases(lockTokens)).thenReturn(lockTokens); }
private void invalidateLockTokens() { when(timelockService.refreshLockLeases(anySet())).thenReturn(ImmutableSet.of()); } }
@Test public void stopsRefreshingLockIfItIsNotRefreshed() { when(timelock.refreshLockLeases(TOKENS)).thenReturn(ImmutableSet.of(TOKEN_1)); refresher.registerLock(TOKEN_1); refresher.registerLock(TOKEN_2); tick(); verify(timelock).refreshLockLeases(TOKENS); tick(); verify(timelock).refreshLockLeases(ImmutableSet.of(TOKEN_1)); }
@Test public void doesNotFailIfDelegateThrows() { when(timelock.refreshLockLeases(any())) .thenThrow(new RuntimeException("test")) .thenReturn(ImmutableSet.of(TOKEN_1)); refresher.registerLock(TOKEN_1); tick(); tick(); verify(timelock, times(2)).refreshLockLeases(ImmutableSet.of(TOKEN_1)); }
@Test public void continuesRefreshingLocksThatAreReturned() { when(timelock.refreshLockLeases(TOKENS)).thenReturn(TOKENS); refresher.registerLock(TOKEN_1); refresher.registerLock(TOKEN_2); tick(); tick(); verify(timelock, times(2)).refreshLockLeases(TOKENS); }
@Test public void stopsRefreshingLockAfterItIsUnregistered() { refresher.registerLock(TOKEN_1); refresher.registerLock(TOKEN_2); refresher.unregisterLocks(ImmutableSet.of(TOKEN_2)); tick(); verify(timelock).refreshLockLeases(ImmutableSet.of(TOKEN_1)); }
@Test public void checkImmutableTsLockOnceIfThoroughlySwept_WithoutValidationOnReads() { TimelockService timelockService = spy(new LegacyTimelockService(timestampService, lockService, lockClient)); long transactionTs = timelockService.getFreshTimestamp(); LockImmutableTimestampResponse res = timelockService.lockImmutableTimestamp(IdentifiedTimeLockRequest.create()); SnapshotTransaction transaction = getSnapshotTransactionWith( timelockService, () -> transactionTs, res, PreCommitConditions.NO_OP, false); transaction.get(TABLE_SWEPT_THOROUGH, ImmutableSet.of(TEST_CELL)); transaction.commit(); timelockService.unlock(ImmutableSet.of(res.getLock())); verify(timelockService).refreshLockLeases(ImmutableSet.of(res.getLock())); }
@Test public void checkImmutableTsLockOnceIfThoroughlySwept_WithValidationOnReads() { TimelockService timelockService = spy(new LegacyTimelockService(timestampService, lockService, lockClient)); long transactionTs = timelockService.getFreshTimestamp(); LockImmutableTimestampResponse res = timelockService.lockImmutableTimestamp(IdentifiedTimeLockRequest.create()); SnapshotTransaction transaction = getSnapshotTransactionWith( timelockService, () -> transactionTs, res, PreCommitConditions.NO_OP, true); transaction.get(TABLE_SWEPT_THOROUGH, ImmutableSet.of(TEST_CELL)); transaction.commit(); timelockService.unlock(ImmutableSet.of(res.getLock())); verify(timelockService).refreshLockLeases(ImmutableSet.of(res.getLock())); }
private boolean immutableTsLockIsValid() { return !timelockService.refreshLockLeases(ImmutableSet.of(immutableTsLock)).isEmpty(); } }
@Test public void commitThrowsIfRolledBackAtCommitTime_expiredLocks() { final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); TimelockService timelockService = spy(new LegacyTimelockService(timestampService, lockService, lockClient)); // expire the locks when the pre-commit check happens - this is guaranteed to be after we've written the data PreCommitCondition condition = unused -> doReturn(ImmutableSet.of()).when(timelockService).refreshLockLeases(any()); LockImmutableTimestampResponse res = timelockService.lockImmutableTimestamp(IdentifiedTimeLockRequest.create()); long transactionTs = timelockService.getFreshTimestamp(); SnapshotTransaction snapshot = getSnapshotTransactionWith( timelockService, () -> transactionTs, res, condition); //simulate roll back at commit time transactionService.putUnlessExists(snapshot.getTimestamp(), TransactionConstants.FAILED_COMMIT_TS); snapshot.put(TABLE, ImmutableMap.of(cell, PtBytes.toBytes("value"))); assertThatExceptionOfType(TransactionLockTimeoutException.class).isThrownBy(snapshot::commit); timelockService.unlock(ImmutableSet.of(res.getLock())); TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics) .hasFailedCommits(1) .hasLocksExpired(1); }
private void refreshLocks() { try { Set<LockToken> toRefresh = ImmutableSet.copyOf(tokensToRefresh); if (toRefresh.isEmpty()) { return; } Set<LockToken> refreshed = timelockService.refreshLockLeases(toRefresh); tokensToRefresh.removeAll(Sets.difference(toRefresh, refreshed)); } catch (Throwable error) { log.warn("Error while refreshing locks. Trying again on next iteration", error); } }
@Override public Set<LockToken> refreshLockLeases( Set<LockToken> tokens) { return executeWithRecord(() -> timelockService.refreshLockLeases(tokens)); }
@Override public Set<LockToken> refreshLockLeases(Set<LockToken> tokens) { return executeOnTimeLock(() -> delegate.refreshLockLeases(tokens)); }