private static Cell getTransactionCell(long startTimestamp) { return Cell.create( TransactionConstants.getValueForTimestamp(startTimestamp), TransactionConstants.COMMIT_TS_COLUMN); } }
public Map<Long, Long> get(Iterable<Long> startTimestamps) { Map<Long, Long> result = Maps.newHashMap(); Map<Cell, Long> startTsMap = Maps.newHashMap(); for (Long startTimestamp : startTimestamps) { Cell cell = getTransactionCell(startTimestamp); startTsMap.put(cell, MAX_TIMESTAMP); } Map<Cell, Value> rawResults = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, startTsMap); for (Map.Entry<Cell, Value> e : rawResults.entrySet()) { long startTs = TransactionConstants.getTimestampForValue(e.getKey().getRowName()); long commitTs = TransactionConstants.getTimestampForValue(e.getValue().getContents()); result.put(startTs, commitTs); } return result; }
KeyValueService kvs = services.getKeyValueService(); byte[] startBytes = TransactionConstants.getValueForTimestamp(startTimestamp); byte[] timestampBytes = TransactionConstants.getValueForTimestamp(timestamp); RowResult<Value> row = range.next(); byte[] rowName = row.getRowName(); long startTs = TransactionConstants.getTimestampForValue(rowName); long commitTs = TransactionConstants.getTimestampForValue(value.getContents()); if (commitTs <= timestamp) { continue; // this is a valid transaction
KeyValueService kvs = services.getKeyValueService(); byte[] startBytes = TransactionConstants.getValueForTimestamp(startTimestamp); byte[] timestampBytes = TransactionConstants.getValueForTimestamp(timestamp); RowResult<Value> row = range.next(); byte[] rowName = row.getRowName(); long startTs = TransactionConstants.getTimestampForValue(rowName); long commitTs = TransactionConstants.getTimestampForValue(value.getContents()); if (commitTs <= timestamp) { continue; // this is a valid transaction
private static Cell getTransactionCell(long startTimestamp) { return Cell.create(TransactionConstants.getValueForTimestamp(startTimestamp), TransactionConstants.COMMIT_TS_COLUMN); }
public Long get(Long startTimestamp) { Cell cell = getTransactionCell(startTimestamp); Map<Cell, Value> returnMap = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP)); if (returnMap.containsKey(cell)) { return TransactionConstants.getTimestampForValue(returnMap.get(cell).getContents()); } else { return null; } }
public void putAll(Map<Long, Long> timestampMap) throws KeyAlreadyExistsException { Map<Cell, byte[]> kvMap = new HashMap<>(); for (Map.Entry<Long, Long> entry : timestampMap.entrySet()) { kvMap.put( getTransactionCell(entry.getKey()), TransactionConstants.getValueForTimestamp(entry.getValue())); } keyValueService.put(TransactionConstants.TRANSACTION_TABLE, kvMap, 0); // This can throw unchecked exceptions }
@Override public Map<Long, Long> get(Iterable<Long> startTimestamps) { Map<Cell, Long> startTsMap = Maps.newHashMap(); for (Long startTimestamp : startTimestamps) { Cell cell = getTransactionCell(startTimestamp); startTsMap.put(cell, MAX_TIMESTAMP); } Map<Cell, Value> rawResults = keyValueService.get( TransactionConstants.TRANSACTION_TABLE, startTsMap); Map<Long, Long> result = Maps.newHashMapWithExpectedSize(rawResults .size()); for (Map.Entry<Cell, Value> e : rawResults.entrySet()) { long startTs = TransactionConstants.getTimestampForValue(e.getKey() .getRowName()); long commitTs = TransactionConstants.getTimestampForValue(e .getValue().getContents()); result.put(startTs, commitTs); } return result; }
private void commit(long timestamp) { Cell cell = Cell.create( TransactionConstants.getValueForTimestamp(timestamp), TransactionConstants.COMMIT_TS_COLUMN); byte[] value = TransactionConstants.getValueForTimestamp(timestamp); delegate().putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, value)); } }
@Override public Long get(long startTimestamp) { Cell cell = getTransactionCell(startTimestamp); Map<Cell, Value> returnMap = keyValueService.get( TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP)); if (returnMap.containsKey(cell)) { return TransactionConstants.getTimestampForValue(returnMap .get(cell).getContents()); } else { return null; } }
public void putUnlessExists(long startTimestamp, long commitTimestamp) throws KeyAlreadyExistsException { Cell key = getTransactionCell(startTimestamp); byte[] value = TransactionConstants.getValueForTimestamp(commitTimestamp); keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(key, value)); }
public Map<Long, Long> get(Iterable<Long> startTimestamps) { Map<Long, Long> result = Maps.newHashMap(); Map<Cell, Long> startTsMap = Maps.newHashMap(); for (Long startTimestamp : startTimestamps) { Cell cell = getTransactionCell(startTimestamp); startTsMap.put(cell, MAX_TIMESTAMP); } Map<Cell, Value> rawResults = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, startTsMap); for (Map.Entry<Cell, Value> e : rawResults.entrySet()) { long startTs = TransactionConstants.getTimestampForValue(e.getKey().getRowName()); long commitTs = TransactionConstants.getTimestampForValue(e.getValue().getContents()); result.put(startTs, commitTs); } return result; }
@Override public void putUnlessExists(long startTimestamp, long commitTimestamp) { Cell key = getTransactionCell(startTimestamp); byte[] value = TransactionConstants .getValueForTimestamp(commitTimestamp); keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(key, value)); }
public Long get(Long startTimestamp) { Cell cell = getTransactionCell(startTimestamp); Map<Cell, Value> returnMap = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP)); if (returnMap.containsKey(cell)) { return TransactionConstants.getTimestampForValue(returnMap.get(cell).getContents()); } else { return null; } }
/** * We will block here until the passed transactions have released their lock. This means that * the committing transaction is either complete or it has failed and we are allowed to roll * it back. */ private void waitForCommitToComplete(Iterable<Long> startTimestamps) { boolean isEmpty = true; Set<LockDescriptor> lockDescriptors = Sets.newHashSet(); for (long start : startTimestamps) { if (start < immutableTimestamp) { // We don't need to block in this case because this transaction is already complete continue; } isEmpty = false; lockDescriptors.add( AtlasRowLockDescriptor.of( TransactionConstants.TRANSACTION_TABLE.getQualifiedName(), TransactionConstants.getValueForTimestamp(start))); } if (isEmpty) { return; } waitFor(lockDescriptors); }
@Override public Map<Long, Long> get(Iterable<Long> startTimestamps) { Map<Cell, Long> startTsMap = Maps.newHashMap(); for (Long startTimestamp : startTimestamps) { Cell cell = getTransactionCell(startTimestamp); startTsMap.put(cell, MAX_TIMESTAMP); } Map<Cell, Value> rawResults = keyValueService.get( TransactionConstants.TRANSACTION_TABLE, startTsMap); Map<Long, Long> result = Maps.newHashMapWithExpectedSize(rawResults .size()); for (Map.Entry<Cell, Value> e : rawResults.entrySet()) { long startTs = TransactionConstants.getTimestampForValue(e.getKey() .getRowName()); long commitTs = TransactionConstants.getTimestampForValue(e .getValue().getContents()); result.put(startTs, commitTs); } return result; }
e.getKey().getRowName()); if (Arrays.equals(e.getValue(), TransactionConstants.getValueForTimestamp(TransactionConstants.FAILED_COMMIT_TS))) { mapToAssertLockNotHeld.put(descriptor, LockMode.READ); } else {
@Override public Long get(long startTimestamp) { Cell cell = getTransactionCell(startTimestamp); Map<Cell, Value> returnMap = keyValueService.get( TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP)); if (returnMap.containsKey(cell)) { return TransactionConstants.getTimestampForValue(returnMap .get(cell).getContents()); } else { return null; } }
AtlasRowLockDescriptor.of( TransactionConstants.TRANSACTION_TABLE.getQualifiedName(), TransactionConstants.getValueForTimestamp(getStartTimestamp()))); continue;
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"); }