From 0ddd635166331da43db63a0f99337fefd6eda3e1 Mon Sep 17 00:00:00 2001 From: xiangguangyxg Date: Mon, 30 Dec 2024 20:30:39 +0800 Subject: [PATCH] [Enhancement] Support fe starting with only image no bdb log Signed-off-by: xiangguangyxg --- .../journal/bdbje/BDBEnvironment.java | 22 +++++++++++-------- .../com/starrocks/server/GlobalStateMgr.java | 11 +--------- .../journal/bdbje/BDBEnvironmentTest.java | 20 ++++++++--------- .../journal/bdbje/BDBJEJournalTest.java | 2 +- .../journal/bdbje/BDBJournalCursorTest.java | 2 +- 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/journal/bdbje/BDBEnvironment.java b/fe/fe-core/src/main/java/com/starrocks/journal/bdbje/BDBEnvironment.java index 0faa4380623f7..c7caed7b05d0c 100644 --- a/fe/fe-core/src/main/java/com/starrocks/journal/bdbje/BDBEnvironment.java +++ b/fe/fe-core/src/main/java/com/starrocks/journal/bdbje/BDBEnvironment.java @@ -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 helperNode = GlobalStateMgr.getCurrentState().getNodeMgr().getHelperNode(); @@ -147,7 +149,7 @@ public static BDBEnvironment initBDBEnvironment(String nodeName) throws JournalE helperHostPort, GlobalStateMgr.getCurrentState().isElectable()); // setup - bdbEnvironment.setup(); + bdbEnvironment.setup(isFirstTimeStartUp); return bdbEnvironment; } @@ -165,14 +167,14 @@ 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) { @@ -180,10 +182,12 @@ protected void initConfigs(boolean isElectable) throws JournalException { 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 diff --git a/fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java b/fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java index 83ba6f6645a07..32ebad1a9122f 100644 --- a/fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java +++ b/fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java @@ -1265,16 +1265,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(); } diff --git a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBEnvironmentTest.java b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBEnvironmentTest.java index 0c3599f308a1e..961313524f297 100644 --- a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBEnvironmentTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBEnvironmentTest.java @@ -88,7 +88,7 @@ public void testSetupStandalone() throws Exception { selfNodeHostPort, selfNodeHostPort, true); - environment.setup(); + environment.setup(true); CloseSafeDatabase db = environment.openDatabase("testdb"); DatabaseEntry key = randomEntry(); @@ -117,7 +117,7 @@ public void testSetupStandaloneMultitimes() throws Exception { selfNodeHostPort, selfNodeHostPort, true); - environment.setup(); + environment.setup(true); } Assert.fail(); } finally { @@ -173,7 +173,7 @@ private void initClusterMasterFollowerNoRetry() throws Exception { leaderNodeHostPort, leaderNodeHostPort, true); - leaderEnvironment.setup(); + leaderEnvironment.setup(true); Assert.assertEquals(0, leaderEnvironment.getDatabaseNames().size()); // set up 2 followers @@ -188,7 +188,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; @@ -243,7 +243,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); } @@ -268,7 +268,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; } @@ -282,7 +282,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); @@ -335,7 +335,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 @@ -348,7 +348,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); } @@ -370,7 +370,7 @@ public void testGetDatabase() throws Exception { selfNodeHostPort, selfNodeHostPort, true); - environment.setup(); + environment.setup(true); new MockUp() { @Mock diff --git a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJEJournalTest.java b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJEJournalTest.java index 758f077ebf61c..78509918961b3 100644 --- a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJEJournalTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJEJournalTest.java @@ -88,7 +88,7 @@ private BDBEnvironment initBDBEnv(String name) throws Exception { selfNodeHostPort, selfNodeHostPort, true); - environment.setup(); + environment.setup(true); return environment; } diff --git a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJournalCursorTest.java b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJournalCursorTest.java index e77615651a941..12b369ac3baf2 100644 --- a/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJournalCursorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/journal/bdbje/BDBJournalCursorTest.java @@ -85,7 +85,7 @@ private BDBEnvironment initBDBEnv() throws Exception { selfNodeHostPort, selfNodeHostPort, true); - environment.setup(); + environment.setup(true); return environment; }