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

Support replace mode for lightning post-import conflict detection #45774

Closed
lyzx2001 opened this issue Aug 2, 2023 · 1 comment · Fixed by #46763
Closed

Support replace mode for lightning post-import conflict detection #45774

lyzx2001 opened this issue Aug 2, 2023 · 1 comment · Fixed by #46763
Assignees
Labels
type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@lyzx2001
Copy link
Contributor

lyzx2001 commented Aug 2, 2023

Feature Request

Is your feature request related to a problem? Please describe:

Currently lightning only supports remove mode for post-import conflict detection, but many customers request lightning to support replace mode for lightning post-import conflict detection.

Describe the feature you'd like:

replace mode for lightning post-import conflict detection:
To resolve rows with conflict, instead of deleting all the rows that are engaged in conflict (the algorithm for remove), we delete some rows with conflict and reserve other rows that can be kept and not cause conflict anymore. Under this circumstance, we only delete the necessary rows to resolve conflicts, so that we can keep more original rows than remove mode as long as the conflicts are resolved.

For instance, we have the following table structure:

create table test (c1 int primary key, c2 int);

And we have 2 rows:

1, 111
1, 222

remove mode would delete both 2 rows, but replace mode would only delete 1 row and reserve the other one.

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

Design documentation:

https://pingcap.feishu.cn/docx/XD52dwxfdoewUQxDDRtcdUq4nod?from=from_copylink

Implementation steps:

  1. Change the structure of the tables that record data KV conflicts and index KV conflicts. Add index to track and search rows with conflict faster.

    if task.indexInfo == nil {
    err = m.RecordDataConflictError(gCtx, stream)
    } else {
    err = m.RecordIndexConflictError(gCtx, stream, task.tableID, task.indexInfo)
    }

  2. Use local backend import, set duplicate-resolution = 'record' to record the conflict rows but not delete them from downstream, manually use TiKV's API to extract information from the tables, and implement the replace algorithm to check the feasibility of the method.

  3. Modify ResolveAllConflictKeys function to support the replace algorithm that delete only the necessary rows to resolve conflict.

    err = local.errorMgr.ResolveAllConflictKeys(

  4. Optimize executing logic and performance for the replace algorithm.

@lyzx2001 lyzx2001 added the type/feature-request Categorizes issue or PR as related to a new feature. label Aug 2, 2023
@lyzx2001
Copy link
Contributor Author

lyzx2001 commented Aug 2, 2023

/assign @lyzx2001

ti-chi-bot bot pushed a commit that referenced this issue Aug 4, 2023
@lyzx2001 lyzx2001 changed the title Support replace mode for lightning backend conflict detection Support replace mode for lightning post conflict detection Aug 14, 2023
@lyzx2001 lyzx2001 changed the title Support replace mode for lightning post conflict detection Support replace mode for lightning backend conflict detection Aug 14, 2023
@lyzx2001 lyzx2001 changed the title Support replace mode for lightning backend conflict detection Support replace mode for lightning post-import conflict detection Aug 30, 2023
ti-chi-bot bot pushed a commit that referenced this issue Sep 1, 2023
ti-chi-bot bot pushed a commit that referenced this issue Oct 7, 2023
ti-chi-bot bot pushed a commit that referenced this issue Nov 3, 2023
ti-chi-bot bot pushed a commit that referenced this issue Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
1 participant