Skip to content

0006867: Made it possible to track engine uninstallation progress #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 3.16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -44,7 +44,9 @@
import org.jumpmind.db.io.DatabaseXmlUtil;
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.DatabaseInfo;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlResultsListener;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.sql.SqlScript;
Expand All @@ -59,6 +61,7 @@
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.config.INodeIdCreator;
import org.jumpmind.symmetric.db.AbstractSymmetricDialect;
import org.jumpmind.symmetric.db.ISoftwareUpgradeListener;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.ext.ISymmetricEngineLifecycle;
Expand Down Expand Up @@ -770,52 +773,97 @@ msg, getParameterService().getExternalId(), getParameterService().getNodeGroupId
}

public synchronized void uninstall() {
uninstall(new ProcessInfo());
}

public synchronized void uninstall(ProcessInfo processInfo) {
log.info("Attempting an uninstall of all SymmetricDS database objects from the database");
final int dropTriggersWeight = 20;
final int dropTablesWeight = 80;
final int totalStepCount = dropTriggersWeight + dropTablesWeight + 13;
processInfo.setTotalDataCount(totalStepCount);
stop();
processInfo.incrementCurrentDataCount();
log.info("Just cleaned {} files in the staging area during the uninstall.", getStagingManager().clean(0));
try {
String prefix = parameterService.getTablePrefix();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_GROUPLET)) != null) {
groupletService.deleteAllGrouplets();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_TRIGGER_ROUTER)) != null) {
triggerRouterService.deleteAllTriggerRouters();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_FILE_TRIGGER_ROUTER)) != null) {
fileSyncService.deleteAllFileTriggerRouters();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_ROUTER)) != null) {
triggerRouterService.deleteAllRouters();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_CONFLICT)) != null) {
dataLoaderService.deleteAllConflicts();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_TRANSFORM_TABLE)) != null) {
transformService.deleteAllTransformTables();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_ROUTER)) != null) {
triggerRouterService.deleteAllRouters();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_CONFLICT)) != null) {
dataLoaderService.deleteAllConflicts();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_NODE_GROUP_LINK)) != null) {
configurationService.deleteAllNodeGroupLinks();
}
processInfo.incrementCurrentDataCount();
if (platform.readTableFromDatabase(null, null, TableConstants.getTableName(prefix, TableConstants.SYM_LOCK)) != null) {
// this should remove all triggers because we have removed all the trigger configuration
triggerRouterService.syncTriggers(true);
}
} catch (SqlException ex) {
log.warn("Error while trying to remove triggers on tables", ex);
}
processInfo.setCurrentDataCount(dropTriggersWeight + 10);
// remove any additional triggers that may remain because they were not in trigger history
symmetricDialect.cleanupTriggers();
processInfo.incrementCurrentDataCount();
log.info("Removing SymmetricDS database objects");
symmetricDialect.dropTablesAndDatabaseObjects();
Database symSchema = ((AbstractSymmetricDialect) symmetricDialect).readSymmetricSchemaFromDatabase();
String dropTablesSql = platform.getDdlBuilder().dropTables(symSchema);
DatabaseInfo databaseInfo = platform.getDatabaseInfo();
int dropStatementsToRunCount = SqlScript.calculateTotalStatements(dropTablesSql,
databaseInfo.getSqlCommandDelimiter(), databaseInfo.isTriggersContainJava());
SqlScript dropTablesScript = new SqlScript(dropTablesSql, getSqlTemplate(), false, null);
dropTablesScript.setListener(new ISqlResultsListener() {
@Override
public void sqlBefore(String sql, int lineNumber) {
}

@Override
public void sqlApplied(String sql, int rowsUpdated, int rowsRetrieved, int lineNumber) {
processInfo.setCurrentDataCount(
Math.round((dropTablesWeight * (lineNumber + 1)) / (float) dropStatementsToRunCount) + dropTriggersWeight + 11);
}

@Override
public void sqlErrored(String sql, SqlException ex, int lineNumber, boolean dropStatement, boolean sequenceCreate) {
}
});
dropTablesScript.execute(platform.getDatabaseInfo().isRequiresAutoCommitForDdl());
processInfo.setCurrentDataCount(dropTriggersWeight + dropTablesWeight + 11);
symmetricDialect.dropRequiredDatabaseObjects();
processInfo.incrementCurrentDataCount();
// force cache to be cleared
nodeService.deleteIdentity();
parameterService.setDatabaseHasBeenInitialized(false);
processInfo.setCurrentDataCount(totalStepCount);
log.info("Finished uninstalling SymmetricDS database objects from the database");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jumpmind.symmetric.io.stage.IStagingManager;
import org.jumpmind.symmetric.job.IJobManager;
import org.jumpmind.symmetric.model.NodeStatus;
import org.jumpmind.symmetric.model.ProcessInfo;
import org.jumpmind.symmetric.model.RemoteNodeStatuses;
import org.jumpmind.symmetric.service.IAcknowledgeService;
import org.jumpmind.symmetric.service.IBandwidthService;
Expand Down Expand Up @@ -77,6 +78,8 @@ public interface ISymmetricEngine {

public void uninstall();

public void uninstall(ProcessInfo processInfo);

/**
* @return the URL that represents this engine
*/
Expand Down