Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -90,7 +90,7 @@ private void insertInitialSLV(DSLContext dslContext, int slv) {
dslContext.insertInto(DSL.table(SCHEMA_VERSION_TABLE_NAME))
.columns(DSL.field(name("version_number")),
DSL.field(name("applied_on")))
.values(slv, DSL.currentTimestamp())
.values(2, DSL.currentTimestamp())
.execute();
LOG.info("Inserted initial SLV '{}' into SchemaVersion table.", slv);
}
Expand Down
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 @@ -81,6 +81,7 @@
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
import org.apache.hadoop.ozone.recon.scm.ReconContainerReportQueue;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.apache.hadoop.ozone.recon.tasks.NSSummaryTask;
import org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.apache.ozone.recon.schema.generated.tables.daos.GlobalStatsDao;
import org.apache.ozone.recon.schema.generated.tables.pojos.GlobalStats;
Expand Down Expand Up @@ -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) {
try {
Thread.sleep(waitInterval);
waited += waitInterval;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("Interrupted while waiting for OM tables initialization");
return;
}
}

if (waited >= maxWaitMillis) {
log.warn("OM tables not initialized after {} ms; skipping NSSummary rebuild trigger.", maxWaitMillis);
return;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

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