Skip to content

Commit

Permalink
0005015: Speed up start up by only checking tables when version changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 3, 2021
1 parent a1e6c9a commit f2a7836
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Expand Up @@ -509,10 +509,24 @@ public void setup() {

public void setupDatabase(boolean force) {
log.info("Initializing SymmetricDS database");
if (parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE) || force) {
symmetricDialect.initTablesAndDatabaseObjects();
boolean isAutoConfigDatabase = parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE);
boolean isAutoConfigDatabaseFast = parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE_FAST);

if (force || isAutoConfigDatabase) {
if (isAutoConfigDatabaseFast && !hasSoftwareVersionChanged()) {
log.info("Version matches for tables and objects");
} else {
log.info("Checking tables and objects");
symmetricDialect.initTablesAndDatabaseObjects();
}
} else {
log.info("SymmetricDS is not configured to auto-create the database");
if (hasSoftwareVersionChanged()) {
throw new SymmetricException("Upgrade of SymmetricDS runtime tables to version " + Version.version() +
" is required. Enable " + ParameterConstants.AUTO_CONFIGURE_DATABASE
+ " parameter for automatic upgrade of tables or perform manual upgrade with symadmin.");
} else {
log.info("SymmetricDS is not configured to auto-create the database");
}
}
try {
configurationService.initDefaultChannels();
Expand All @@ -531,6 +545,14 @@ public void setupDatabase(boolean force) {
log.info("Done initializing SymmetricDS database");
}

protected boolean hasSoftwareVersionChanged() {
Node identity = nodeService.findIdentity();
if (identity != null) {
return !Version.version().equals(identity.getSymmetricVersion());
}
return true;
}

protected void autoConfigRegistrationServer() {
Node node = nodeService.findIdentity();

Expand Down
Expand Up @@ -138,6 +138,7 @@ private ParameterConstants() {
public final static String AUTO_SYNC_CONFIGURATION = "auto.sync.configuration";
public final static String AUTO_SYNC_CONFIGURATION_ON_INCOMING = "auto.sync.configuration.on.incoming";
public final static String AUTO_CONFIGURE_DATABASE = "auto.config.database";
public final static String AUTO_CONFIGURE_DATABASE_FAST = "auto.config.database.fast";
public final static String AUTO_SYNC_TRIGGERS = "auto.sync.triggers";
public final static String AUTO_SYNC_TRIGGERS_AT_STARTUP = "auto.sync.triggers.at.startup";
public final static String AUTO_SYNC_CONFIG_AT_STARTUP = "auto.sync.config.at.startup";
Expand Down
Expand Up @@ -617,6 +617,13 @@ auto.start.engine=true
# Type: boolean
auto.config.database=true

# If both auto.config.database and this parameter are true when symmetric starts up, it will only try to create the necessary tables
# if the current software version is different from the version used during the last start up (stored on sym_node.symmetric_version).
#
# Tags: general
# Type: boolean
auto.config.database.fast=true

# If this is true, triggers will be created or dropped to match configuration during the sync triggers process.
#
# DatabaseOverridable: true
Expand Down

0 comments on commit f2a7836

Please sign in to comment.