Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: controller handles planned termination #457

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class BrokerConfig implements ControllerConfig {

private final DatabaseConfig db;

private boolean terminating;

public BrokerConfig() {
this.metrics = new MetricsConfig();
this.proxy = new ProxyConfig();
Expand Down Expand Up @@ -206,6 +208,11 @@ public String advertiseAddress() {
return advertiseAddress;
}

@Override
public boolean goingAway() {
return terminating;
}

public void setName(String name) {
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ default int workloadTolerance() {

String dbPassword();

boolean goingAway();

}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void heartbeat() {

try {
String target = leaderAddress();
controllerClient.heartbeat(target, config.nodeId(), config.epoch(), false)
controllerClient.heartbeat(target, config.nodeId(), config.epoch(), config.goingAway())
.whenComplete((r, e) -> {
if (null != e) {
LOGGER.error("Failed to maintain heartbeat to {}", target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public void process() throws ControllerException {
// Someone must have won the leader election campaign.
return;
}

if (metadataStore.config().goingAway()) {
LOGGER.info("Current node is terminating thus should stop renewing its leadership lease");
return;
}

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, metadataStore.config().leaseLifeSpanInSecs());
update.setExpirationTime(calendar.getTime());
Expand All @@ -70,6 +76,11 @@ public void process() throws ControllerException {
lease.getNodeId(), lease.getEpoch(), lease.getExpirationTime());
}
} else {
if (metadataStore.config().goingAway()) {
LOGGER.debug("Current node is terminating and will not campaign for leadership");
return;
}

// Perform leader election campaign
Lease update = leaseMapper.currentWithWriteLock();
if (lease.getEpoch() == update.getEpoch() && lease.getNodeId() == update.getNodeId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public DatabaseTestBase() {
Mockito.when(config.deletedGroupLingersInSecs()).thenCallRealMethod();
Mockito.when(config.balanceWorkloadIntervalInSecs()).thenCallRealMethod();
Mockito.when(config.recycleS3IntervalInSecs()).thenCallRealMethod();
Mockito.when(config.goingAway()).thenReturn(false);
gson = new GsonBuilder()
.registerTypeAdapter(SubStream.class, new SubStreamSerializer())
.registerTypeAdapter(SubStream.class, new SubStreamDeserializer())
Expand Down
6 changes: 3 additions & 3 deletions distribution/conf/broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ innerSecretKey: ""
s3Stream:
s3WALPath: "/tmp/s3rocketmq/wal"
s3Endpoint: "http://minio.hellocorp.test"
s3Bucket: "lzh"
s3Bucket: "lizhanhui"
s3Region: "us-east-1"
s3ForcePathStyle: true
s3AccessKey: "mcFoJPLvxNmRq497dhK0"
s3SecretKey: "UU7PE0VOo3fRtqYEBeIIQzOSGFT3GctuiLoZg2hY"
s3AccessKey: "kicaSWtNBPf7XCCsdW8Z"
s3SecretKey: "dgWxasHBEQBBXxAxBpFmp4VWIoQ0XyDU3gGdFnaT"
db:
url: "jdbc:mysql://mysql-server:3306/metadata"
userName: "root"
Expand Down