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.
Introduce batch message container framework and support key based bat…
…ching container (apache#4435) ### Motivation Introduce batch message container framework to support multiple ways to do message batch. Currently, pulsar support a most basic batch message container, use the batch message container framework can quickly implement other types batch message container, even users can customize their own batch message container. Add a new batch message container named BatchMessageKeyBasedContainer to support batching message in key_shared subscription mode.
- Loading branch information
1 parent
34f1a58
commit b45736a
Showing
18 changed files
with
914 additions
and
275 deletions.
There are no files selected for viewing
163 changes: 128 additions & 35 deletions
163
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
64 changes: 64 additions & 0 deletions
64
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/BatchMessageContainer.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,64 @@ | ||
/** | ||
* 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.api; | ||
|
||
/** | ||
* Batch message container for individual messages being published until they are batched and sent to broker | ||
*/ | ||
public interface BatchMessageContainer { | ||
|
||
/** | ||
* Clear the message batch container. | ||
*/ | ||
void clear(); | ||
|
||
/** | ||
* Check the message batch container is empty. | ||
* | ||
* @return return true if empty, otherwise return false. | ||
*/ | ||
boolean isEmpty(); | ||
|
||
/** | ||
* Get count of messages in the message batch container. | ||
* | ||
* @return messages count | ||
*/ | ||
int getNumMessagesInBatch(); | ||
|
||
/** | ||
* Get current message batch size of the message batch container in bytes. | ||
* | ||
* @return message batch size in bytes | ||
*/ | ||
long getCurrentBatchSize(); | ||
|
||
/** | ||
* Release the payload and clear the container. | ||
* | ||
* @param ex cause | ||
*/ | ||
void discard(Exception ex); | ||
|
||
/** | ||
* Return the batch container batch message in multiple batches | ||
* @return | ||
*/ | ||
boolean isMultiBatches(); | ||
} |
56 changes: 56 additions & 0 deletions
56
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/BatcherBuilder.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,56 @@ | ||
/** | ||
* 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.api; | ||
|
||
import org.apache.pulsar.client.internal.DefaultImplementation; | ||
|
||
/** | ||
* Batcher builder | ||
*/ | ||
public interface BatcherBuilder { | ||
|
||
/** | ||
* Default batch message container | ||
* | ||
* incoming single messages: | ||
* (k1, v1), (k2, v1), (k3, v1), (k1, v2), (k2, v2), (k3, v2), (k1, v3), (k2, v3), (k3, v3) | ||
* | ||
* batched into single batch message: | ||
* [(k1, v1), (k2, v1), (k3, v1), (k1, v2), (k2, v2), (k3, v2), (k1, v3), (k2, v3), (k3, v3)] | ||
*/ | ||
BatcherBuilder DEFAULT = DefaultImplementation.newDefaultBatcherBuilder(); | ||
|
||
/** | ||
* Key based batch message container | ||
* | ||
* incoming single messages: | ||
* (k1, v1), (k2, v1), (k3, v1), (k1, v2), (k2, v2), (k3, v2), (k1, v3), (k2, v3), (k3, v3) | ||
* | ||
* batched into multiple batch messages: | ||
* [(k1, v1), (k1, v2), (k1, v3)], [(k2, v1), (k2, v2), (k2, v3)], [(k3, v1), (k3, v2), (k3, v3)] | ||
*/ | ||
BatcherBuilder KEY_BASED = DefaultImplementation.newKeyBasedBatcherBuilder(); | ||
|
||
/** | ||
* Build a new batch message container. | ||
* @return new batch message container | ||
*/ | ||
BatchMessageContainer build(); | ||
|
||
} |
Oops, something went wrong.