congbobo184 commented on a change in pull request #9490:
URL: https://github.com/apache/pulsar/pull/9490#discussion_r575819038
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -168,7 +280,55 @@ public void addFailed(ManagedLedgerException exception,
Object ctx) {
}
}
+ private synchronized void takeSnapshotByChangeTimes() {
+ if (changeMaxReadPositionAndAddAbortTimes.get() >=
takeSnapshotIntervalNumber) {
+ takeSnapshot();
+ }
+ }
+
+ private synchronized void takeSnapshotByTimeout() {
+ if (changeMaxReadPositionAndAddAbortTimes.get() > 0) {
+ takeSnapshot();
+ }
+ timer.newTimeout(TopicTransactionBuffer.this,
+ takeSnapshotIntervalTime, TimeUnit.MILLISECONDS);
+ }
+
+ private void takeSnapshot() {
+ changeMaxReadPositionAndAddAbortTimes.set(0);
+ takeSnapshotWriter.thenAccept(writer -> {
+ TransactionBufferSnapshot snapshot = new
TransactionBufferSnapshot();
+ snapshot.setTopicName(topic.getName());
+ snapshot.setMaxReadPositionLedgerId(maxReadPosition.getLedgerId());
+ snapshot.setMaxReadPositionEntryId(maxReadPosition.getEntryId());
+ List<AbortTxnMetadata> list = new ArrayList<>();
+ aborts.forEach((k, v) -> {
+ AbortTxnMetadata abortTxnMetadata = new AbortTxnMetadata();
+ abortTxnMetadata.setTxnIdMostBits(k.getMostSigBits());
+ abortTxnMetadata.setTxnIdLeastBits(k.getLeastSigBits());
+ abortTxnMetadata.setLedgerId(v.getLedgerId());
+ abortTxnMetadata.setEntryId(v.getEntryId());
+ list.add(abortTxnMetadata);
+ });
+ snapshot.setAborts(list);
+ writer.writeAsync(snapshot).thenAccept((messageId) -> {
+ if (log.isDebugEnabled()) {
+ log.debug("[{}]Transaction buffer take snapshot success! "
+ + "messageId : {}", topic.getName(), messageId);
+ }
+ }).exceptionally(e -> {
+ if (log.isDebugEnabled()) {
Review comment:
yes, great suggestion!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]