Skip to content

Commit

Permalink
0005433: Sync triggers when parameters change that affect triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Sep 2, 2022
1 parent cb6aabf commit a34b581
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
Expand Up @@ -23,10 +23,12 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.properties.DefaultParameterParser.ParameterMetaData;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.ext.IConfigurationChangedListener;
import org.jumpmind.symmetric.io.data.CsvData;
Expand Down Expand Up @@ -100,7 +102,8 @@ public void handleChange(Context context, Table table, CsvData data) {
updateContext(TableConstants.SYM_TRANSFORM_TABLE, table, context, CTX_KEY_FLUSH_TRANSFORMS_NEEDED);
updateContext(TableConstants.SYM_TRANSFORM_COLUMN, table, context, CTX_KEY_FLUSH_TRANSFORMS_NEEDED);
updateContext(TableConstants.SYM_TRIGGER_ROUTER_GROUPLET, table, context, CTX_KEY_FLUSH_GROUPLETS_NEEDED, CTX_KEY_RESYNC_NEEDED);
if (matchesTable(table, TableConstants.SYM_PARAMETER)) {
if (matchesTable(table, TableConstants.SYM_PARAMETER) && matchesExternalId(table, data, "external_id")
&& matchesNodeGroupId(table, data, "node_group_id")) {
String jobName = JobDefinition.getJobNameFromData(data);
if (jobName != null) {
getHashSet(context, CTX_KEY_CHANGED_JOB_IDS).add(jobName);
Expand All @@ -111,6 +114,10 @@ public void handleChange(Context context, Table table, CsvData data) {
} else if (ParameterConstants.CLUSTER_LOCKING_ENABLED.equals(paramKey)) {
context.put(CTX_KEY_CLUSTER_NEEDED, true);
}
Map<String, ParameterMetaData> parameters = ParameterConstants.getParameterMetaData();
if (parameters.get(paramKey).getTags().contains(ParameterMetaData.TAG_TRIGGER)) {
context.put(CTX_KEY_RESYNC_NEEDED, true);
}
}
if ((matchesTable(table, TableConstants.SYM_TRIGGER) || matchesTable(table, TableConstants.SYM_TRIGGER_ROUTER)) && isSyncTriggersAllowed(context) &&
context.get(CTX_KEY_RESYNC_NEEDED) == null) {
Expand Down Expand Up @@ -294,6 +301,18 @@ private boolean matchesTable(Table table, String tableSuffix) {
}
}

private boolean matchesExternalId(Table table, CsvData data, String columnName) {
String externalId = engine.getParameterService().getExternalId();
String columnValue = getColumnValue(table, data, columnName);
return columnValue == null || externalId.equals(columnValue) || columnValue.equals(ParameterConstants.ALL);
}

private boolean matchesNodeGroupId(Table table, CsvData data, String columnName) {
String nodeGroupId = engine.getParameterService().getNodeGroupId();
String columnValue = getColumnValue(table, data, columnName);
return columnValue == null || nodeGroupId.equals(columnValue) || columnValue.equals(ParameterConstants.ALL);
}

private void updateContext(String tableSuffix, Table table, Context context, String... constants) {
if (matchesTable(table, tableSuffix)) {
for (String constant : constants) {
Expand Down
58 changes: 34 additions & 24 deletions symmetric-core/src/main/resources/symmetric-default.properties
Expand Up @@ -270,9 +270,9 @@ target.db.read.strings.as.bytes=

# Whether target binary fields should be treated as lobs
#
# DatabaseOverridable: false
# DatabaseOverridable: true
# Type: boolean
# Tags: other
# Tags: trigger
target.treat.binary.as.lob.enabled=

# Defines the number of milliseconds before logging that a target query is slow.
Expand Down Expand Up @@ -1686,7 +1686,7 @@ dataextractor.enable=true
# convert($(columnName), 'AR8ISO8859P6', 'AR8MSWIN1256')
#
# DatabaseOverridable: true
# Tags: extract
# Tags: extract, trigger
# Type: textbox
dataextractor.text.column.expression=

Expand Down Expand Up @@ -2018,7 +2018,7 @@ hsqldb.initialize.db=true

# This is the precision that is used in the number template for oracle triggers
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
oracle.template.precision=*,38

# Use the text minimum format model for capturing changes to number data types.
Expand All @@ -2027,8 +2027,8 @@ oracle.template.precision=*,38
# When disabled, numbers are converted with cast to number(*,38), which
# can capture up to 38 digits.
#
# DatabaseOverridable: false
# Tags: other
# DatabaseOverridable: true
# Tags: trigger
# Type: boolean
oracle.template.precision.text.minimum=false

Expand Down Expand Up @@ -2124,7 +2124,7 @@ oracle.load.query.hint.parallel.count=1
# when the database collation for char types isn't compatible with n char types.
#
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
# Type: boolean
oracle.use.ntypes.for.sync=false

Expand Down Expand Up @@ -2178,12 +2178,12 @@ db2.zseries.version=DSN08015

# Specify the database type to cast clob values to
# DatabaseOverridable: true
# Tags: AS400
# Tags: AS400, trigger
as400.cast.clob.to=DBCLOB

# Turn on the capture of transaction id for DB2 systems that support it.
# DatabaseOverridable: false
# Tags: DB2
# Tags: DB2, trigger
db2.capture.transaction.id=false

# Specify the type of line feed to use in JMX console methods. Possible values are: text or html.
Expand Down Expand Up @@ -2241,7 +2241,7 @@ offline.node.detection.restart.minutes=5
#
# This is currently supported by the following dialects: mysql, oracle, db2, postgres, sql server
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
# Type: boolean
trigger.update.capture.changed.data.only.enabled=false

Expand All @@ -2258,18 +2258,19 @@ trigger.create.before.initial.load.enabled=true
# to all nodes on configured group links. Supported on MS SQL-Server only.
#
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
# Type: boolean
trigger.capture.ddl.changes=false

# The delimiter to use when capturing changes from a DDL trigger. MS SQL-Server only.
# See: trigger.capture.ddl.changes
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
trigger.capture.ddl.delimiter=$

# Enable or disabled use of create or replace syntax on Oracle and MS-SQL 2016 and newer.
#
# DatabaseOverridable: true
# Tags: other
# Type: boolean
trigger.allow.create.or.replace=true
Expand All @@ -2284,7 +2285,8 @@ trigger.allow.create.or.replace=true
# an update. This parameter, when changed, requires a restart of the
# SymmetricDS instance, followed by a rebuild of the triggers.
#
# Tags: other
# DatabaseOverridable: true
# Tags: trigger
# Type: boolean
trigger.use.insert.delete.for.primary.key.changes=true

Expand All @@ -2296,10 +2298,18 @@ trigger.use.insert.delete.for.primary.key.changes=true
# be synchronized.
#
# DatabaseOverridable: true
# Tags: other
# Tags: trigger, load
# Type: boolean
db.treat.date.time.as.varchar.enabled=false

# Specify the timezone for the create_time value on sym_data when changes are captured.
# Only implemented for Oracle, Tibero, and PostgreSQL currently.
#
# DatabaseOverridable: true
# Tags: trigger, load
# Type: textbox
data.create_time.timezone=

# This is the expected increment value for the data_id in the data table.
# This is useful if you use auto_increment_increment and auto_increment_offset in MySQL.
# Note that these settings require innodb_autoinc_lock_mode=0, otherwise the increment
Expand Down Expand Up @@ -2587,14 +2597,14 @@ mssql.allow.only.row.level.locks.on.runtime.tables=true
# when the database collation for char types isn't compatible with n char types.
#
# DatabaseOverridable: true
# Tags: other, mssql
# Tags: trigger, mssql
# Type: boolean
mssql.use.ntypes.for.sync=false

# Specify the user the SymmetricDS triggers should execute as. Possible values are
# { CALLER | SELF | OWNER | 'user_name' }
# DatabaseOverridable: true
# Tags: other, mssql
# Tags: trigger, mssql
mssql.trigger.execute.as=caller

# Set the order of triggers to 'First' using sp_settriggerorder after creating triggers.
Expand All @@ -2603,7 +2613,7 @@ mssql.trigger.execute.as=caller
# If the user has a trigger set as 'First', it will be changed to 'None'.
#
# DatabaseOverridable: true
# Tags: other, mssql
# Tags: trigger, mssql
# Type: boolean
mssql.trigger.order.first=false

Expand All @@ -2617,7 +2627,7 @@ mssql.lock.escalation.disabled=true
# Includes the catalog/database name within generated triggers (catalog.schema.table). May need turned off to support backup processes such as creating a bacpac file
#
# DatabaseOverridable: true
# Tags: other, mssql
# Tags: trigger, mssql
# Type: boolean
mssql.include.catalog.in.triggers=true

Expand All @@ -2626,7 +2636,7 @@ mssql.include.catalog.in.triggers=true
# collation of the varchar columns of a table
#
# DatabaseOverridable: true
# Tags: other, mssql
# Tags: trigger, mssql
db.master.collation=

# Automatically alter data, data_event and outgoing_batch tables to allow only
Expand Down Expand Up @@ -2854,7 +2864,7 @@ node.offline.archive.dir=
# When disabled, monitor events are still generated, just not synced to other nodes.
#
# DatabaseOverridable: true
# Tags: other
# Tags: trigger
# Type: boolean
monitor.events.capture.enabled=false

Expand Down Expand Up @@ -2994,9 +3004,9 @@ log.conflict.resolution=false

# Whether binary fields should be treated as lobs
#
# DatabaseOverridable: false
# DatabaseOverridable: true
# Type: boolean
# Tags: other
# Tags: trigger
treat.binary.as.lob.enabled=true

# Whether char fields should be right trimmed
Expand Down Expand Up @@ -3178,8 +3188,8 @@ job.log.miner.period.time.ms=10000
# Postgres triggers default to "security invoker" with permissions based on caller.
# Enable this parameter to use "security definer" with permissions based on owner.
#
# DatabaseOverridable: false
# Tags: postgres
# DatabaseOverridable: true
# Tags: postgres, trigger
# Type: boolean
postgres.security.definer=false

Expand Down
Expand Up @@ -193,6 +193,7 @@ public static class ParameterMetaData implements Serializable {
public static final String TYPE_CODE = "code";
public static final String TYPE_XML = "xml";
public static final String TYPE_ENCRYPTED = "encrypted";
public static final String TAG_TRIGGER = "trigger";
private static final long serialVersionUID = 1L;
private String key;
private String description;
Expand Down

0 comments on commit a34b581

Please sign in to comment.