SymmetricDS中的自引用表外键约束问题

时间:2018-10-23 17:30:30

标签: azure-sql-database open-source symmetricds

在Windows上运行SymmetricDS时,我在Azure SQL数据库上遇到了针对从属服务器和主服务器的外键约束错误,如下所示。

    [primary-staging_prod-us-000] - AcknowledgeService - The outgoing batch 001-338 failed: 
    [FK,-900] The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_Matter_ScenarioParentID_Matter". The conflict occurred in database "DBSYNC_STAGING_PROD", table "dbo.Matter", column 'id'.

“问题”表具有如下自引用外键约束。

  ALTER TABLE [dbo].[Matter]  WITH NOCHECK ADD  CONSTRAINT [FK_Matter_ScenarioParentID_Matter] FOREIGN KEY([ScenarioParentID])
  REFERENCES [dbo].[Matter] ([ID])

我修改了sym_table_reload_request的配置,如下所示

  insert into SYM_TABLE_RELOAD_REQUEST (target_node_id, source_node_id, trigger_id, router_id, create_time,create_table,reload_select, last_update_time)
 values ('secondary-staging_prod-us-001', 'primary-staging_prod-us-000', 'TriggerAll_82', 'primary_2_secondary-staging_prod-us', GetDate(),1,' 1=1 order by ID ', GetDate());

但是reload_select列无济于事,并且在从主节点(主节点)的辅助节点(从节点)中插入记录时,外键约束给出了错误。

这是其余的配置。

   insert into sym_channel(channel_id, processing_order, max_batch_size, enabled, description)
   values('matter', 1, 100000, 1, 'All data from staging_prod and dbsync_staging_prod');


  insert into sym_node_group (node_group_id) values ('primary-staging_prod-us');
  insert into sym_node_group (node_group_id) values ('secondary-staging_prod-us');

  insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('primary-staging_prod-us', 'secondary-staging_prod-us', 'W');
  insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action) values ('secondary-staging_prod-us', 'primary-staging_prod-us', 'P');

  insert into sym_trigger (trigger_id,source_catalog_name,source_schema_name, source_table_name, channel_id, sync_on_insert, sync_on_update, sync_on_delete, last_update_time,create_time, sync_on_incoming_batch)
  values('TriggerAll_82', null, 'dbo', 'Matter', 'matter', 1 , 1, 1, GetDate(), GetDate(), 1);



   insert into sym_router (router_id,source_node_group_id,target_node_group_id,target_catalog_name,target_schema_name,target_table_name,USE_SOURCE_CATALOG_SCHEMA,router_type,create_time,last_update_time)
   values('primary_2_secondary-staging_prod-us', 'primary-staging_prod-us', 'secondary-staging_prod-us', null, 'dbo', null, 0,'default',GetDate(), GetDate());

    insert into sym_router (router_id,source_node_group_id,target_node_group_id,target_catalog_name,target_schema_name,target_table_name,USE_SOURCE_CATALOG_SCHEMA,router_type,create_time,last_update_time)
    values('secondary_2_primary-staging_prod-us', 'secondary-staging_prod-us', 'primary-staging_prod-us', null, 'dbo', null, 0,'default', GetDate(), GetDate());

@ chenson42,在您发表评论后,我在问题表上添加了具有以下配置的无效触发器。

insert into sym_trigger_router (trigger_id,router_id,initial_load_order,initial_load_select,last_update_time,create_time)
values('TriggerAll_82_D1','primary_2_secondary-staging_prod-us', 98,' ID in ( SELECT [ScenarioParentID] FROM dbo.[Matter] WHERE [ScenarioParentID] IS NOT NULL )',GetDate(),GetDate());


insert into sym_trigger_router (trigger_id,router_id,initial_load_order,initial_load_select,last_update_time,create_time)
values('TriggerAll_82_D2','primary_2_secondary-staging_prod-us', 99,' ID in ( SELECT [ID] FROM dbo.[Matter] WHERE [ScenarioParentID] IS NULL ) ',GetDate(),GetDate());


insert into sym_trigger_router (trigger_id,router_id,initial_load_order,last_update_time,create_time)
values('TriggerAll_82','primary_2_secondary-staging_prod-us', 100,GetDate(),GetDate());




insert into sym_trigger 
(trigger_id,source_catalog_name,source_schema_name, source_table_name, channel_id, sync_on_insert, sync_on_update, sync_on_delete, last_update_time,create_time, sync_on_incoming_batch)
values('TriggerAll_82_D1', null, 'dbo', 'Matter', 'matter', 0 , 0, 0, GetDate(), GetDate(), 0);

insert into sym_trigger 
(trigger_id,source_catalog_name,source_schema_name, source_table_name, channel_id, sync_on_insert, sync_on_update, sync_on_delete, last_update_time,create_time, sync_on_incoming_batch)
values('TriggerAll_82_D2', null, 'dbo', 'Matter', 'matter', 0 , 0, 0, GetDate(), GetDate(), 0);


insert into sym_trigger 
(trigger_id,source_catalog_name,source_schema_name, source_table_name, channel_id, sync_on_insert, sync_on_update, sync_on_delete, last_update_time,create_time, sync_on_incoming_batch)
values('TriggerAll_82', null, 'dbo', 'Matter', 'matter', 1 , 1, 1, GetDate(), GetDate(), 1);

我必须删除以下配置,因为它没有选择initial_load_select。

--insert into SYM_TABLE_RELOAD_REQUEST (target_node_id, source_node_id, trigger_id, router_id, create_time,create_table, last_update_time)
--     values ('secondary-staging_prod-us-001', 'primary-staging_prod-us-000', 'TriggerAll_82_D1', 'primary_2_secondary-staging_prod-us', GetDate(),1, GetDate());


--insert into SYM_TABLE_RELOAD_REQUEST (target_node_id, source_node_id, trigger_id, router_id, create_time,create_table, last_update_time)
--     values ('secondary-staging_prod-us-001', 'primary-staging_prod-us-000', 'TriggerAll_82_D2', 'primary_2_secondary-staging_prod-us', GetDate(),1, GetDate());


--insert into SYM_TABLE_RELOAD_REQUEST (target_node_id, source_node_id, trigger_id, router_id, create_time,create_table, last_update_time)
--     values ('secondary-staging_prod-us-001', 'primary-staging_prod-us-000', 'TriggerAll_82', 'primary_2_secondary-staging_prod-us', GetDate(),1, GetDate());

致谢

Rajat Agrawal

0 个答案:

没有答案