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

[BugFix] Recalculate max_continuous_version after schema change finished #28473

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

sevev
Copy link
Contributor

@sevev sevev commented Aug 2, 2023

We will create a new tablet for each original tablet and we will write original tablet and new tablet during schema change. We will construct a version_graph to keep versions info for each table and the following code is how to update version_graph:

void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}

There exists a scenario where _max_continuous_version cannot be updated correctly
e.g.

  1. create a new tablet t2 for origin tablet t1 during schema change and t2 has version 91,92,93,95,96,97,98. version 94 write failed.
  2. when running schema change job, alter version is 98 and t1 has version [0-90], [91-96], 97, 98
  3. max_continuous_version of t2 is 0 before convert rowset. After convert version [0-90], max_continuous_version is update to 93 because t2 has version 91-93 before.
  4. max_continuous_version don't update because the left rowsets version is not satisfy update condition(version.fisrt == 0 or version.first == _max_continuous_verison + 1). So the max_continuous_version will keep 93 after convert rowset finished.
  5. we will check the max_continuous_version of t2 at last and it should not less than alter version. But max_continuous_version(93) is less than alter version(98), so the alter job failed at last.

The main reason is we don't update _max_continuous_version correctly during alter job, we should recalculate the max_continuous_version after rowset conversion.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr will affect users' behaviors
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.1
    • 3.0
    • 2.5
    • 2.4

Signed-off-by: zhangqiang <[email protected]>
@wanpengfei-git
Copy link
Collaborator

[FE PR Coverage Check]

😍 pass : 0 / 0 (0%)

@luohaha
Copy link
Contributor

luohaha commented Aug 2, 2023

This problem can be check here:

int64_t Tablet::max_continuous_version() const {
    if (_updates != nullptr) {
        return _updates->max_version();
    } else {
        std::shared_lock rdlock(_meta_lock);
        int64_t v = _timestamped_version_tracker.get_max_continuous_version();
        if (tablet_state() == TABLET_RUNNING) {
            // can be check here:
            DCHECK_EQ(v, _max_continuous_version_from_beginning_unlocked().second);
        }
        return v;
    }
}

Because DCHECK_EQ can only work on asan mode, so I think we can add some ERROR log here to dig such bug out early

@decster decster merged commit bbedba4 into StarRocks:main Aug 2, 2023
22 checks passed
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.1

@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.0

@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-2.5

@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

backport branch-3.1

✅ Backports have been created

@github-actions github-actions bot removed the 2.5 label Aug 2, 2023
@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

backport branch-3.0

✅ Backports have been created

@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2023

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 2, 2023
…hed (#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
(cherry picked from commit bbedba4)

# Conflicts:
#	be/src/storage/tablet.h
mergify bot pushed a commit that referenced this pull request Aug 2, 2023
…hed (#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
(cherry picked from commit bbedba4)
mergify bot pushed a commit that referenced this pull request Aug 2, 2023
…hed (#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
(cherry picked from commit bbedba4)

# Conflicts:
#	be/src/storage/tablet.h
sevev added a commit to sevev/starrocks that referenced this pull request Aug 2, 2023
…hed (StarRocks#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
@sevev
Copy link
Contributor Author

sevev commented Aug 2, 2023

#28513 backport branch-2.5

wanpengfei-git pushed a commit that referenced this pull request Aug 2, 2023
…hed (#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
sevev added a commit to sevev/starrocks that referenced this pull request Aug 2, 2023
…hed (StarRocks#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
Astralidea pushed a commit that referenced this pull request Aug 3, 2023
…after schema change finished (#28473) (#28522)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.

---------

Signed-off-by: zhangqiang <[email protected]>
wanpengfei-git pushed a commit that referenced this pull request Aug 6, 2023
…hed (#28473)

We will create a new tablet for each original tablet and we will write
original tablet and new tablet during schema change. We will construct a
`version_graph` to keep versions info for each table and the following
code is how to update `version_graph`:
```
void VersionGraph::add_version_to_graph(const Version& version) {
    _add_version_to_graph(version);
    if (version.first == _max_continuous_version + 1) {
        _max_continuous_version = _get_max_continuous_version_from(_max_continuous_version + 1);
    } else if (version.first == 0) {
        // We need to reconstruct max_continuous_version from zero if input version is starting from zero
        // e.g.
        // 1. Tablet A is doing schema change
        // 2. We create a new tablet B releated A, and we will create a initial rowset and _max_continuous_version
        //    will be updated to 1
        // 3. Tablet A has a rowset R with version (0, m)
        // 4. Schema change will try convert R
        // 5. The start version of R (0) is not equal to `_max_continuous_version + 1`, and the _max_continuous_version
        //    will not update
        _max_continuous_version = _get_max_continuous_version_from(0);
    }
}
```
There exists a scenario where _max_continuous_version cannot be updated
correctly
e.g.
1. create a new tablet `t2` for origin tablet `t1` during schema change
and `t2` has version 91,92,93,95,96,97,98. version 94 write failed.
2. when running schema change job, alter version is 98 and `t1` has
version [0-90], [91-96], 97, 98
3. `max_continuous_version` of `t2` is 0 before convert rowset. After
convert version [0-90], `max_continuous_version` is update to 93 because
`t2` has version 91-93 before.
4. `max_continuous_version` don't update because the left rowsets
version is not satisfy update condition(version.fisrt == 0 or
version.first == _max_continuous_verison + 1). So the
`max_continuous_version` will keep 93 after convert rowset finished.
5. we will check the max_continuous_version of `t2` at last and it
should not less than alter version. But max_continuous_version(93) is
less than alter version(98), so the alter job failed at last.

The main reason is we don't update `_max_continuous_version` correctly
during alter job, we should recalculate the `max_continuous_version`
after rowset conversion.
---------

Signed-off-by: zhangqiang <[email protected]>
(cherry picked from commit bbedba4)
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

Successfully merging this pull request may close these issues.

5 participants