Skip to content
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

agent.LocalOrchestrator.OnRowsChangesApplied called twice. #1121

Open
rahulworx opened this issue Nov 8, 2023 · 3 comments
Open

agent.LocalOrchestrator.OnRowsChangesApplied called twice. #1121

rahulworx opened this issue Nov 8, 2023 · 3 comments

Comments

@rahulworx
Copy link

I have setup a timer to call synchronise every 3 minutes for the changes that occurs in a table. But my
agent.LocalOrchestrator.OnRowsChangesApplied get called twice for every single change.
What can be the issue?

@Mimetis
Copy link
Owner

Mimetis commented Nov 8, 2023

OnRowsChangesApplied is called for every table and depends on multiple factors:

  • If you have multiple batch files to be applied, for one table, it will be called for each batch
  • If you have set a batch a max lines count, it will be called also for each max lines count applied
  • And finally it will be called for each state of your table Modified and Deleted

If your scenario, I guess it's called for the state Modified and Deleted

One thing you can do, is to check the values of the argument, something like that:

agent.LocalOrchestrator.OnRowsChangesApplied(args =>
{
    // check state
    if (args.State == SyncRowState.Modified)
        Console.WriteLine("State: Insert or Edit rows");
    else if (args.State == SyncRowState.Deleted)
        Console.WriteLine("State: Delete rows");
    else
        Console.WriteLine($"State: Retry or Fail ?: {args.State}");

    // Check if we have some rows applied
    if (args.SyncRows == null || args.SyncRows.Count <= 0)
        Console.WriteLine($"No rows applied for this state");

});

If you don't have bulk mode enabled (Only SqlSyncProvider supports it), OnRowsChangesApplied is called for every rows, twice (each state)

If you need less granular event, you can use

  • OnBatchChangesApplied that will only be raised for each batch files applied.
  • OnTableChangesApplied that will occurs at the end, after all batches are applied and all conflicts resolved.

That being said, you still have two events raised, for each state (Deleted / Modified)

Obviously the lesser granular level would be OnDatabaseChangesApplied, I guess.

Make sense ?

@Mimetis
Copy link
Owner

Mimetis commented Nov 9, 2023

That being said, I just made some tests and the interceptor should not be called twice for each rows...
Can you provide me a sample to be able to reproduce your issue ?

@Mimetis
Copy link
Owner

Mimetis commented Nov 9, 2023

Another thing to mention, if you are using bulk insert with SqlSyncProvider, you could have a particular where the bulk method is called and tries to insert/update a bunch of rows, but it's failing for some reasons.
OnRowsChangesApplied is called with all the rows failing and the explicit error (you can retrieve this error from the argument)

Then, DMS tries to applies all these rows, one by one. In some cases, applying rows one by row can resolve the issue.
OnRowsChangesApplied is called a second time in this particular case.

Can you check if it's the case for you ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants