Skip to content

Commit

Permalink
[Enhancement] Support fe starting with only image no bdb log (backport
Browse files Browse the repository at this point in the history
…#54514) (#54548)

Signed-off-by: xiangguangyxg <[email protected]>
Co-authored-by: xiangguangyxg <[email protected]>
  • Loading branch information
mergify[bot] and xiangguangyxg authored Dec 31, 2024
1 parent b0eb44b commit 8f16a92
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ public static BDBEnvironment initBDBEnvironment(String nodeName) throws JournalE

// constructor
String selfNodeHostPort = NetUtils.getHostPortInAccessibleFormat(selfNode.first, selfNode.second);

boolean isFirstTimeStartUp = false;

File dbEnv = new File(getBdbDir());
if (!dbEnv.exists()) {
dbEnv.mkdirs();
isFirstTimeStartUp = true;
}

Pair<String, Integer> helperNode = GlobalStateMgr.getCurrentState().getNodeMgr().getHelperNode();
Expand All @@ -147,7 +149,7 @@ public static BDBEnvironment initBDBEnvironment(String nodeName) throws JournalE
helperHostPort, GlobalStateMgr.getCurrentState().isElectable());

// setup
bdbEnvironment.setup();
bdbEnvironment.setup(isFirstTimeStartUp);
return bdbEnvironment;
}

Expand All @@ -165,25 +167,27 @@ protected BDBEnvironment(File envHome, String selfNodeName, String selfNodeHostP
}

// The setup() method opens the environment and database
protected void setup() throws JournalException, InterruptedException {
protected void setup(boolean isFirstTimeStartUp) throws JournalException, InterruptedException {
this.closing = false;
ensureHelperInLocal();
initConfigs(isElectable);
initConfigs(isFirstTimeStartUp);
setupEnvironment();
}

protected void initConfigs(boolean isElectable) throws JournalException {
protected void initConfigs(boolean isFirstTimeStartUp) throws JournalException {
// Almost never used, just in case the master can not restart
if (Config.bdbje_reset_election_group) {
if (!isElectable) {
String errMsg = "Current node is not in the electable_nodes list. will exit";
LOG.error(errMsg);
throw new JournalException(errMsg);
}
DbResetRepGroup resetUtility = new DbResetRepGroup(envHome, STARROCKS_JOURNAL_GROUP, selfNodeName,
selfNodeHostPort);
resetUtility.reset();
LOG.info("group has been reset.");
if (!isFirstTimeStartUp) {
DbResetRepGroup resetUtility = new DbResetRepGroup(envHome, STARROCKS_JOURNAL_GROUP, selfNodeName,
selfNodeHostPort);
resetUtility.reset();
LOG.info("group has been reset.");
}
}

// set replication config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,16 +1264,7 @@ private void transferToLeader() {
dominationStartTimeMs = System.currentTimeMillis();

try {
// Log the first frontend
if (nodeMgr.isFirstTimeStartUp()) {
// if isFirstTimeStartUp is true, frontends must contain this Node.
Frontend self = nodeMgr.getMySelf();
Preconditions.checkNotNull(self);
// OP_ADD_FIRST_FRONTEND is emitted, so it can write to BDBJE even if canWrite is false
editLog.logAddFirstFrontend(self);
}

if (Config.bdbje_reset_election_group) {
if (Config.bdbje_reset_election_group || nodeMgr.isFirstTimeStartUp()) {
nodeMgr.resetFrontends();
}

Expand Down
6 changes: 6 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/server/NodeMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,19 @@ public void resetFrontends() {
frontends.clear();
Frontend self = new Frontend(role, nodeName, selfNode.first, selfNode.second);
frontends.put(self.getNodeName(), self);
// reset helper nodes
helperNodes.clear();
helperNodes.add(selfNode);

GlobalStateMgr.getCurrentState().getEditLog().logResetFrontends(self);
}

public void replayResetFrontends(Frontend frontend) {
frontends.clear();
frontends.put(frontend.getNodeName(), frontend);
// reset helper nodes
helperNodes.clear();
helperNodes.add(Pair.create(frontend.getHost(), frontend.getEditLogPort()));
}

public void save(ImageWriter imageWriter) throws IOException, SRMetaBlockException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testSetupStandalone() throws Exception {
selfNodeHostPort,
selfNodeHostPort,
true);
environment.setup();
environment.setup(true);

CloseSafeDatabase db = environment.openDatabase("testdb");
DatabaseEntry key = randomEntry();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void testSetupStandaloneMultitimes() throws Exception {
selfNodeHostPort,
selfNodeHostPort,
true);
environment.setup();
environment.setup(true);
}
Assert.fail();
} finally {
Expand Down Expand Up @@ -171,7 +171,7 @@ private void initClusterMasterFollowerNoRetry() throws Exception {
leaderNodeHostPort,
leaderNodeHostPort,
true);
leaderEnvironment.setup();
leaderEnvironment.setup(true);
Assert.assertEquals(0, leaderEnvironment.getDatabaseNames().size());

// set up 2 followers
Expand All @@ -186,7 +186,7 @@ private void initClusterMasterFollowerNoRetry() throws Exception {
leaderNodeHostPort,
true);
followerEnvironments[i] = followerEnvironment;
followerEnvironment.setup();
followerEnvironment.setup(true);
Assert.assertEquals(0, followerEnvironment.getDatabaseNames().size());
}
BDBEnvironment.RETRY_TIME = 3;
Expand Down Expand Up @@ -230,7 +230,7 @@ public void testNormalCluster() throws Exception {
findUnbindHostPort(),
leaderNodeHostPort,
false);
observerEnvironment.setup();
observerEnvironment.setup(true);

// observer read
Assert.assertEquals(1, observerEnvironment.getDatabaseNames().size());
Expand Down Expand Up @@ -299,7 +299,7 @@ public void checkForNullParam(final Object param, final String name) {
true);
Assert.assertTrue(true);
try {
maserEnvironment.setup();
maserEnvironment.setup(true);
} catch (JournalException e) {
LOG.warn("got Rollback Exception, as expect, ", e);
}
Expand All @@ -324,7 +324,7 @@ private void leaderFailOver() throws Exception {
if (followerEnvironments[i].getReplicatedEnvironment().getState() == ReplicatedEnvironment.State.MASTER) {
newMasterEnvironment = followerEnvironments[i];
LOG.warn("=========> new leader is {}", newMasterEnvironment.getReplicatedEnvironment().getNodeName());
newMasterEnvironment.setup();
newMasterEnvironment.setup(true);
newMasterFollowerIndex = i;
break;
}
Expand All @@ -338,7 +338,7 @@ private void leaderFailOver() throws Exception {
leaderNodeHostPort,
leaderNodeHostPort,
true);
oldMasterEnvironment.setup();
oldMasterEnvironment.setup(true);
LOG.warn("============> old leader is setup as follower");
Thread.sleep(1000);

Expand Down Expand Up @@ -391,7 +391,7 @@ protected void testAddBadFollowerBase(boolean failover) throws Exception {
true);
LOG.warn("=========> start new follower for the first time");
// should set up successfully as a standalone leader
newfollowerEnvironment.setup();
newfollowerEnvironment.setup(true);
newfollowerEnvironment.close();

// 2. bad new follower start for the second time
Expand All @@ -404,7 +404,7 @@ protected void testAddBadFollowerBase(boolean failover) throws Exception {
true);
LOG.warn("==========> start new follower for the second time");
try {
newfollowerEnvironment.setup();
newfollowerEnvironment.setup(true);
} catch (Exception e) {
LOG.warn("===========> failed for the second time, as expect, ", e);
}
Expand All @@ -426,7 +426,7 @@ public void testGetDatabase() throws Exception {
selfNodeHostPort,
selfNodeHostPort,
true);
environment.setup();
environment.setup(true);

new MockUp<ReplicatedEnvironment>() {
@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private BDBEnvironment initBDBEnv(String name) throws Exception {
selfNodeHostPort,
selfNodeHostPort,
true);
environment.setup();
environment.setup(true);
return environment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private BDBEnvironment initBDBEnv() throws Exception {
selfNodeHostPort,
selfNodeHostPort,
true);
environment.setup();
environment.setup(true);
return environment;
}

Expand Down

0 comments on commit 8f16a92

Please sign in to comment.