codelipenghui commented on code in PR #15137: URL: https://github.com/apache/pulsar/pull/15137#discussion_r857425970
########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/util/LogIndexBackoff.java: ########## @@ -0,0 +1,58 @@ +/** + * 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.transaction.util; + +import org.apache.pulsar.client.api.RedeliveryBackoff; + +public class LogIndexBackoff implements RedeliveryBackoff { + + private final long minLag; + private final long maxLag; + private final double exponent; + + public LogIndexBackoff(long minLag, long maxLag, double exponent) { + this.minLag = minLag; + this.maxLag = maxLag; + this.exponent = exponent; + } + + public long getMinLag() { + return this.minLag; + } + + public long getMaxLag() { + return this.maxLag; + } + + public double getExponent() { + return exponent; + } + + @Override + public long next(int indexCount) { + if (indexCount <= 0 || minLag <= 0) { + return 0; Review Comment: If the `indexCount` <=0 we should return the `minLag`? And we should ensure `minLag` > 0? ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/util/LogIndexBackoff.java: ########## @@ -0,0 +1,58 @@ +/** + * 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.transaction.util; + +import org.apache.pulsar.client.api.RedeliveryBackoff; + +public class LogIndexBackoff implements RedeliveryBackoff { Review Comment: ```suggestion public class LogIndexLagBackoff { ``` ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/util/LogIndexBackoff.java: ########## @@ -0,0 +1,58 @@ +/** + * 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.transaction.util; + +import org.apache.pulsar.client.api.RedeliveryBackoff; + +public class LogIndexBackoff implements RedeliveryBackoff { + + private final long minLag; + private final long maxLag; + private final double exponent; + + public LogIndexBackoff(long minLag, long maxLag, double exponent) { + this.minLag = minLag; + this.maxLag = maxLag; + this.exponent = exponent; + } + + public long getMinLag() { + return this.minLag; + } + + public long getMaxLag() { + return this.maxLag; + } + + public double getExponent() { + return exponent; + } Review Comment: Add a `@Getter` annotation to reduce the template code ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/util/LogIndexBackoff.java: ########## @@ -0,0 +1,58 @@ +/** + * 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.transaction.util; + +import org.apache.pulsar.client.api.RedeliveryBackoff; + +public class LogIndexBackoff implements RedeliveryBackoff { + + private final long minLag; + private final long maxLag; + private final double exponent; + + public LogIndexBackoff(long minLag, long maxLag, double exponent) { + this.minLag = minLag; + this.maxLag = maxLag; + this.exponent = exponent; Review Comment: The exponent should > 0 ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/pendingack/impl/MLPendingAckStore.java: ########## @@ -292,6 +249,69 @@ public void addFailed(ManagedLedgerException exception, Object ctx) { return completableFuture; } + private void handleMetadataEntry(PositionImpl logPosition, PendingAckMetadataEntry pendingAckMetadataEntry) { + // store the persistent position in to memory + // store the max position of this entry retain + if (pendingAckMetadataEntry.getPendingAckOp() != PendingAckOp.ABORT + && pendingAckMetadataEntry.getPendingAckOp() != PendingAckOp.COMMIT) { + Optional<PendingAckMetadata> optional = pendingAckMetadataEntry.getPendingAckMetadatasList() + .stream().max((o1, o2) -> ComparisonChain.start().compare(o1.getLedgerId(), + o2.getLedgerId()).compare(o1.getEntryId(), o2.getEntryId()).result()); + + optional.ifPresent(pendingAckMetadata -> { + PositionImpl nowPosition = PositionImpl.get(pendingAckMetadata.getLedgerId(), + pendingAckMetadata.getEntryId()); + + if (nowPosition.compareTo(maxAckPosition) > 0) { + maxAckPosition = nowPosition; + } + if (logAppendTimes.get() > upperLimitOfLogAppendTimes) { Review Comment: Also here also have a race condition, if more than 1 threads reach line 269, it will not respect the constraints of backoff ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/pendingack/impl/MLPendingAckStore.java: ########## @@ -292,6 +249,69 @@ public void addFailed(ManagedLedgerException exception, Object ctx) { return completableFuture; } + private void handleMetadataEntry(PositionImpl logPosition, PendingAckMetadataEntry pendingAckMetadataEntry) { + // store the persistent position in to memory + // store the max position of this entry retain + if (pendingAckMetadataEntry.getPendingAckOp() != PendingAckOp.ABORT + && pendingAckMetadataEntry.getPendingAckOp() != PendingAckOp.COMMIT) { + Optional<PendingAckMetadata> optional = pendingAckMetadataEntry.getPendingAckMetadatasList() + .stream().max((o1, o2) -> ComparisonChain.start().compare(o1.getLedgerId(), + o2.getLedgerId()).compare(o1.getEntryId(), o2.getEntryId()).result()); + + optional.ifPresent(pendingAckMetadata -> { + PositionImpl nowPosition = PositionImpl.get(pendingAckMetadata.getLedgerId(), + pendingAckMetadata.getEntryId()); + + if (nowPosition.compareTo(maxAckPosition) > 0) { + maxAckPosition = nowPosition; + } + if (logAppendTimes.get() > upperLimitOfLogAppendTimes) { Review Comment: we should use `currentIndexLag` and `maxIndexLag` here to keep consistent with the `LogIndexLagBackoff ` ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/util/LogIndexBackoff.java: ########## @@ -0,0 +1,58 @@ +/** + * 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.transaction.util; + +import org.apache.pulsar.client.api.RedeliveryBackoff; + +public class LogIndexBackoff implements RedeliveryBackoff { + + private final long minLag; + private final long maxLag; + private final double exponent; + + public LogIndexBackoff(long minLag, long maxLag, double exponent) { + this.minLag = minLag; + this.maxLag = maxLag; Review Comment: The `maxLag` should >= `minLag` and `minLag` should > 0 -- 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]
