@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { dest.setWritePointer(in.readLong()); int stateIdx = in.readInt(); try { dest.setState(TransactionEdit.State.values()[stateIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("State enum ordinal value is out of range: " + stateIdx); } dest.setExpiration(in.readLong()); dest.setCommitPointer(in.readLong()); dest.setCanCommit(in.readBoolean()); int changeSize = in.readInt(); Set<ChangeId> changes = Sets.newHashSet(); for (int i = 0; i < changeSize; i++) { int currentLength = in.readInt(); byte[] currentBytes = new byte[currentLength]; in.readFully(currentBytes); changes.add(new ChangeId(currentBytes)); } dest.setChanges(changes); // 1st version did not store this info. It is safe to set firstInProgress to 0, it may decrease performance until // this tx is finished, but correctness will be preserved. dest.setVisibilityUpperBound(0); }
/** @deprecated use {@link TransactionEditCodecs.TransactionEditCodecV4} instead, it is still here for * unit-tests only */ @Override @Deprecated public void encode(TransactionEdit src, DataOutput out) throws IOException { out.writeLong(src.getWritePointer()); // use ordinal for predictable size, though this does not support evolution out.writeInt(src.getState().ordinal()); out.writeLong(src.getExpiration()); out.writeLong(src.getCommitPointer()); out.writeBoolean(src.getCanCommit()); Set<ChangeId> changes = src.getChanges(); if (changes == null) { out.writeInt(0); } else { out.writeInt(changes.size()); for (ChangeId c : changes) { byte[] cKey = c.getKey(); out.writeInt(cKey.length); out.write(cKey); } } // NOTE: we didn't have visibilityUpperBound in V1, it was added in V2 // we didn't have transaction type, truncateInvalidTx and truncateInvalidTxTime in V1 and V2, // it was added in V3 }
List<TransactionEdit> edits = Lists.newArrayListWithCapacity(numEntries); for (int i = 0; i < numEntries; i++) { TransactionEdit.State nextType = TransactionEdit.State.values()[random.nextInt(6)]; long writePointer = Math.abs(random.nextLong()); switch (nextType) {
/** @deprecated use {@link TransactionEditCodecs.TransactionEditCodecV4} instead, it is still here for * unit-tests only */ @Override @Deprecated public void encode(TransactionEdit src, DataOutput out) throws IOException { out.writeLong(src.getWritePointer()); // use ordinal for predictable size, though this does not support evolution out.writeInt(src.getState().ordinal()); out.writeLong(src.getExpiration()); out.writeLong(src.getCommitPointer()); out.writeBoolean(src.getCanCommit()); Set<ChangeId> changes = src.getChanges(); if (changes == null) { out.writeInt(0); } else { out.writeInt(changes.size()); for (ChangeId c : changes) { byte[] cKey = c.getKey(); out.writeInt(cKey.length); out.write(cKey); } } // NOTE: we didn't have visibilityUpperBound in V1, it was added in V2 // we didn't have transaction type, truncateInvalidTx and truncateInvalidTxTime in V1 and V2, // it was added in V3 }
@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { dest.setWritePointer(in.readLong()); int stateIdx = in.readInt(); try { dest.setState(TransactionEdit.State.values()[stateIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("State enum ordinal value is out of range: " + stateIdx); } dest.setExpiration(in.readLong()); dest.setCommitPointer(in.readLong()); dest.setCanCommit(in.readBoolean()); int changeSize = in.readInt(); Set<ChangeId> changes = Sets.newHashSet(); for (int i = 0; i < changeSize; i++) { int currentLength = in.readInt(); byte[] currentBytes = new byte[currentLength]; in.readFully(currentBytes); changes.add(new ChangeId(currentBytes)); } dest.setChanges(changes); // 1st version did not store this info. It is safe to set firstInProgress to 0, it may decrease performance until // this tx is finished, but correctness will be preserved. dest.setVisibilityUpperBound(0); }
/** @deprecated use {@link TransactionEditCodecs.TransactionEditCodecV4} instead, it is still here for * unit-tests only */ @Override @Deprecated public void encode(TransactionEdit src, DataOutput out) throws IOException { out.writeLong(src.getWritePointer()); // use ordinal for predictable size, though this does not support evolution out.writeInt(src.getState().ordinal()); out.writeLong(src.getExpiration()); out.writeLong(src.getCommitPointer()); out.writeBoolean(src.getCanCommit()); Set<ChangeId> changes = src.getChanges(); if (changes == null) { out.writeInt(0); } else { out.writeInt(changes.size()); for (ChangeId c : changes) { byte[] cKey = c.getKey(); out.writeInt(cKey.length); out.write(cKey); } } // NOTE: we didn't have visibilityUpperBound in V1, it was added in V2 // we didn't have transaction type, truncateInvalidTx and truncateInvalidTxTime in V1 and V2, // it was added in V3 }
@Override public void decode(TransactionEdit dest, DataInput in) throws IOException { dest.setWritePointer(in.readLong()); int stateIdx = in.readInt(); try { dest.setState(TransactionEdit.State.values()[stateIdx]); } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("State enum ordinal value is out of range: " + stateIdx); } dest.setExpiration(in.readLong()); dest.setCommitPointer(in.readLong()); dest.setCanCommit(in.readBoolean()); int changeSize = in.readInt(); Set<ChangeId> changes = Sets.newHashSet(); for (int i = 0; i < changeSize; i++) { int currentLength = in.readInt(); byte[] currentBytes = new byte[currentLength]; in.readFully(currentBytes); changes.add(new ChangeId(currentBytes)); } dest.setChanges(changes); // 1st version did not store this info. It is safe to set firstInProgress to 0, it may decrease performance until // this tx is finished, but correctness will be preserved. dest.setVisibilityUpperBound(0); }
/** * Creates a new instance from {@link co.cask.tephra.persist.TransactionEdit}. */ @Deprecated public static TransactionEdit convertCaskTxEdit(co.cask.tephra.persist.TransactionEdit txEdit) { if (txEdit == null) { return null; } return new TransactionEdit(txEdit.getWritePointer(), txEdit.getVisibilityUpperBound(), TransactionEdit.State.valueOf(txEdit.getState().toString()), txEdit.getExpiration(), txEdit.getChanges(), txEdit.getCommitPointer(), txEdit.getCanCommit(), txEdit.getType(), txEdit.getTruncateInvalidTx(), txEdit.getTruncateInvalidTxTime(), txEdit.getParentWritePointer(), txEdit.getCheckpointPointers()); }