congbobo184 commented on code in PR #16428: URL: https://github.com/apache/pulsar/pull/16428#discussion_r920081049
########## pulsar-transaction/coordinator/src/main/java/org/apache/pulsar/transaction/coordinator/impl/TxnLogBufferedWriter.java: ########## @@ -0,0 +1,489 @@ +/** + * 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.transaction.coordinator.impl; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.util.Recycler; +import java.io.Closeable; +import java.util.ArrayList; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import lombok.Getter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; +import org.apache.bookkeeper.common.util.OrderedExecutor; +import org.apache.bookkeeper.mledger.AsyncCallbacks; +import org.apache.bookkeeper.mledger.ManagedLedger; +import org.apache.bookkeeper.mledger.ManagedLedgerException; +import org.apache.bookkeeper.mledger.Position; +import org.apache.bookkeeper.mledger.impl.PositionImpl; +import org.apache.bookkeeper.util.SafeRunnable; +import org.apache.commons.lang3.tuple.Triple; +import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; +import org.apache.pulsar.common.util.collections.BitSetRecyclable; + +/*** + * See PIP-160: https://github.com/apache/pulsar/issues/15516. + * Buffer requests and flush to Managed Ledger. Transaction Log Store And Pending Ack Store will no longer write to + * Managed Ledger directly, Change to using this class to write Ledger data. + * Caches “write requests” for a certain number or a certain size of request data and then writes them to the + * Managed Ledger in one go. After Managed Ledger has written complete, responds to each request-caller. In this + * process, Managed Ledger doesn't care how many records(or what to be written) in the Entry, it just treats them as + * a single block of data. + * The first write-request by transaction components will take a long time to receive a response, because we must wait + * for subsequent requests to accumulate enough data to actually start writing to the Managed Ledger. To control the + * maximum latency, we will mark the first request time for each batch, and additional timing triggers writes. + * You can enable or disabled the batch feature, will use Managed Ledger directly and without batching when disabled. + */ +@Slf4j +public class TxnLogBufferedWriter<T> implements AsyncCallbacks.AddEntryCallback, Closeable { + + public static final short BATCHED_ENTRY_DATA_PREFIX_MAGIC_NUMBER = 0x0e01; + + public static final short BATCHED_ENTRY_DATA_PREFIX_VERSION = 1; + + private static final ManagedLedgerException BUFFERED_WRITER_CLOSED_EXCEPTION = + new ManagedLedgerException("Transaction log buffered write has closed"); Review Comment: It's better to return ManagedLedgerFencedException. ########## pulsar-transaction/coordinator/src/main/java/org/apache/pulsar/transaction/coordinator/impl/TxnLogBufferedWriter.java: ########## @@ -0,0 +1,489 @@ +/** + * 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.transaction.coordinator.impl; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.util.Recycler; +import java.io.Closeable; +import java.util.ArrayList; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import lombok.Getter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; +import org.apache.bookkeeper.common.util.OrderedExecutor; +import org.apache.bookkeeper.mledger.AsyncCallbacks; +import org.apache.bookkeeper.mledger.ManagedLedger; +import org.apache.bookkeeper.mledger.ManagedLedgerException; +import org.apache.bookkeeper.mledger.Position; +import org.apache.bookkeeper.mledger.impl.PositionImpl; +import org.apache.bookkeeper.util.SafeRunnable; +import org.apache.commons.lang3.tuple.Triple; +import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; +import org.apache.pulsar.common.util.collections.BitSetRecyclable; + +/*** + * See PIP-160: https://github.com/apache/pulsar/issues/15516. + * Buffer requests and flush to Managed Ledger. Transaction Log Store And Pending Ack Store will no longer write to + * Managed Ledger directly, Change to using this class to write Ledger data. + * Caches “write requests” for a certain number or a certain size of request data and then writes them to the + * Managed Ledger in one go. After Managed Ledger has written complete, responds to each request-caller. In this + * process, Managed Ledger doesn't care how many records(or what to be written) in the Entry, it just treats them as + * a single block of data. + * The first write-request by transaction components will take a long time to receive a response, because we must wait + * for subsequent requests to accumulate enough data to actually start writing to the Managed Ledger. To control the + * maximum latency, we will mark the first request time for each batch, and additional timing triggers writes. + * You can enable or disabled the batch feature, will use Managed Ledger directly and without batching when disabled. + */ +@Slf4j +public class TxnLogBufferedWriter<T> implements AsyncCallbacks.AddEntryCallback, Closeable { + + public static final short BATCHED_ENTRY_DATA_PREFIX_MAGIC_NUMBER = 0x0e01; + + public static final short BATCHED_ENTRY_DATA_PREFIX_VERSION = 1; + + private static final ManagedLedgerException BUFFERED_WRITER_CLOSED_EXCEPTION = + new ManagedLedgerException("Transaction log buffered write has closed"); Review Comment: ```suggestion new ManagedLedgerException("Transaction log buffered writer has closed"); ``` -- 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]
