/** * This should only be created by the lock service. This call will not actually refresh the token. */ public HeldLocksToken refresh(long newExpirationDateMs) { return new HeldLocksToken(tokenId, client, creationDateMs, newExpirationDateMs, lockMap, lockTimeout, versionId, requestingThread); }
Object readResolve() { return new HeldLocksToken(tokenId, client, creationDateMs, expirationDateMs, lockMap, lockTimeout, versionId, requestingThread); } }
public static HeldLocksToken getFakeHeldLocksToken(String clientName, String requestingThread, BigInteger tokenId, String... descriptors) { ImmutableSortedMap<LockDescriptor, LockMode> lockDescriptorLockMode = getLockDescriptorLockMode(Arrays.asList(descriptors)); return new HeldLocksToken(tokenId, LockClient.of(clientName), System.currentTimeMillis(), System.currentTimeMillis(), LockCollections.of(lockDescriptorLockMode), LockRequest.getDefaultLockTimeout(), 0L, requestingThread); }
@Override public Set<LockRefreshToken> refreshLockRefreshTokens(Iterable<LockRefreshToken> tokens) { List<HeldLocksToken> fakeTokens = Lists.newArrayList(); LockDescriptor fakeLockDesc = StringLockDescriptor.of("refreshLockRefreshTokens"); SortedLockCollection<LockDescriptor> fakeLockSet = LockCollections.of(ImmutableSortedMap.of(fakeLockDesc, LockMode.READ)); for (LockRefreshToken token : tokens) { fakeTokens.add(new HeldLocksToken( token.getTokenId(), LockClient.ANONYMOUS, 0L, 0L, fakeLockSet, maxAllowedLockTimeout, 0L, "UnknownThread-refreshLockRefreshTokens")); } return ImmutableSet.copyOf(Iterables.transform(refreshTokens(fakeTokens), HeldLocksTokens.getRefreshTokenFun())); }
private HeldLocksToken createHeldLocksToken(LockClient client, SortedLockCollection<LockDescriptor> lockDescriptorMap, LockCollection<? extends ClientAwareReadWriteLock> heldLocksMap, TimeDuration lockTimeout, @Nullable Long versionId, String requestThread) { while (true) { BigInteger tokenId = new BigInteger(RANDOM_BIT_COUNT, randomPool.getSecureRandom()); long expirationDateMs = currentTimeMillis() + lockTimeout.toMillis(); HeldLocksToken token = new HeldLocksToken(tokenId, client, currentTimeMillis(), expirationDateMs, lockDescriptorMap, lockTimeout, versionId, requestThread); HeldLocks<HeldLocksToken> heldLocks = HeldLocks.of(token, heldLocksMap); if (heldLocksTokenMap.putIfAbsent(token, heldLocks) == null) { lockTokenReaperQueue.add(token); if (!client.isAnonymous()) { lockClientMultimap.put(client, token); } return token; } log.error("Lock ID collision! " + "Count of held tokens = {}" + "; random bit count = {}", SafeArg.of("heldTokenCount", heldLocksTokenMap.size()), SafeArg.of("randomBitCount", RANDOM_BIT_COUNT)); } }
@Override public boolean unlockSimple(SimpleHeldLocksToken token) { Preconditions.checkNotNull(token); LockDescriptor fakeLockDesc = StringLockDescriptor.of("unlockSimple"); SortedLockCollection<LockDescriptor> fakeLockSet = LockCollections.of(ImmutableSortedMap.of(fakeLockDesc, LockMode.READ)); return unlock(new HeldLocksToken( token.getTokenId(), LockClient.ANONYMOUS, token.getCreationDateMs(), 0L, fakeLockSet, maxAllowedLockTimeout, 0L, "UnknownThread-unlockSimple")); }
private static HeldLocksToken getHeldLocksToken(BigInteger tokenId) { long creationDateMs = System.currentTimeMillis(); long expirationDateMs = creationDateMs - 1; TimeDuration lockTimeout = SimpleTimeDuration.of(0, TimeUnit.SECONDS); long versionId = 0L; return new HeldLocksToken( tokenId, LockClient.of("fake lock client"), creationDateMs, expirationDateMs, LOCK_DESCRIPTORS, lockTimeout, versionId, "Dummy thread"); } }
@Test public void testSerializationDeserialization() throws Exception { SortedMap<LockDescriptor, LockMode> lockMap = ImmutableSortedMap.of(StringLockDescriptor.of("foo"), LockMode.READ); HeldLocksToken heldLocksToken = new HeldLocksToken( BigInteger.valueOf(0), LockClient.of("foo"), 0, 0, LockCollections.of(lockMap), SimpleTimeDuration.of(1, TimeUnit.SECONDS), 0L, "Dummy Thread"); HeldLocksToken deserializedHeldLocksToken = mapper.readValue(mapper.writeValueAsString(heldLocksToken), HeldLocksToken.class); assertThat(deserializedHeldLocksToken, is(heldLocksToken)); }
Object readResolve() { return new HeldLocksToken(tokenId, client, creationDateMs, expirationDateMs, lockMap, lockTimeout, versionId, requestingThread); } }
/** * This should only be created by the lock service. This call will not actually refresh the token. */ public HeldLocksToken refresh(long newExpirationDateMs) { return new HeldLocksToken(tokenId, client, creationDateMs, newExpirationDateMs, lockMap, lockTimeout, versionId, requestingThread); }
private HeldLocksToken getExpiredHeldLocksToken() { ImmutableSortedMap.Builder<LockDescriptor, LockMode> builder = ImmutableSortedMap.naturalOrder(); builder.put( AtlasRowLockDescriptor.of( TransactionConstants.TRANSACTION_TABLE.getQualifiedName(), TransactionConstants.getValueForTimestamp(0L)), LockMode.WRITE); long creationDateMs = System.currentTimeMillis(); long expirationDateMs = creationDateMs - 1; TimeDuration lockTimeout = SimpleTimeDuration.of(0, TimeUnit.SECONDS); long versionId = 0L; return new HeldLocksToken( BigInteger.ZERO, lockClient, creationDateMs, expirationDateMs, LockCollections.of(builder.build()), lockTimeout, versionId, "Dummy thread"); }