Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public Injector getInjector() {
static void setInjector(Injector inj) {
injector = inj;
}

/**
* Expose injector for internal upgrade actions that run outside Jersey.
*/
public static Injector getGlobalInjector() {
return injector;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ public Void call() throws Exception {
reconSchemaManager.createReconSchema();
LOG.debug("Recon schema creation done.");

LOG.info("Finalizing Layout Features.");
// Handle Recon Schema Versioning
ReconSchemaVersionTableManager versionTableManager =
injector.getInstance(ReconSchemaVersionTableManager.class);
DataSource dataSource = injector.getInstance(DataSource.class);

ReconLayoutVersionManager layoutVersionManager =
new ReconLayoutVersionManager(versionTableManager, reconContext, dataSource);
// Run the upgrade framework to finalize layout features if needed
layoutVersionManager.finalizeLayoutFeatures();

LOG.info("Recon schema versioning completed.");

this.reconSafeModeMgr = injector.getInstance(ReconSafeModeManager.class);
this.reconSafeModeMgr.setInSafeMode(true);
httpServer = injector.getInstance(ReconHttpServer.class);
Expand All @@ -177,6 +164,20 @@ public Void call() throws Exception {
// Start all services
start();
isStarted = true;

LOG.info("Finalizing Layout Features.");
// Handle Recon Schema Versioning
ReconSchemaVersionTableManager versionTableManager =
injector.getInstance(ReconSchemaVersionTableManager.class);
DataSource dataSource = injector.getInstance(DataSource.class);

ReconLayoutVersionManager layoutVersionManager =
new ReconLayoutVersionManager(versionTableManager, reconContext, dataSource);
// Run the upgrade framework to finalize layout features if needed
layoutVersionManager.finalizeLayoutFeatures();

LOG.info("Recon schema versioning completed.");

LOG.info("Recon server initialized successfully!");
} catch (Exception e) {
LOG.error("Error during initializing Recon server.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ public static org.apache.hadoop.ozone.recon.tasks.NSSummaryTask.RebuildState get
public static boolean triggerAsyncNSSummaryRebuild(
ReconNamespaceSummaryManager reconNamespaceSummaryManager,
ReconOMMetadataManager omMetadataManager) {

// Submit rebuild task to single thread executor for async execution
NSSUMMARY_REBUILD_EXECUTOR.submit(() -> {
try {

// This will go through NSSummaryTask's unified control mechanism
reconNamespaceSummaryManager.rebuildNSSummaryTree(omMetadataManager);
log.info("Async NSSummary tree rebuild completed successfully.");
Expand All @@ -142,7 +143,6 @@ public static boolean triggerAsyncNSSummaryRebuild(
}
});

log.info("Async NSSummary tree rebuild triggered successfully.");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 com.google.inject.Injector;
import javax.sql.DataSource;
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) {
throw new IllegalStateException(
"Guice injector not initialized. NSSummary rebuild cannot proceed during upgrade.");
}

ReconNamespaceSummaryManager nsMgr = injector.getInstance(ReconNamespaceSummaryManager.class);
ReconOMMetadataManager omMgr = injector.getInstance(ReconOMMetadataManager.class);

// Fire and forget: unified control using ReconUtils -> NSSummaryTask
LOG.info("Triggering asynchronous NSSummary tree rebuild for materialized totals (upgrade action).");
ReconUtils.triggerAsyncNSSummaryRebuild(nsMgr, omMgr);
}

@Override
public UpgradeActionType getType() {
return FINALIZE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public enum ReconLayoutFeature {
// Represents the starting point for Recon's layout versioning system.
INITIAL_VERSION(0, "Recon Layout Versioning Introduction"),
TASK_STATUS_STATISTICS(1, "Recon Task Status Statistics Tracking Introduced"),
UNHEALTHY_CONTAINER_REPLICA_MISMATCH(2, "Adding replica mismatch state to the unhealthy container table");
UNHEALTHY_CONTAINER_REPLICA_MISMATCH(2, "Adding replica mismatch state to the unhealthy container table"),

// HDDS-13432: Materialize NSSummary totals and rebuild tree on upgrade
NSSUMMARY_AGGREGATED_TOTALS(3, "Aggregated totals for NSSummary and auto-rebuild on upgrade");

private final int version;
private final String description;
Expand Down