Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
Signed-off-by: gengjun-git <[email protected]>
  • Loading branch information
gengjun-git committed Feb 18, 2025
1 parent 37ab374 commit 154fd07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
55 changes: 19 additions & 36 deletions fe/fe-core/src/main/java/com/starrocks/StarRocksFE.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.starrocks.qe.CoordinatorMonitor;
import com.starrocks.qe.QeService;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.server.GracefulExitFlag;
import com.starrocks.server.RunMode;
import com.starrocks.service.ExecuteEnv;
import com.starrocks.service.FrontendOptions;
Expand All @@ -66,6 +67,8 @@
import org.apache.commons.cli.ParseException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import sun.misc.Signal;
import sun.misc.SignalHandler;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -178,8 +181,6 @@ public static void start(String starRocksDir, String pidDir, String[] args) {

ThreadPoolManager.registerAllThreadPoolMetric();

addShutdownHook();

RestoreClusterSnapshotMgr.finishRestoring();

LOG.info("FE started successfully");
Expand All @@ -196,6 +197,22 @@ public static void start(String starRocksDir, String pidDir, String[] args) {
System.exit(0);
}

private void handleGracefulExit() {
Signal.handle(new Signal("USR1"), new SignalHandler() {
@Override
public void handle(Signal sig) {
LOG.info("start to handle graceful exit");

GracefulExitFlag.markGracefulExit();



System.exit(0);
LOG.info("Successfully to handle graceful exit");
}
});
}

/*
* -v --version
* Print the version of StarRocks Frontend
Expand Down Expand Up @@ -371,38 +388,4 @@ private static boolean createAndLockPidFile(String pidFilePath) {

return false;
}

// NOTE: To avoid dead lock
// 1. never call System.exit in shutdownHook
// 2. shutdownHook cannot have lock conflict with the function calling System.exit
private static void addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOG.info("start to execute shutdown hook");
try {
Thread t = new Thread(() -> {
try {
Journal journal = GlobalStateMgr.getCurrentState().getJournal();
if (journal instanceof BDBJEJournal) {
BDBEnvironment bdbEnvironment = ((BDBJEJournal) journal).getBdbEnvironment();
if (bdbEnvironment != null) {
bdbEnvironment.flushVLSNMapping();
}
}
} catch (Throwable e) {
LOG.warn("flush vlsn mapping failed", e);
}
});

t.start();

// it is necessary to set shutdown timeout,
// because in addition to kill by user, System.exit(-1) will trigger the shutdown hook too,
// if no timeout and shutdown hook blocked indefinitely, Fe will fall into a catastrophic state.
t.join(30000);
} catch (Throwable e) {
LOG.warn("shut down hook failed", e);
}
LOG.info("shutdown hook end");
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// 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
//
// https://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 com.starrocks.server;

import java.util.concurrent.atomic.AtomicBoolean;

public class GracefulExitFlag {
private static final AtomicBoolean gracefulExit = new AtomicBoolean(false);

public static void markGracefulExit() {
gracefulExit.set(true);
}

public static boolean isGracefulExit() {
return gracefulExit.get();
}
}

0 comments on commit 154fd07

Please sign in to comment.