poorbarcode commented on code in PR #16931:
URL: https://github.com/apache/pulsar/pull/16931#discussion_r1000814409
##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/transaction/TxnID.java:
##########
@@ -39,14 +43,14 @@ public class TxnID implements Serializable {
*
* @serial
*/
- private final long mostSigBits;
+ private long mostSigBits;
Review Comment:
Hi @liangyepianzhou
I see you have added the new class `TxnIDData`, so should we remove these
two changes?
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerFactoryImpl.java:
##########
@@ -420,7 +420,29 @@ public void closeFailed(ManagedLedgerException exception,
Object ctx) {
});
}
+ @Override
+ public void asyncOpenReadOnlyManagedLedger(String managedLedgerName,
Review Comment:
Can we write this method like this( Saves the new class `AsyncCallbacks
.OpenReadOnlyManagedLedgerCallback` )?
```
@Override
public CompletableFuture<ReadOnlyManagedLedgerImpl>
asyncOpenReadOnlyManagedLedger(String managedLedgerName,
ManagedLedgerConfig config, Object ctx) {
if (closed) {
return FutureUtil.failedFuture(new
ManagedLedgerException.ManagedLedgerFactoryClosedException());
}
ReadOnlyManagedLedgerImpl roManagedLedger = new
ReadOnlyManagedLedgerImpl(this,
bookkeeperFactory
.get(new
EnsemblePlacementPolicyConfig(config.getBookKeeperEnsemblePlacementPolicyClassName(),
config.getBookKeeperEnsemblePlacementPolicyProperties())),
store, config, scheduledExecutor, managedLedgerName);
return roManagedLedger.initialize().thenApply(ignore -> roManagedLedger);
}
```
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/systopic/TransactionBufferSnapshotBaseSystemTopicClient.java:
##########
@@ -0,0 +1,218 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.systopic;
+
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.broker.service.SystemTopicTxnBufferSnapshotService;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.common.naming.TopicName;
+
+@Slf4j
+public class TransactionBufferSnapshotBaseSystemTopicClient<T> extends
SystemTopicClientBase<T> {
+
+ protected final SystemTopicTxnBufferSnapshotService<T>
systemTopicTxnBufferSnapshotService;
+ protected final Class<T> schemaType;
+
+ public TransactionBufferSnapshotBaseSystemTopicClient(PulsarClient client,
+ TopicName topicName,
+
SystemTopicTxnBufferSnapshotService<T>
+
systemTopicTxnBufferSnapshotService,
+ Class<T> schemaType)
{
+ super(client, topicName);
+ this.systemTopicTxnBufferSnapshotService =
systemTopicTxnBufferSnapshotService;
+ this.schemaType = schemaType;
+ }
+
+ protected void removeWriter(Writer<T> writer) {
+ writers.remove(writer);
+ this.systemTopicTxnBufferSnapshotService.removeClient(topicName, this);
+ }
+
+ protected void removeReader(Reader<T> reader) {
+ readers.remove(reader);
+ this.systemTopicTxnBufferSnapshotService.removeClient(topicName, this);
+ }
+
+ protected static class TransactionBufferSnapshotWriter<T> implements
Writer<T> {
+
+ protected final Producer<T> producer;
+ protected final TransactionBufferSnapshotBaseSystemTopicClient<T>
+ transactionBufferSnapshotBaseSystemTopicClient;
+
+ protected TransactionBufferSnapshotWriter(Producer<T> producer,
+
TransactionBufferSnapshotBaseSystemTopicClient<T>
+
transactionBufferSnapshotBaseSystemTopicClient) {
+ this.producer = producer;
+ this.transactionBufferSnapshotBaseSystemTopicClient =
transactionBufferSnapshotBaseSystemTopicClient;
+ }
+
+ @Override
+ public MessageId write(T t, String key)
+ throws PulsarClientException {
+ return producer.newMessage().key(key)
+ .value(t).send();
+ }
+
+ @Override
+ public CompletableFuture<MessageId> writeAsync(T t, String key) {
+ return producer.newMessage()
+ .key(key)
+ .value(t).sendAsync();
+ }
+
+ @Override
+ public MessageId delete(T t, String key)
+ throws PulsarClientException {
+ return producer.newMessage()
+ .key(key)
+ .value(null)
+ .send();
+ }
+
+ @Override
+ public CompletableFuture<MessageId> deleteAsync(T t, String key) {
+ return producer.newMessage()
+ .key(key)
+ .value(null)
+ .sendAsync();
+ }
+
+ @Override
+ public void close() throws IOException {
+ this.producer.close();
+ transactionBufferSnapshotBaseSystemTopicClient.removeWriter(this);
Review Comment:
Can we write this method like this?
```
@Override
public void close() throws IOException {
this.closeAsync().join();
}
```
Same for `TransactionBufferSnapshotReader`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]