Skip to content

Conversation

@adixitconfluent
Copy link
Contributor

About

This PR performs a refactor of SharePartition.java acquire functionality. The functionality had become quite huge and adding new code in this method looks daunting. Hence, I have refactored the code to use Strategy design pattern to distinguish code for acquire mode thereby creating a clean separation between acquisition modes

Testing

The originally present unit and integrayion tests should cover this change.

@adixitconfluent adixitconfluent marked this pull request as draft January 7, 2026 10:15
@github-actions github-actions bot added triage PRs from the community core Kafka Broker KIP-932 Queues for Kafka labels Jan 7, 2026
@adixitconfluent adixitconfluent marked this pull request as ready for review January 7, 2026 10:31
@AndrewJSchofield AndrewJSchofield removed the triage PRs from the community label Jan 8, 2026
Copy link
Contributor

@apoorvmittal10 apoorvmittal10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refactor, left a comment regarding APIs in AcquireStrategy.

Though it's a good refactor and I ll invest more time going through it.

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.server.share.fetch.acquire;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the package should be fetch itself. Same for other classes in the PR.

Suggested change
package org.apache.kafka.server.share.fetch.acquire;
package org.apache.kafka.server.share.fetch;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I created acquire package inside fetch was since these are 5 new classes already which are specific to acquire itself and with more refactors in the future, the classes under acquire will only increase, hence I thought to segregate it. I am open to changing it if you think otherwise.

Comment on lines +46 to +50
public boolean requiresSubsetMatch(InFlightBatch inFlightBatch, int maxRecordsToAcquire, int acquiredCount) {
// batch_optimized mode doesn't force subset matching based on record count alone.
// Subset matching is determined by other factors (fullMatch, offsetState, throttling).
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not needed in BatchOptimized mode then this API is not needed in interface. Remove the method from interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is exposed to SharePartition and determines if the in-flight batch requires subset matching based on the acquire mode. In a way it decides if you need to maintain the in-flight batch at per offset level and acquire only a subset of those offsets or you should be good with the entire batch. Hence, it is needed in the interface itself.

* creating a single batch only.</li>
* </ul>
*/
public interface AcquireStrategy {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just on a high level, not totally aligned with the APIs exposed here in the method. I was thinking that you just need one method acquire which shall process as per the Strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of the refactor is to move the code only which is different for the strategies. If we move the entire acquire logic outside SharePartition, there will be a lot of duplicate code that we need to manage. Also, for adding new strategy, we will require more code to implement it along with possible duplication of some code. Hence, the best idea to me was to decide the places in acquire which are different and acordingly design the APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved core Kafka Broker KIP-932 Queues for Kafka

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants