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

[DocDB] splitting: Disable tablet splitting for tablets with incorrectly persisted data #12189

Open
arybochkin opened this issue Apr 18, 2022 · 4 comments
Assignees
Labels
area/docdb YugabyteDB core features kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue

Comments

@arybochkin
Copy link
Contributor

arybochkin commented Apr 18, 2022

Jira Link: DB-1991
The following cases should be handled at tablet server side:

  • Reject tablet splitting and do not try again if the partition bound is misaligned (applicable for the case when split at statement was used to create an index table)
  • Reject tablet splitting and do not try again if there are doc keys inside the tablet that are outside of tablet partition boundaries; refer to GetSplitKey() / GetEncodedMiddleKey() a new error code must be returned to identify such tablets for indexes recreation after YBOperation.partition_key encoding issue is fixed
  • Add protection into read and write code path for debug builds (for performance reasons and to not crash existing clusters) that we are always put into RocksDB keys that match tablet partition boundaries

Step to reproduce the issue:

  1. Create a cluster with enable_automatic_tablet_splitting=true:
./bin/yb-ctl create --master_flags="enable_automatic_tablet_splitting=true,tablet_split_low_phase_shard_count_per_node=16,tablet_split_low_phase_size_threshold_bytes=13421" --tserver_flags="yb_num_shards_per_tserver=1"
  1. Index tablet splitting via split at statement
    1.1. Create a table and a unique index
# create table test1(id int primary key, name text);
# create unique index idx1 on test1(name ASC) split at values(('p'));

Tablets info after statements have been executed:

yugabyte        idx1       000033e1000030008000000000004005        d75c1be78e94456d9803758d6650a897        range: [<start>, DocKey([], ["p"]))
yugabyte        idx1       000033e1000030008000000000004005        b5531d9aa54a45fb821fcf2baca3f268        range: [DocKey([], ["p"]), <end>)

1.2. Insert a row with a value that matches partition bounds

# insert into test1 values(3, 'p');

YBOperation is forwarded to the first tablet d75c1be78e94456d9803758d6650a897 as YBOperation.partition_key is less than the second partition lower bound: 537000000021 < 5370000021. But the operation should have been forwarded to the second tablet in accordance with range bounds. Tablets dump confirms the inserted row is persisted in the first tablet (with respect to DocDB format):

tablet-d75c1be78e94456d9803758d6650a897 in readable format:
SubDocKey(DocKey([], ["p", null]), [SystemColumnId(0); HT{ physical: 1649185585666746 }]) -> null; intent doc ht: HT{ physical: 1649185585665110 }
SubDocKey(DocKey([], ["p", null]), [ColumnId(12); HT{ physical: 1649185585666746 w: 1 }]) -> "G\xfc\xa0H\x80\x00\x00\x03!!"; intent doc ht: HT{ physical: 1649185585665110 w: 1 }

Data Block # 1 @ 0051
--------------------------------------
  HEX    5370000024214A80238001785106292545804A: 238001785106292BA9804A24
  ASCII  S p : # Ä  x Q  ) + © Ä J $ 
  ------
  HEX    5370000024214B8C238001785106292545803FAB: 238001785106292BA9803FAB5347FCA048800000032121
  ASCII  S p : # Ä  x Q  ) + © Ä ? ´ S G ¸ † H Ä 
  ------

tablet-b5531d9aa54a45fb821fcf2baca3f268
<empty>
  1. Index tablet splitting via split at statement
    2.1. ./bin/ysqlsh and create a table and a unique index:
create table employees(id int primary key, name text, description text);
create unique index idx1 on employees(description ASC);

2.2. mv collect_insert_data.txt to collect_insert_data.py and run python ./collect_insert_data.py
2.3. ./bin/ysqlsh -f sql_data.sql
2.4. Wait for the data to be loaded

Expected result: only 10 records are loaded
Actual result: the record that matches partition bound is duplicated, the following can be observed:

# select count(*) from employees group by description;
 count
-------
     1
     1
     1
     1
     1
     1
  9780
     1
     1
     1
(10 rows)
@arybochkin arybochkin added area/docdb YugabyteDB core features status/awaiting-triage Issue awaiting triage labels Apr 18, 2022
@arybochkin arybochkin self-assigned this Apr 18, 2022
@rthallamko3 rthallamko3 added priority/critical Critical issue and removed status/awaiting-triage Issue awaiting triage labels Apr 20, 2022
arybochkin added a commit that referenced this issue May 15, 2022
…ith range partitioning

Summary:
Issue #12190 gives a potential data loss, a temporary disabling for both dynamic and
manual splitting for index tables with range partitioning is required at master server side.
When #12190 and #12191 are done tablet splitting should be enabled for those tables.
Additional tablet splitting disabling is added at tablet server side, other checks and cases
will be covered in #12189.
Additionally, an index versioning support is implemented by adding a new field
`partition_key_version` into schema's `TableProperties` and `TablePropertiesPB` --
the default version should be updated in the context of #12190, after that tablet splitting
becomes enabled automatically for index tables with range partitioning.

Test Plan:
Main:
1. unit test:
ybd --cxx-test pgwrapper_pg_tablet_split-test --gtest_filter "PgTabletSplitTest.ManualSplitIndexTablet"

2. manual test:
2.1) create a cluster
```
./bin/yb-ctl create --master_flags="enable_automatic_tablet_splitting=true,\
                                   tablet_split_low_phase_shard_count_per_node=16,\
                                   tablet_split_low_phase_size_threshold_bytes=13421" \
                                --tserver_flags="yb_num_shards_per_tserver=1"
```
2.2) run `./bin/ysqlsh` and execute
```
create table employees(id int primary key, name text, description text);
create index idx1 on employees(description ASC);
```
2.3) open tablet server web ui and make sure only one tablet exists for index table
2.4) download `collect_insert_data.txt` from #10926 and rename to `collect_insert_data.py`
2.5) execute `./collect_insert_data.py` to generate sql script
2.6) execute `./bin/ysqlsh -f sql_data.sql`
2.7) make sure only one tablet still exists for index table, while the table has several tablets
2.8) flush `idx1` index tablet: `./bin/yb-ts-cli flush_tablet <UUID>`
2.9) try manual split: `./bin/yb-admin split_tablet -master_addresses localhost:7100 <UUID>`
the following error should appear:
```
Error running split_tablet: Not implemented (yb/master/tablet_split_manager.cc:176):
Unable to start split of tablet <UUID>: Tablet splitting is not supported for the index table "idx1"
with table_id "000033e5000030008000000000004005". Please, rebuild the index!
```

3. Additional tests should not give unexpected results:
ybd --cxx-test tablet_tablet-split-test
ybd --cxx-test integration-tests_tablet-split-itest
ybd --cxx-test integration-tests_tablet_server-itest
ybd --cxx-test integration-tests_cql-tablet-split-test
ybd --cxx-test integration-xcluster-tablet-split-itest
ybd --cxx-test common_schema-test --gtest_filter TestSchema.TestSchema
ybd --cxx-test common_schema-test --gtest_filter TestSchema.TestCreateProjection
ybd --cxx-test master_catalog_manager-test --gtest_filter "TestCatalogManager.CheckIfCanDeleteSingleTablet"
ybd --cxx-test pgwrapper_pg_tablet_split-test --gtest_filter "PgTabletSplitTest.SplitDuringLongRunningTransaction"
ybd --cxx-test pgwrapper_pg_mini-test --gtest_filter "PgMiniTest.TabletSplitSecondaryIndexYSQL"

Reviewers: timur, rthallam

Reviewed By: timur, rthallam

Subscribers: zyu, ybase, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D16738
arybochkin added a commit that referenced this issue Jun 7, 2022
… index tables with range partitioning

Summary:
Issue #12190 gives a potential data loss, a temporary disabling for both dynamic and
manual splitting for index tables with range partitioning is required at master server side.
When #12190 and #12191 are done tablet splitting should be enabled for those tables.
Additional tablet splitting disabling is added at tablet server side, other checks and cases
will be covered in #12189.
Additionally, an index versioning support is implemented by adding a new field
`partition_key_version` into schema's `TableProperties` and `TablePropertiesPB` --
the default version should be updated in the context of #12190, after that tablet splitting
becomes enabled automatically for index tables with range partitioning.

Original commit: 2ef55c8 / D16738

Test Plan:
Main:
1. unit test:
ybd --cxx-test pgwrapper_pg_tablet_split-test --gtest_filter "PgTabletSplitTest.ManualSplitIndexTablet"

2. manual test:
2.1) create a cluster
```
./bin/yb-ctl create --master_flags="enable_automatic_tablet_splitting=true,\
                                   tablet_split_low_phase_shard_count_per_node=16,\
                                   tablet_split_low_phase_size_threshold_bytes=13421" \
                                --tserver_flags="yb_num_shards_per_tserver=1"
```
2.2) run `./bin/ysqlsh` and execute
```
create table employees(id int primary key, name text, description text);
create index idx1 on employees(description ASC);
```
2.3) open tablet server web ui and make sure only one tablet exists for index table
2.4) download `collect_insert_data.txt` from #10926 and rename to `collect_insert_data.py`
2.5) execute `./collect_insert_data.py` to generate sql script
2.6) execute `./bin/ysqlsh -f sql_data.sql`
2.7) make sure only one tablet still exists for index table, while the table has several tablets
2.8) flush `idx1` index tablet: `./bin/yb-ts-cli flush_tablet <UUID>`
2.9) try manual split: `./bin/yb-admin split_tablet -master_addresses localhost:7100 <UUID>`
the following error should appear:
```
Error running split_tablet: Not implemented (yb/master/tablet_split_manager.cc:176):
Unable to start split of tablet <UUID>: Tablet splitting is not supported for the index table "idx1"
with table_id "000033e5000030008000000000004005". Please, rebuild the index!
```

3. Additional tests should not give unexpected results:
ybd --cxx-test tablet_tablet-split-test
ybd --cxx-test integration-tests_tablet-split-itest
ybd --cxx-test integration-tests_tablet_server-itest
ybd --cxx-test integration-tests_cql-tablet-split-test
ybd --cxx-test integration-xcluster-tablet-split-itest
ybd --cxx-test common_schema-test --gtest_filter TestSchema.TestSchema
ybd --cxx-test common_schema-test --gtest_filter TestSchema.TestCreateProjection
ybd --cxx-test master_catalog_manager-test --gtest_filter "TestCatalogManager.CheckIfCanDeleteSingleTablet"
ybd --cxx-test pgwrapper_pg_tablet_split-test --gtest_filter "PgTabletSplitTest.SplitDuringLongRunningTransaction"
ybd --cxx-test pgwrapper_pg_mini-test --gtest_filter "PgMiniTest.TabletSplitSecondaryIndexYSQL"

Reviewers: rthallam, timur

Reviewed By: rthallam, timur

Subscribers: bogdan, ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D17001
@yugabyte-ci yugabyte-ci added the kind/bug This issue is a bug label Jun 9, 2022
@arybochkin
Copy link
Contributor Author

Taking into account changes in #12211, #12190 and #12191, the issues mentioned above might not happen in a real cluster, some king of synthetic simulation with changing test flags may be required.

@arybochkin arybochkin added priority/high High Priority and removed priority/critical Critical issue labels Jul 7, 2022
@rthallamko3
Copy link
Contributor

@arybochkin , Can we close this now?

@yugabyte-ci yugabyte-ci added kind/enhancement This is an enhancement of an existing feature and removed kind/bug This issue is a bug labels Nov 1, 2022
@arybochkin
Copy link
Contributor Author

We cannot close. Sanity checks are required for issue, all possible unit test have already been added in the context of #12190.

@rthallamko3
Copy link
Contributor

Reopening for adding sanity checks.

@yugabyte-ci yugabyte-ci added priority/medium Medium priority issue and removed priority/high High Priority labels Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docdb YugabyteDB core features kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants