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.
Group metadata manager & coordinator (#23)
Master Issue: #4 *Motivation* Support Kafka group coordinator protocols.
- Loading branch information
Showing
12 changed files
with
2,205 additions
and
13 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/io/streamnative/kop/coordinator/group/DelayedHeartbeat.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,58 @@ | ||
/** | ||
* Licensed 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 io.streamnative.kop.coordinator.group; | ||
|
||
import io.streamnative.kop.utils.delayed.DelayedOperation; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Delayed heartbeat operations that are added to the purgatory for session timeout checking. | ||
* Heartbeats are paused during rebalance. | ||
*/ | ||
class DelayedHeartbeat extends DelayedOperation { | ||
|
||
private final GroupCoordinator coordinator; | ||
private final GroupMetadata group; | ||
private final MemberMetadata member; | ||
private long heartbeatDeadline; | ||
|
||
DelayedHeartbeat(GroupCoordinator coordinator, | ||
GroupMetadata group, | ||
MemberMetadata member, | ||
long heartbeatDeadline, | ||
long sessionTimeout) { | ||
super(sessionTimeout, Optional.of(group.lock())); | ||
|
||
this.coordinator = coordinator; | ||
this.group = group; | ||
this.member = member; | ||
this.heartbeatDeadline = heartbeatDeadline; | ||
} | ||
|
||
@Override | ||
public void onExpiration() { | ||
coordinator.onExpireHeartbeat(group, member, heartbeatDeadline); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
coordinator.onCompleteHeartbeat(); | ||
} | ||
|
||
@Override | ||
public boolean tryComplete() { | ||
return coordinator.tryCompleteHeartbeat(group, member, heartbeatDeadline, () -> forceComplete()); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/io/streamnative/kop/coordinator/group/DelayedJoin.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,57 @@ | ||
/** | ||
* Licensed 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 io.streamnative.kop.coordinator.group; | ||
|
||
import io.streamnative.kop.utils.delayed.DelayedOperation; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Delayed rebalance operations that are added to the purgatory when group is preparing for rebalance. | ||
* | ||
* <p>Whenever a join-group request is received, check if all known group members have requested | ||
* to re-join the group; if yes, complete this operation to proceed rebalance. | ||
* | ||
* <p>When the operation has expired, any known members that have not requested to re-join | ||
* the group are marked as failed, and complete this operation to proceed rebalance with | ||
* the rest of the group. | ||
*/ | ||
class DelayedJoin extends DelayedOperation { | ||
|
||
final GroupCoordinator coordinator; | ||
final GroupMetadata group; | ||
|
||
protected DelayedJoin(GroupCoordinator coordinator, | ||
GroupMetadata group, | ||
long rebalanceTimeout) { | ||
super(rebalanceTimeout, Optional.of(group.lock())); | ||
this.coordinator = coordinator; | ||
this.group = group; | ||
} | ||
|
||
@Override | ||
public void onExpiration() { | ||
coordinator.onExpireJoin(); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
coordinator.onCompleteJoin(group); | ||
} | ||
|
||
@Override | ||
public boolean tryComplete() { | ||
return coordinator.tryCompleteJoin(group, () -> forceComplete()); | ||
} | ||
|
||
} |
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.