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

[ISSUE #6662] Optimize the process of HA's confirmOffset calculation #6663

Merged
merged 5 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -268,6 +268,7 @@ public void changeToMaster(final int newMasterEpoch, final int syncStateSetEpoch

// Notify ha service, change to master
this.haService.changeToMaster(newMasterEpoch);
this.haService.setBrokerControllerId(this.brokerControllerId);
Copy link
Contributor

Choose a reason for hiding this comment

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

After registration is completed, the brokerControllerId is determined, and there is no need to set it every time the master is switched.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll modify this logic.


this.brokerController.getBrokerConfig().setBrokerId(MixAll.MASTER_ID);
this.brokerController.getMessageStoreConfig().setBrokerRole(BrokerRole.SYNC_MASTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
Expand All @@ -50,6 +51,7 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* SwitchAble ha service, support switch role to master or slave.
Expand All @@ -72,6 +74,8 @@ public class AutoSwitchHAService extends DefaultHAService {
private EpochFileCache epochCache;
private AutoSwitchHAClient haClient;

private Long brokerControllerId = null;

public AutoSwitchHAService() {
}

Expand Down Expand Up @@ -428,6 +432,14 @@ public void updateConfirmOffset(long confirmOffset) {
private long computeConfirmOffset() {
final Set<Long> currentSyncStateSet = getSyncStateSet();
long confirmOffset = this.defaultMessageStore.getMaxPhyOffset();
Copy link
Contributor

@fuyou001 fuyou001 Apr 28, 2023

Choose a reason for hiding this comment

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

should refactor confirmOffset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, it has been renamed to newConfirmOffset.

List<Long> idList = this.connectionList.stream().map(connection -> ((AutoSwitchHAConnection)connection).getSlaveId()).collect(Collectors.toList());
for (Long syncId : currentSyncStateSet) {
if (!idList.contains(syncId) && this.brokerControllerId != null && !Objects.equals(syncId, this.brokerControllerId)) {
LOGGER.warn("Slave {} is still in syncStateSet, but has lost its connection. So new offset can't be compute.", syncId);
return this.confirmOffset;
}
}

for (HAConnection connection : this.connectionList) {
final Long slaveId = ((AutoSwitchHAConnection) connection).getSlaveId();
if (currentSyncStateSet.contains(slaveId)) {
Expand Down Expand Up @@ -545,6 +557,14 @@ public List<EpochEntry> getEpochEntries() {
return this.epochCache.getAllEntries();
}

public Long getBrokerControllerId() {
return brokerControllerId;
}

public void setBrokerControllerId(Long brokerControllerId) {
this.brokerControllerId = brokerControllerId;
}

class AutoSwitchAcceptSocketService extends AcceptSocketService {

public AutoSwitchAcceptSocketService(final MessageStoreConfig messageStoreConfig) {
Expand Down