From 01996e6b1f3f73d24cd768427e8790d05e7bdb5a Mon Sep 17 00:00:00 2001 From: zhoujinsong Date: Fri, 6 Jun 2025 15:19:18 +0800 Subject: [PATCH 1/2] Split dispose processing of rest service and optimizing service --- .../amoro/server/AmoroServiceContainer.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java index c9d205a077..76e356289f 100644 --- a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java +++ b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java @@ -116,8 +116,9 @@ public AmoroServiceContainer() throws Exception { } public static void main(String[] args) { + AmoroServiceContainer service = null; try { - AmoroServiceContainer service = new AmoroServiceContainer(); + service = new AmoroServiceContainer(); Runtime.getRuntime() .addShutdownHook( new Thread( @@ -132,16 +133,17 @@ public static void main(String[] args) { service.waitLeaderShip(); service.startOptimizingService(); service.waitFollowerShip(); - // become follower, dispose optimizingService stop - service.stopOptimizingService(); } catch (Exception e) { LOG.error("AMS start error", e); } finally { - service.dispose(); + service.disposeOptimizingService(); } } } catch (Throwable t) { LOG.error("AMS encountered an unknown exception, will exist", t); + if (service != null) { + service.disposeRestService(); + } System.exit(1); } } @@ -209,7 +211,7 @@ private void addHandlerChain(RuntimeHandlerChain chain) { } } - public void dispose() { + public void disposeOptimizingService() { if (tableManagementServer != null && tableManagementServer.isServing()) { LOG.info("Stopping table management server..."); tableManagementServer.stop(); @@ -218,6 +220,19 @@ public void dispose() { LOG.info("Stopping optimizing server..."); optimizingServiceServer.stop(); } + if (tableService != null) { + LOG.info("Stopping table service..."); + tableService.dispose(); + tableService = null; + } + if (optimizingService != null) { + LOG.info("Stopping optimizing service..."); + optimizingService.dispose(); + optimizingService = null; + } + } + + public void disposeRestService() { if (httpServer != null) { LOG.info("Stopping http server..."); try { @@ -226,22 +241,11 @@ public void dispose() { LOG.error("Error stopping http server", e); } } - if (tableService != null) { - LOG.info("Stopping table service..."); - tableService.dispose(); - tableService = null; - } if (terminalManager != null) { LOG.info("Stopping terminal manager..."); terminalManager.dispose(); terminalManager = null; } - if (optimizingService != null) { - LOG.info("Stopping optimizing service..."); - optimizingService.dispose(); - optimizingService = null; - } - if (amsServiceMetrics != null) { amsServiceMetrics.unregister(); } @@ -250,6 +254,11 @@ public void dispose() { MetricManager.dispose(); } + public void dispose() { + disposeOptimizingService(); + disposeRestService(); + } + private void initConfig() throws Exception { LOG.info("initializing configurations..."); new ConfigurationHelper().init(); From 485d9c4bd2027a4371d080c8654414c74d72fb11 Mon Sep 17 00:00:00 2001 From: zhoujinsong Date: Fri, 6 Jun 2025 15:27:15 +0800 Subject: [PATCH 2/2] as head --- .../java/org/apache/amoro/server/AmoroServiceContainer.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java index 76e356289f..97761249bd 100644 --- a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java +++ b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java @@ -116,9 +116,8 @@ public AmoroServiceContainer() throws Exception { } public static void main(String[] args) { - AmoroServiceContainer service = null; try { - service = new AmoroServiceContainer(); + AmoroServiceContainer service = new AmoroServiceContainer(); Runtime.getRuntime() .addShutdownHook( new Thread( @@ -141,9 +140,6 @@ public static void main(String[] args) { } } catch (Throwable t) { LOG.error("AMS encountered an unknown exception, will exist", t); - if (service != null) { - service.disposeRestService(); - } System.exit(1); } }