Skip to content

Commit

Permalink
colocation: set pgtable_id for SetSchema (#4986)
Browse files Browse the repository at this point in the history
Summary:

`pgtable_id` for schemas are not set consistently for master metadata
and tserver metadata.

- Create table request from postgres does not set it
- `CatalogManager::CreateTable` does not set it
- `RaftGroupMetadata::AddTable` does set it
- `CatalogManager::AlterTable` does set it
- `CatalogManager::AddIndexInfoToTable` does not set it
- `CatalogManager::MarkIndexInfoFromTableForDeletion` does not set it
- `RaftGroupMetadata::SetSchema` does not set it

Ideally, `pgtable_id` would be set into the master schema on create,
either on the create table request from postgres or
`CatalogManager::CreateTable`.  However, this may cause backwards
compatibility issues.

For now, tackle this problem at `RaftGroupMetadata::SetSchema` by
setting `pgtable_id` there.  This is just a copy-paste from
`RaftGroupMetadata::AddTable`.  Ideally, both shouldn't have to do this
because the master schema would already have it.

Test Plan:

```sh
./bin/yb-ctl create \
  --master_flags "ysql_disable_index_backfill=false" \
  --tserver_flags "ysql_disable_index_backfill=false"
./bin/ysqlsh
```

```sql
CREATE TABLE t (i int);
CREATE INDEX ON t (i);
DROP INDEX t_i_idx;
DROP TABLE t; -- no corruption from docdb
```

```sh
# Set `ysql_disable_index_backfill` default to false in the code, then
./yb_build.sh \
  --cxx-test pgwrapper_pg_libpq-test \
  --gtest_filter PgLibPqTest.TableColocation
```

Reviewers: neha

Reviewed By: neha

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D8834
  • Loading branch information
jaki committed Jul 8, 2020
1 parent f28a609 commit d92b234
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/yb/tablet/tablet_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,16 @@ void RaftGroupMetadata::SetSchema(const Schema& schema,
index_map,
deleted_cols,
version);
if (target_table_id != primary_table_id_) {
if (schema.table_properties().is_ysql_catalog_table()) {
Uuid cotable_id;
CHECK_OK(cotable_id.FromHexString(target_table_id));
new_table_info->schema.set_cotable_id(cotable_id);
} else {
auto result = CHECK_RESULT(GetPgsqlTableOid(target_table_id));
new_table_info->schema.set_pgtable_id(result);
}
}
VLOG_WITH_PREFIX(1) << raft_group_id_ << " Updating table " << target_table_id
<< " to Schema version " << version
<< " from \n" << yb::ToString(kv_store_.tables[target_table_id])
Expand Down

0 comments on commit d92b234

Please sign in to comment.