KAFKA-14462; [16/N] Add CoordinatorLoader and CoordinatorPlayback interfaces (#13794)

This patch adds the CoordinatorLoader and the CoordinatorPlayback interfaces. The former is used to load (or rebuild) the coordinator state by replaying all the records stored in the partition. The later is the interface that must be implemented by coordinator to support replaying records.

Reviewers: Calvin Liu <caliu@confluent.io>, Justine Olshan <jolshan@confluent.io>
This commit is contained in:
David Jacot 2023-06-02 21:21:51 +02:00 committed by GitHub
parent 02fb4b882b
commit e5d67b81fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/*
* 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.kafka.coordinator.group.runtime;
import org.apache.kafka.common.TopicPartition;
import java.util.concurrent.CompletableFuture;
/**
* Interface to implement a coordinator loader. A loader reads records
* from a partition and replays them to the coordinator.
*
* @param <U> The type of the record.
*/
interface CoordinatorLoader<U> {
/**
* Loads the coordinator by reading all the records from the TopicPartition
* and applying them to the Replayable object.
*
* @param tp The TopicPartition to read from.
* @param coordinator The object to apply records to.
*/
CompletableFuture<Void> load(
TopicPartition tp,
CoordinatorPlayback<U> coordinator
);
}

View File

@ -0,0 +1,36 @@
/*
* 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.kafka.coordinator.group.runtime;
/**
* The CoordinatorPlayback interface. This interface is used to replay
* records to the coordinator in order to update its state. This is
* also used to rebuild a coordinator state from scratch by replaying
* all records stored in the partition.
*
* @param <U> The type of the record.
*/
public interface CoordinatorPlayback<U> {
/**
* Applies the given record to this object.
*
* @param record A record.
* @throws RuntimeException if the record can not be applied.
*/
void replay(U record) throws RuntimeException;
}