private void encodeChanges(BinaryEncoder encoder, Set<ChangeId> changes) throws IOException { if (!changes.isEmpty()) { encoder.writeInt(changes.size()); for (ChangeId change : changes) { encoder.writeBytes(change.getKey()); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override public void encode(OutputStream out, TransactionSnapshot snapshot) { SnapshotCodec codec = getCurrentCodec(); try { new BinaryEncoder(out).writeInt(codec.getVersion()); } catch (IOException e) { LOG.error("Unable to write transaction state version: ", e); throw Throwables.propagate(e); } codec.encode(out, snapshot); }
@Override public void encode(OutputStream out, TransactionSnapshot snapshot) { try { BinaryEncoder encoder = new BinaryEncoder(out); encoder.writeLong(snapshot.getTimestamp()); encoder.writeLong(snapshot.getReadPointer()); encoder.writeLong(snapshot.getWritePointer()); encodeInvalid(encoder, snapshot.getInvalid()); encodeInProgress(encoder, snapshot.getInProgress()); encodeChangeSets(encoder, snapshot.getCommittingChangeSets()); encodeChangeSets(encoder, snapshot.getCommittedChangeSets()); } catch (IOException e) { LOG.error("Unable to serialize transaction state: ", e); throw Throwables.propagate(e); } }
/** * write a sequence of bytes. First writes the number of bytes as an int, then the bytes themselves. * @throws java.io.IOException If there is IO error. */ public BinaryEncoder writeBytes(byte[] bytes) throws IOException { writeLong(bytes.length); output.write(bytes, 0, bytes.length); return this; } }
private void encodeChangeSets(BinaryEncoder encoder, Map<Long, Set<ChangeId>> changes) throws IOException { if (!changes.isEmpty()) { encoder.writeInt(changes.size()); for (Map.Entry<Long, Set<ChangeId>> entry : changes.entrySet()) { encoder.writeLong(entry.getKey()); encodeChanges(encoder, entry.getValue()); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); encoder.writeInt(entry.getValue().getType().ordinal()); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }
@Override protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress) throws IOException { if (!inProgress.isEmpty()) { encoder.writeInt(inProgress.size()); for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) { encoder.writeLong(entry.getKey()); // tx id encoder.writeLong(entry.getValue().getExpiration()); encoder.writeLong(entry.getValue().getVisibilityUpperBound()); encoder.writeInt(entry.getValue().getType().ordinal()); // write checkpoint tx IDs LongArrayList checkpointPointers = entry.getValue().getCheckpointWritePointers(); if (!checkpointPointers.isEmpty()) { encoder.writeInt(checkpointPointers.size()); for (int i = 0; i < checkpointPointers.size(); i++) { encoder.writeLong(checkpointPointers.getLong(i)); } } encoder.writeInt(0); } } encoder.writeInt(0); // zero denotes end of list as per AVRO spec }