@Override public Transaction startShort() { long wp = currentTxPointer++; // NOTE: -1 here is because we have logic that uses (readpointer + 1) as a "exclusive stop key" in some datasets return new Transaction( Long.MAX_VALUE - 1, wp, new long[0], new long[0], Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT); }
@Override public Transaction startShort() { long wp = currentTxPointer++; // NOTE: -1 here is because we have logic that uses (readpointer + 1) as a "exclusive stop key" in some datasets return new Transaction( Long.MAX_VALUE - 1, wp, new long[0], new long[0], Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT); }
@Override public Transaction startShort() { long wp = getWritePointer(); // NOTE: -1 here is because we have logic that uses (readpointer + 1) as a "exclusive stop key" in some datasets return new Transaction( Long.MAX_VALUE - 1, wp, new long[0], new long[0], Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT); }
@Override public Transaction startShort() { long wp = getWritePointer(); // NOTE: -1 here is because we have logic that uses (readpointer + 1) as a "exclusive stop key" in some datasets return new Transaction( Long.MAX_VALUE - 1, wp, new long[0], new long[0], Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT); }
/** * Creates a new Transaction. This method only get called from start transaction, which is already * synchronized. */ private Transaction createTransaction(long writePointer, TransactionType type) { // For holding the first in progress short transaction Id (with timeout >= 0). long firstShortTx = Transaction.NO_TX_IN_PROGRESS; LongArrayList inProgressIds = new LongArrayList(inProgress.size()); for (Map.Entry<Long, InProgressTx> entry : inProgress.entrySet()) { long txId = entry.getKey(); inProgressIds.add(txId); // add any checkpointed write pointers to the in-progress list LongArrayList childIds = entry.getValue().getCheckpointWritePointers(); if (childIds != null) { for (int i = 0; i < childIds.size(); i++) { inProgressIds.add(childIds.get(i)); } } if (firstShortTx == Transaction.NO_TX_IN_PROGRESS && !entry.getValue().isLongRunning()) { firstShortTx = txId; } } return new Transaction(readPointer, writePointer, invalidArray, inProgressIds.toLongArray(), firstShortTx, type); }
/** * Creates a new Transaction. This method only get called from start transaction, which is already * synchronized. */ private Transaction createTransaction(long writePointer, TransactionType type) { // For holding the first in progress short transaction Id (with timeout >= 0). long firstShortTx = Transaction.NO_TX_IN_PROGRESS; LongArrayList inProgressIds = new LongArrayList(inProgress.size()); for (Map.Entry<Long, InProgressTx> entry : inProgress.entrySet()) { long txId = entry.getKey(); inProgressIds.add(txId); // add any checkpointed write pointers to the in-progress list LongArrayList childIds = entry.getValue().getCheckpointWritePointers(); if (childIds != null) { for (int i = 0; i < childIds.size(); i++) { inProgressIds.add(childIds.get(i)); } } if (firstShortTx == Transaction.NO_TX_IN_PROGRESS && !entry.getValue().isLongRunning()) { firstShortTx = txId; } } return new Transaction(readPointer, writePointer, invalidArray, inProgressIds.toLongArray(), firstShortTx, type); }
@Override public Transaction checkpoint(Transaction tx) { long newWritePointer = getWritePointer(); LongArrayList newCheckpointPointers = new LongArrayList(tx.getCheckpointWritePointers()); newCheckpointPointers.add(newWritePointer); return new Transaction(tx, newWritePointer, newCheckpointPointers.toLongArray()); }
@Override public Transaction checkpoint(Transaction tx) { long newWritePointer = getWritePointer(); LongArrayList newCheckpointPointers = new LongArrayList(tx.getCheckpointWritePointers()); newCheckpointPointers.add(newWritePointer); return new Transaction(tx, newWritePointer, newCheckpointPointers.toLongArray()); }
checkpointedTx = new Transaction(originalTx, newWritePointer, parentTx.getCheckpointWritePointers().toLongArray());
checkpointedTx = new Transaction(originalTx, newWritePointer, parentTx.getCheckpointWritePointers().toLongArray());
@Test public void testSnapshotVisibility() throws Exception { Transaction.VisibilityLevel visibilityLevel = Transaction.VisibilityLevel.SNAPSHOT; Set<Long> checkPointers = ImmutableSet.of(220L, 250L); Transaction tx = new Transaction(readPointer, txId, 250L, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); Set<Long> visibleCurrent = ImmutableSet.of(200L, 220L, 250L); Set<Long> notVisibleCurrent = ImmutableSet.of(); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); checkPointers = ImmutableSet.of(); tx = new Transaction(readPointer, txId, txId, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); visibleCurrent = ImmutableSet.of(txId); notVisibleCurrent = ImmutableSet.of(); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); }
@Test public void testSnapshotExcludeVisibility() throws Exception { Transaction.VisibilityLevel visibilityLevel = Transaction.VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT; Set<Long> checkPointers = ImmutableSet.of(220L, 250L); Transaction tx = new Transaction(readPointer, txId, 250L, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); Set<Long> visibleCurrent = ImmutableSet.of(200L, 220L); Set<Long> notVisibleCurrent = ImmutableSet.of(250L); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); checkPointers = ImmutableSet.of(); tx = new Transaction(readPointer, txId, txId, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); visibleCurrent = ImmutableSet.of(); notVisibleCurrent = ImmutableSet.of(txId); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); }
@Test public void testSnapshotAllVisibility() throws Exception { Transaction.VisibilityLevel visibilityLevel = Transaction.VisibilityLevel.SNAPSHOT_ALL; Set<Long> checkPointers = ImmutableSet.of(220L, 250L); Transaction tx = new Transaction(readPointer, txId, 250L, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); Set<Long> visibleCurrent = ImmutableSet.of(200L, 220L, 250L); Set<Long> notVisibleCurrent = ImmutableSet.of(); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); checkPointers = ImmutableSet.of(); tx = new Transaction(readPointer, txId, txId, toSortedArray(priorInvalids), toSortedArray(priorInProgress), 95L, TransactionType.SHORT, toSortedArray(checkPointers), visibilityLevel); visibleCurrent = ImmutableSet.of(txId); notVisibleCurrent = ImmutableSet.of(); assertVisibility(priorCommitted, postCommitted, priorInvalids, postInvalids, priorInProgress, postInProgress, visibleCurrent, notVisibleCurrent, tx); }
/** * Creates a "dummy" transaction based on the given txVisibilityState's state. This is not a "real" transaction in * the sense that it has not been started, data should not be written with it, and it cannot be committed. However, * this can still be useful for filtering data according to the txVisibilityState's state. Instead of the actual * write pointer from the txVisibilityState, however, we use {@code Long.MAX_VALUE} to avoid mis-identifying any cells * as being written by this transaction (and therefore visible). */ public static Transaction createDummyTransaction(TransactionVisibilityState txVisibilityState) { return new Transaction(txVisibilityState.getReadPointer(), Long.MAX_VALUE, Longs.toArray(txVisibilityState.getInvalid()), Longs.toArray(txVisibilityState.getInProgress().keySet()), TxUtils.getFirstShortInProgress(txVisibilityState.getInProgress()), TransactionType.SHORT); }
/** * Creates a "dummy" transaction based on the given txVisibilityState's state. This is not a "real" transaction in * the sense that it has not been started, data should not be written with it, and it cannot be committed. However, * this can still be useful for filtering data according to the txVisibilityState's state. Instead of the actual * write pointer from the txVisibilityState, however, we use {@code Long.MAX_VALUE} to avoid mis-identifying any cells * as being written by this transaction (and therefore visible). */ public static Transaction createDummyTransaction(TransactionVisibilityState txVisibilityState) { return new Transaction(txVisibilityState.getReadPointer(), Long.MAX_VALUE, Longs.toArray(txVisibilityState.getInvalid()), Longs.toArray(txVisibilityState.getInProgress().keySet()), TxUtils.getFirstShortInProgress(txVisibilityState.getInProgress()), TransactionType.SHORT); }
public static Transaction unwrap(TTransaction thriftTx) { return new Transaction(thriftTx.getReadPointer(), thriftTx.getTransactionId(), thriftTx.getWritePointer(), thriftTx.getInvalids() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInvalids()), thriftTx.getInProgress() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInProgress()), thriftTx.getFirstShort(), getTransactionType(thriftTx.getType()), thriftTx.getCheckpointWritePointers() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getCheckpointWritePointers()), getVisibilityLevel(thriftTx.getVisibilityLevel())); }
public static Transaction unwrap(TTransaction thriftTx) { return new Transaction(thriftTx.getReadPointer(), thriftTx.getTransactionId(), thriftTx.getWritePointer(), thriftTx.getInvalids() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInvalids()), thriftTx.getInProgress() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInProgress()), thriftTx.getFirstShort(), getTransactionType(thriftTx.getType()), thriftTx.getCheckpointWritePointers() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getCheckpointWritePointers()), getVisibilityLevel(thriftTx.getVisibilityLevel())); }
Transaction txOld = new Transaction(tx1.getReadPointer(), tx1.getTransactionId() - 1, new long[] {}, new long[] {}, Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT); Transaction txNew = new Transaction(tx1.getReadPointer(), tx1.getTransactionId() + 1, new long[] {}, new long[] {}, Transaction.NO_TX_IN_PROGRESS, TransactionType.SHORT);