Improve upgrade script to separate long running resources update.

This commit is contained in:
Igor Kulikov 2024-12-27 17:15:59 +02:00
parent b9a5fd0088
commit 15d22e9e6b
4 changed files with 17 additions and 3 deletions

View File

@ -35,6 +35,8 @@ import org.thingsboard.server.service.install.migrate.TsLatestMigrateService;
import org.thingsboard.server.service.install.update.CacheCleanupService; import org.thingsboard.server.service.install.update.CacheCleanupService;
import org.thingsboard.server.service.install.update.DataUpdateService; import org.thingsboard.server.service.install.update.DataUpdateService;
import static org.thingsboard.server.service.install.update.DefaultDataUpdateService.getEnv;
@Service @Service
@Profile("install") @Profile("install")
@Slf4j @Slf4j
@ -99,6 +101,8 @@ public class ThingsboardInstallService {
if ("cassandra-latest-to-postgres".equals(upgradeFromVersion)) { if ("cassandra-latest-to-postgres".equals(upgradeFromVersion)) {
log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ..."); log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ...");
latestMigrateService.migrate(); latestMigrateService.migrate();
} else if (upgradeFromVersion.equals("3.9.0-resources")) {
installScripts.updateResourcesUsage();
} else { } else {
// TODO DON'T FORGET to update SUPPORTED_VERSIONS_FROM in DefaultDatabaseSchemaSettingsService // TODO DON'T FORGET to update SUPPORTED_VERSIONS_FROM in DefaultDatabaseSchemaSettingsService
databaseSchemaVersionService.validateSchemaSettings(); databaseSchemaVersionService.validateSchemaSettings();
@ -118,6 +122,14 @@ public class ThingsboardInstallService {
entityDatabaseSchemaService.createDatabaseIndexes(); entityDatabaseSchemaService.createDatabaseIndexes();
// Runs upgrade scripts that are not possible in plain SQL. // Runs upgrade scripts that are not possible in plain SQL.
// TODO: cleanup update code after each release // TODO: cleanup update code after each release
if (!getEnv("SKIP_RESOURCES_USAGE_MIGRATION", false)) {
installScripts.setUpdateResourcesUsage(true);
} else {
log.info("Skipping resources usage migration. Run the upgrade with fromVersion as '3.9.0-resources' to migrate");
}
if (installScripts.isUpdateResourcesUsage()) {
installScripts.updateResourcesUsage();
}
dataUpdateService.updateData(); dataUpdateService.updateData();
log.info("Updating system data..."); log.info("Updating system data...");
dataUpdateService.upgradeRuleNodes(); dataUpdateService.upgradeRuleNodes();

View File

@ -123,6 +123,9 @@ public class InstallScripts {
@Getter @Setter @Getter @Setter
private boolean updateImages = false; private boolean updateImages = false;
@Getter @Setter
private boolean updateResourcesUsage = false;
@Autowired @Autowired
private ImageService imageService; private ImageService imageService;

View File

@ -65,7 +65,6 @@ public class DefaultDataUpdateService implements DataUpdateService {
public void updateData() throws Exception { public void updateData() throws Exception {
log.info("Updating data ..."); log.info("Updating data ...");
//TODO: should be cleaned after each release //TODO: should be cleaned after each release
installScripts.updateResourcesUsage();
log.info("Data updated."); log.info("Data updated.");
} }

View File

@ -113,7 +113,7 @@ public class ResourcesUpdater {
} }
executor.shutdown(); executor.shutdown();
if (!executor.awaitTermination(10, TimeUnit.MINUTES)) { if (!executor.awaitTermination(5, TimeUnit.HOURS)) {
throw new RuntimeException("Dashboards resources update timeout"); // just in case, should happen throw new RuntimeException("Dashboards resources update timeout"); // just in case, should happen
} }
log.info("Updated {} dashboards", updatedCount); log.info("Updated {} dashboards", updatedCount);
@ -142,7 +142,7 @@ public class ResourcesUpdater {
} }
executor.shutdown(); executor.shutdown();
if (!executor.awaitTermination(10, TimeUnit.MINUTES)) { if (!executor.awaitTermination(5, TimeUnit.HOURS)) {
throw new RuntimeException("Widgets resources update timeout"); throw new RuntimeException("Widgets resources update timeout");
} }
log.info("Updated {} widgets", updatedCount); log.info("Updated {} widgets", updatedCount);