Skip to content

Commit

Permalink
0004143: Remove ping back enabled from trigger router
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Nov 11, 2019
1 parent 4bbbe94 commit 0c35192
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 54 deletions.
39 changes: 7 additions & 32 deletions symmetric-assemble/src/asciidoc/configuration/table-routing.ad
Expand Up @@ -78,43 +78,18 @@ endif::pro[]
ifdef::pro[]
.Required Fields
endif::pro[]
Table Trigger:: The table trigger to link.
Router:: The router to link.
Table Trigger:: The table trigger determines the source of data.
Router:: The router determines where data will be sent.

Initial Load Select:: SQL used as part of the WHERE clause on a SQL statement during the initial load process to extract data from the source node
of the router. If blank all rows will be selected. If you want no rows to load during initial load you can set the expression to 1=0 or
set Initial Load Order to a negative number.
Initial Load Select:: A SQL expression used in the WHERE clause of the SELECT that extracts the table during initial load. Leave blank to retrieve all rows. For correlated joins, reference the table using the "t" alias. Variables are substituted for `$(groupId)`, `$(nodeId)`, and `$(externalId)`. See <<Variables>> section for formatting and manipulation of variables.

ifdef::pro[]
.Advanced Options
endif::pro[]

Initial Load Delete:: SQL used as part of the WHERE clause on a SQL statement during the initial load process to delete data on the target node
of the router.
+
Initial Load Delete SQL will only be used if the following parameter is true (default is false).
+
----
initial.load.delete.first=true
----

Initial Load Order:: Order sequence of this table when an initial load is sent to a node. If this value is the same for
multiple tables, then SymmetricDS will attempt to order the tables according to FK constraints. If this value is set to
a negative number, then the table will be excluded from an initial load.

Enabled:: Each individual trigger-router combination can be disabled or enabled if needed. By default, a trigger router is enabled,
but if you have a reason you wish to define a trigger router combination prior to it being active,
ifndef::pro[you can set the enabled flag to 0.]
ifdef::pro[you can uncheck the enabled box.]
This will cause the trigger-router mapping to be sent to all nodes, but the trigger-router mapping will not be considered
active or enabled for the purposes of capturing data changes or routing.

Ping Back Enabled:: SymmetricDS, by default, avoids circular data changes. When a trigger fires as a result of SymmetricDS itself
(such as the case when sync on incoming batch is set), it records the originating source node of the data change in source_node_id.
During routing, if routing results in sending the data back to the originating source node, the data is not routed by default.
If instead you wish to route the data back to the originating node,
ifndef::pro[you can set the ping_back_enabled column for the needed particular trigger / router combination.]
ifdef::pro[you can check the ping back enabled column.]
This will cause the router to "ping" the data back to the originating node when it usually would not.
Initial Load Delete:: If `initial.load.delete.first` parameter is enabled, this SQL expression is used in the WHERE clause of the DELETE that clears the table on the target node at the beginning of the initial load.

Initial Load Order:: Numeric position for this table in the initial load, sent in ascending numeric order. When two numeric values are the same, the ordering is based on foreign key constraints. Use a negative number to exclude the table from initial load.

Enabled:: When enabled, changes are captured and routed into batches for the table. When disabled, changes are no longer captured for the table and any outstanding changes are placed into batches with a status of "unrouted".

Expand Up @@ -59,8 +59,6 @@ public class TriggerRouter implements Serializable {

private String lastUpdateBy;

private boolean pingBackEnabled = false;

public TriggerRouter() {
this(new Trigger(), new Router());
}
Expand Down Expand Up @@ -204,14 +202,6 @@ public String qualifiedTargetTableName(TriggerHistory triggerHistory) {
return tableName;
}

public void setPingBackEnabled(boolean pingBackEnabled) {
this.pingBackEnabled = pingBackEnabled;
}

public boolean isPingBackEnabled() {
return pingBackEnabled;
}

public boolean isSame(TriggerRouter triggerRouter) {
return (this.trigger == null && triggerRouter.trigger == null)
|| (this.trigger != null && triggerRouter.trigger != null && this.trigger
Expand Down
Expand Up @@ -853,7 +853,7 @@ protected int routeData(ProcessInfo processInfo, Data data, ChannelRouterContext
}

if (nodeIds != null) {
if (!triggerRouter.isPingBackEnabled() && data.getSourceNodeId() != null) {
if (data.getSourceNodeId() != null) {
nodeIds.remove(data.getSourceNodeId());
}

Expand Down
Expand Up @@ -1068,27 +1068,25 @@ public void saveTriggerRouter(TriggerRouter triggerRouter, boolean updateTrigger
new Object[] { triggerRouter.getInitialLoadOrder(),
triggerRouter.getInitialLoadSelect(),
triggerRouter.getInitialLoadDeleteStmt(),
triggerRouter.isPingBackEnabled() ? 1 : 0,
triggerRouter.getLastUpdateBy(),
triggerRouter.getLastUpdateTime(),
triggerRouter.isEnabled() ? 1 : 0,
triggerRouter.getTrigger().getTriggerId(),
triggerRouter.getRouter().getRouterId() }, new int[] { Types.NUMERIC,
Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.VARCHAR,
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.TIMESTAMP, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR })) {
triggerRouter.setCreateTime(triggerRouter.getLastUpdateTime());
sqlTemplate.update(
getSql("insertTriggerRouterSql"),
new Object[] { triggerRouter.getInitialLoadOrder(),
triggerRouter.getInitialLoadSelect(),
triggerRouter.getInitialLoadDeleteStmt(),
triggerRouter.isPingBackEnabled() ? 1 : 0,
triggerRouter.getCreateTime(), triggerRouter.getLastUpdateBy(),
triggerRouter.getLastUpdateTime(),
triggerRouter.isEnabled() ? 1 : 0,
triggerRouter.getTrigger().getTriggerId(),
triggerRouter.getRouter().getRouterId() }, new int[] { Types.NUMERIC,
Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.TIMESTAMP,
Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP,
Types.VARCHAR, Types.TIMESTAMP, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR });
}

Expand Down Expand Up @@ -2162,8 +2160,6 @@ public TriggerRouter mapRow(Row rs) {
triggerRouter.setEnabled(rs.getBoolean("enabled"));
triggerRouter.setInitialLoadDeleteStmt(rs.getString("initial_load_delete_stmt"));

triggerRouter.setPingBackEnabled(rs.getBoolean("ping_back_enabled"));

return triggerRouter;
}
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ public TriggerRouterServiceSqlMap(IDatabasePlatform platform,
+ " inner join $(router) r on tr.router_id=r.router_id ");

putSql("selectTriggerRoutersColumnList",
" tr.trigger_id, tr.router_id, tr.create_time, tr.last_update_time, tr.last_update_by, tr.initial_load_order, tr.initial_load_select, tr.initial_load_delete_stmt, tr.ping_back_enabled, tr.enabled ");
" tr.trigger_id, tr.router_id, tr.create_time, tr.last_update_time, tr.last_update_by, tr.initial_load_order, tr.initial_load_select, tr.initial_load_delete_stmt, tr.enabled ");

putSql("selectRoutersColumnList",
""
Expand Down Expand Up @@ -178,13 +178,13 @@ public TriggerRouterServiceSqlMap(IDatabasePlatform platform,
putSql("insertTriggerRouterSql",
""
+ "insert into $(trigger_router) "
+ " (initial_load_order,initial_load_select,initial_load_delete_stmt,ping_back_enabled,create_time,last_update_by,last_update_time,enabled,trigger_id,router_id) "
+ " values(?,?,?,?,?,?,?,?,?,?) ");
+ " (initial_load_order,initial_load_select,initial_load_delete_stmt,create_time,last_update_by,last_update_time,enabled,trigger_id,router_id) "
+ " values(?,?,?,?,?,?,?,?,?) ");

putSql("updateTriggerRouterSql",
""
+ "update $(trigger_router) "
+ " set initial_load_order=?,initial_load_select=?,initial_load_delete_stmt=?,ping_back_enabled=?,last_update_by=?,last_update_time=?,enabled=? "
+ " set initial_load_order=?,initial_load_select=?,initial_load_delete_stmt=?,last_update_by=?,last_update_time=?,enabled=? "
+ " where trigger_id=? and router_id=? ");

putSql("selectTriggerTargetSql",
Expand Down
1 change: 0 additions & 1 deletion symmetric-core/src/main/resources/symmetric-schema.xml
Expand Up @@ -930,7 +930,6 @@
<column name="initial_load_order" type="INTEGER" required="true" default="1" description="Order sequence of this table when an initial load is sent to a node. If this value is the same for multiple tables, then SymmetricDS will attempt to order the tables according to FK constraints. If this value is set to a negative number, then the table will be excluded from an initial load." />
<column name="initial_load_select" type="LONGVARCHAR" description="Optional expression that can be used to pare down the data selected from a table during the initial load process." />
<column name="initial_load_delete_stmt" type="LONGVARCHAR" description="The expression that is used to delete data when an initial load occurs. If this field is empty, no delete will occur before the initial load. If this field is not empty, the text will be used as a sql statement and executed for the initial load delete." />
<column name="ping_back_enabled" type="BOOLEANINT" size="1" required="true" default="0" description="When enabled, the node will route data that originated from a node back to that node. This attribute is only effective if sync_on_incoming_batch is set to 1."/>
<column name="create_time" type="TIMESTAMP" required="true" description="Timestamp when this entry was created." />
<column name="last_update_by" type="VARCHAR" size="50" description="The user who last updated this entry." />
<column name="last_update_time" type="TIMESTAMP" required="true" description="Timestamp when a user last updated this entry." />
Expand Down

0 comments on commit 0c35192

Please sign in to comment.