forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve batch message acking by removing batch message tracker (apach…
…e#1424) * Improve batch message acking by removing batch message tracker * fix * Fix the cumulative ack * Fix batchsize
- Loading branch information
Showing
9 changed files
with
294 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageAcker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* 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.client.impl; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import java.util.BitSet; | ||
|
||
class BatchMessageAcker { | ||
|
||
static BatchMessageAcker newAcker(int batchSize) { | ||
BitSet bitSet = new BitSet(batchSize); | ||
bitSet.set(0, batchSize); | ||
return new BatchMessageAcker(bitSet, batchSize); | ||
} | ||
|
||
// bitset shared across messages in the same batch. | ||
private final int batchSize; | ||
private final BitSet bitSet; | ||
private boolean prevBatchCumulativelyAcked = false; | ||
|
||
BatchMessageAcker(BitSet bitSet, int batchSize) { | ||
this.bitSet = bitSet; | ||
this.batchSize = batchSize; | ||
} | ||
|
||
@VisibleForTesting | ||
BitSet getBitSet() { | ||
return bitSet; | ||
} | ||
|
||
public synchronized int getBatchSize() { | ||
return batchSize; | ||
} | ||
|
||
public synchronized boolean ackIndividual(int batchIndex) { | ||
bitSet.clear(batchIndex); | ||
return bitSet.isEmpty(); | ||
} | ||
|
||
public synchronized boolean ackCumulative(int batchIndex) { | ||
// +1 since to argument is exclusive | ||
bitSet.clear(0, batchIndex + 1); | ||
return bitSet.isEmpty(); | ||
} | ||
|
||
// debug purpose | ||
public synchronized int getOutstandingAcks() { | ||
return bitSet.cardinality(); | ||
} | ||
|
||
public void setPrevBatchCumulativelyAcked(boolean acked) { | ||
this.prevBatchCumulativelyAcked = acked; | ||
} | ||
|
||
public boolean isPrevBatchCumulativelyAcked() { | ||
return prevBatchCumulativelyAcked; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageAckerDisabled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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.client.impl; | ||
|
||
class BatchMessageAckerDisabled extends BatchMessageAcker { | ||
|
||
static final BatchMessageAckerDisabled INSTANCE = new BatchMessageAckerDisabled(); | ||
|
||
private BatchMessageAckerDisabled() { | ||
super(null, 0); | ||
} | ||
|
||
@Override | ||
public synchronized int getBatchSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean ackIndividual(int batchIndex) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean ackCumulative(int batchIndex) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getOutstandingAcks() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.