use of org.apache.pulsar.client.api.transaction.TxnID in project flink by apache.
the class PulsarUnorderedPartitionSplitReader method snapshotState.
public PulsarPartitionSplitState snapshotState(long checkpointId) {
PulsarPartitionSplitState state = new PulsarPartitionSplitState(registeredSplit);
// Avoiding NP problem when Pulsar don't get the message before Flink checkpoint.
if (uncommittedTransaction != null) {
TxnID txnID = uncommittedTransaction.getTxnID();
this.uncommittedTransaction = newTransaction();
state.setUncommittedTransactionId(txnID);
}
return state;
}
use of org.apache.pulsar.client.api.transaction.TxnID in project flink by apache.
the class PulsarPartitionSplitSerializer method deserializePulsarPartitionSplit.
public PulsarPartitionSplit deserializePulsarPartitionSplit(int version, DataInputStream in) throws IOException {
// partition
TopicPartition partition = deserializeTopicPartition(version, in);
// stopCursor
StopCursor stopCursor = deserializeObject(in);
// latestConsumedId
MessageId latestConsumedId = null;
if (in.readBoolean()) {
byte[] messageIdBytes = deserializeBytes(in);
latestConsumedId = MessageId.fromByteArray(messageIdBytes);
}
// uncommittedTransactionId
TxnID uncommittedTransactionId = null;
if (in.readBoolean()) {
long mostSigBits = in.readLong();
long leastSigBits = in.readLong();
uncommittedTransactionId = new TxnID(mostSigBits, leastSigBits);
}
// Creation
return new PulsarPartitionSplit(partition, stopCursor, latestConsumedId, uncommittedTransactionId);
}
use of org.apache.pulsar.client.api.transaction.TxnID in project flink by apache.
the class PulsarCommittableSerializerTest method committableSerDe.
@Test
void committableSerDe() throws IOException {
String topic = randomAlphabetic(10);
TxnID txnID = new TxnID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong());
PulsarCommittable committable = new PulsarCommittable(txnID, topic);
byte[] bytes = INSTANCE.serialize(committable);
PulsarCommittable committable1 = INSTANCE.deserialize(INSTANCE.getVersion(), bytes);
assertEquals(committable1, committable);
}
use of org.apache.pulsar.client.api.transaction.TxnID in project flink by apache.
the class PulsarPartitionSplitSerializer method serializePulsarPartitionSplit.
// ----------------- helper methods --------------
public void serializePulsarPartitionSplit(DataOutputStream out, PulsarPartitionSplit split) throws IOException {
// partition
serializeTopicPartition(out, split.getPartition());
// stopCursor
serializeObject(out, split.getStopCursor());
// latestConsumedId
MessageId latestConsumedId = split.getLatestConsumedId();
if (latestConsumedId == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
serializeBytes(out, latestConsumedId.toByteArray());
}
// uncommittedTransactionId
TxnID uncommittedTransactionId = split.getUncommittedTransactionId();
if (uncommittedTransactionId == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeLong(uncommittedTransactionId.getMostSigBits());
out.writeLong(uncommittedTransactionId.getLeastSigBits());
}
}
use of org.apache.pulsar.client.api.transaction.TxnID in project flink by apache.
the class PulsarCommittableSerializer method serialize.
@Override
public byte[] serialize(PulsarCommittable obj) throws IOException {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(baos)) {
TxnID txnID = obj.getTxnID();
out.writeLong(txnID.getMostSigBits());
out.writeLong(txnID.getLeastSigBits());
out.writeUTF(obj.getTopic());
out.flush();
return baos.toByteArray();
}
}
Aggregations