flink源碼閱讀---local啓動流程

啓動腳本:

 start-cluster.sh

bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
. "$bin"/config.sh
# Start the JobManager instance(s)
shopt -s nocasematch
if [[ $HIGH_AVAILABILITY == "zookeeper" ]]; then
    # HA Mode
    readMasters
    echo "Starting HA cluster with ${#MASTERS[@]} masters."
    for ((i=0;i<${#MASTERS[@]};++i)); do
        master=${MASTERS[i]}
        webuiport=${WEBUIPORTS[i]}
        if [ ${MASTERS_ALL_LOCALHOST} = true ] ; then
            "${FLINK_BIN_DIR}"/jobmanager.sh start "${master}" "${webuiport}"
        else
            ssh -n $FLINK_SSH_OPTS $master -- "nohup /bin/bash -l \"${FLINK_BIN_DIR}/jobmanager.sh\" start ${master} ${webuiport} &"
        fi
    done
else
    echo "Starting cluster."
    # Start single JobManager on this machine
    "$FLINK_BIN_DIR"/jobmanager.sh start
fi
shopt -u nocasematch
# Start TaskManager instance(s)
TMSlaves start

可以看到start-cluster.sh調用了jobmanager.sh和taskmanager.sh,其中jobmanager.sh又調用了flink-daemon.sh,flink-daemon.sh接着調用org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint,如下圖:

case $DAEMON in
    (taskexecutor)
        CLASS_TO_RUN=org.apache.flink.runtime.taskexecutor.TaskManagerRunner
    ;;

    (zookeeper)
        CLASS_TO_RUN=org.apache.flink.runtime.zookeeper.FlinkZooKeeperQuorumPeer
    ;;

    (historyserver)
        CLASS_TO_RUN=org.apache.flink.runtime.webmonitor.history.HistoryServer
    ;;

    (standalonesession)
        CLASS_TO_RUN=org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint
    ;;

    (standalonejob)
        CLASS_TO_RUN=org.apache.flink.container.entrypoint.StandaloneJobClusterEntryPoint
    ;;

    (*)
        echo "Unknown daemon '${DAEMON}'. $USAGE."
        exit 1
    ;;
esac
$JAVA_RUN $JVM_ARGS ${FLINK_ENV_JAVA_OPTS} "${log_setting[@]}" -classpath "`manglePathList "$FLINK_TM_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" ${CLASS_TO_RUN} "${ARGS[@]}" > "$out" 200<&- 2>&1 < /dev/null &

taskmanager.sh環境變量ENTRYPOINT=taskexecutor,所以調用org.apache.flink.runtime.taskexecutor.TaskManagerRunner;

java程序啓動

StandaloneSessionClusterEntrypoint

配置啓動如下:

main函數入口

main函數入口,主要是解析傳入參數生成configuration配置,然後生成StandaloneSessionClusterEntrypoint對象,調用

StandaloneSessionClusterEntrypoint對象的runClusterEntrypoint方法啓動集羣,如下圖:

啓動集羣

啓動集羣調用的clusterEntrypoint.startCluster(),該方法主要是加載plugins、配置文件系統、設置securitycontext、最後調用securitycontext.runSecured()啓動集羣服務

啓動集羣服務

集羣服務啓動調用ClusterEntrypoint對象的runCluster方法,該方法主要初始化服務並啓動服務,如下圖:

ioExecutor:
 Executors.newFixedThreadPool( ClusterEntrypointUtils.getPoolSize(configuration), new ExecutorThreadFactory("cluster-io"))

haServices = createHaServices(configuration, ioExecutor);

blobServer = new BlobServer(configuration, haServices.createBlobStore());
blobServer.start();
heartbeatServices = createHeartbeatServices(configuration);
metricRegistry = createMetricRegistry(configuration, pluginManager);
processMetricGroup = MetricUtils.instantiateProcessMetricGroup(
   metricRegistry,
   hostname,
   ConfigurationUtils.getSystemResourceMetricsProbingInterval(configuration));
archivedExecutionGraphStore = createSerializableExecutionGraphStore(configuration, commonRpcService.getScheduledExecutor());
DispatcherResourceManagerComponentFactory //啓動了{@link Dispatcher}、{@link ResourceManager}和{@link WebMonitorEndpoint}

在同樣的過程中

TaskManagerRunner

main函數入口

main函數主要是解析環境變量,獲取最大打開文件句柄數,接着調用runTaskManagerSecurely啓動taskmanager

啓動集羣:、

啓動taskmanager和jobmanager前兩步邏輯一樣,最後異步調用runTaskManager啓動集羣服務

啓動集羣服務:

至此,flink集羣已經啓動,可以打開自己的瀏覽器,輸入url地址查看信息如下:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章