sumitagrawl commented on code in PR #8938: URL: https://github.com/apache/ozone/pull/8938#discussion_r2276322221
########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/upgrade/NSSummaryAggregatedTotalsUpgrade.java: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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 org.apache.hadoop.ozone.recon.upgrade; + +import static org.apache.hadoop.ozone.recon.upgrade.ReconUpgradeAction.UpgradeActionType.FINALIZE; + +import javax.sql.DataSource; +import com.google.inject.Injector; +import org.apache.hadoop.ozone.recon.ReconGuiceServletContextListener; +import org.apache.hadoop.ozone.recon.ReconUtils; +import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager; +import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Upgrade action that triggers a rebuild of the NSSummary tree to + * populate materialized totals upon upgrade to the feature version. + * + * This runs at FINALIZE and schedules the rebuild asynchronously so + * Recon startup is not blocked. During rebuild, APIs that depend on + * the tree may return initializing responses as designed. + */ +@UpgradeActionRecon(feature = ReconLayoutFeature.NSSUMMARY_AGGREGATED_TOTALS, type = FINALIZE) +public class NSSummaryAggregatedTotalsUpgrade implements ReconUpgradeAction { + + private static final Logger LOG = LoggerFactory.getLogger(NSSummaryAggregatedTotalsUpgrade.class); + + @Override + public void execute(DataSource source) throws Exception { + // Resolve required services from Guice + Injector injector = ReconGuiceServletContextListener.getGlobalInjector(); + if (injector == null) { + // Should not happen since ReconServer sets the injector before finalize call + LOG.warn("Guice injector not initialized yet; skipping NSSummary rebuild at upgrade."); + return; Review Comment: It should throw exception if injector is not initalized, code issue ########## hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java: ########## @@ -131,9 +132,36 @@ public static boolean triggerAsyncNSSummaryRebuild( ReconNamespaceSummaryManager reconNamespaceSummaryManager, ReconOMMetadataManager omMetadataManager) { + // Check if a rebuild is already in progress + if (getNSSummaryRebuildState() == NSSummaryTask.RebuildState.RUNNING) { + log.info("NSSummary rebuild already in progress; skipping duplicate trigger."); + return false; + } + // Submit rebuild task to single thread executor for async execution NSSUMMARY_REBUILD_EXECUTOR.submit(() -> { try { + // Wait for OM tables to be initialized before proceeding + long maxWaitMillis = 300_000L; // 5 minutes + long waited = 0L; + long waitInterval = 1000L; // 1 second + + while (!omMetadataManager.isOmTablesInitialized() && waited < maxWaitMillis) { Review Comment: under what case its not initialized? I think should be initailized before calling and this wait might not be required. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
