DEV Community

Michael
Michael

Posted on

Fixing "Can't get distribution attribute of table" in GBase 8a

If an OS power loss or crash happens on a China-domestically developed GBase 8a MPP database from GBASE, some metadata may not be flushed to disk — the gbase.table_distribution table is one example. On a single-node cluster with no replica to recover from automatically, certain tables then fail to query with Can't get distribution attribute of table.

The error

ERROR 1149 (42000): (GBA-02SC-1001) Can't get distribution attribute of table `testdb`.`t2_test`, please check your gbase.table_distribution.
Enter fullscreen mode Exit fullscreen mode

Why it happens

Distribution metadata lives in table_distribution: the distribution type (hash or random), whether the table is a replicated table, and so on.

If the table does not exist on disk at all, the error is a plain not exists:

gbase> select * from t2_test2;
ERROR 1146 (42S02): Table 'testdb.t2_test2' doesn't exist
Enter fullscreen mode Exit fullscreen mode

If the table exists but that metadata row was lost, the query fails differently:

gbase> select * from t2_test;
ERROR 1149 (42000): (GBA-02SC-1001) Can't get distribution attribute of table `testdb`.`t2_test`, please check your gbase.table_distribution.
Enter fullscreen mode Exit fullscreen mode

Rebuilding the table then hits two classic, contradictory symptoms — dropping it says Unknown table, creating it says already exists:

gbase> drop table t2_test;
ERROR 1702 (HY000): gcluster table error: (GBA-02DD-0017) Unknown table 'testdb.t2_test'
gbase>
gbase> create table t2_test like t2;
ERROR 1050 (42S01): Table 't2_test' already exists
gbase>
Enter fullscreen mode Exit fullscreen mode

Solutions

1. Rebuild the distribution row by hand

Insert the missing row into table_distribution:

gbase> insert into table_distribution values('testdb.t2_test','testdb','t2_test','NO',null,null,null,'NO',2);
Query OK, 1 row affected (Elapsed: 00:00:00.00)
gbase> select * from table_distribution where index_name like '%t2_test%';
+----------------+--------+---------+-------------+-------------+------------------+--------------------+-------------+----------------------+
| index_name     | dbName | tbName  | isReplicate | hash_column | lmt_storage_size | table_storage_size | is_nocopies | data_distribution_id |
+----------------+--------+---------+-------------+-------------+------------------+--------------------+-------------+----------------------+
| testdb.t2_test | testdb | t2_test | NO          | NULL        |             NULL |               NULL | NO          |                    2 |
+----------------+--------+---------+-------------+-------------+------------------+--------------------+-------------+----------------------+
1 row in set (Elapsed: 00:00:00.00)
Enter fullscreen mode Exit fullscreen mode

Field meanings follow the table_distribution metadata table. In particular:

  • isReplicate: whether this is a replicated table.
  • hash_column: fill in the real hash column if there is one.
  • data_distribution_id: copy it from another existing, queryable table and keep it consistent.

Then restart only the gclusterd service, because gnode has no table_distribution table:

[gbase@localhost gbase]$ gcluster_services gcluster restart
Stopping gcluster :                                        [  OK  ]
Starting gcluster :                                    [  OK  ]
Enter fullscreen mode Exit fullscreen mode

The table queries again:

gbase> select * from t2_test;
Empty set (Elapsed: 00:00:00.03)
Enter fullscreen mode Exit fullscreen mode

This is the right option when the data matters and cannot be dropped. To find which tables lost their metadata:

gbase> select table_name from information_schema.tables where table_schema='testdb' and table_name not in(select tbname from gbase.table_distribution where dbname='testdb');
+------------+
| table_name |
+------------+
| t2_test    |
+------------+
1 row in set (Elapsed: 00:00:00.00)
Enter fullscreen mode Exit fullscreen mode

2. Restore from another cluster

If another environment has identical tables, copy that table's data over and restart the local service:

scp gbase@XXXX:/opt/gbase/gcluster/userdata/gcluster/gbase/table_distribution.* /opt/gbase/gcluster/userdata/gcluster/gbase/
Enter fullscreen mode Exit fullscreen mode

Back up the local files first.

3. Drop and rebuild

In a test environment where the data is disposable and speed of recovery matters most, dropping the database and rebuilding is the quickest route.

Going forward, keep a copy of gbase.table_distribution in the backup routine: it is small, but on a single-node gbase cluster it is the only source of truth that lets the database map a table to its distribution. Verifying that metadata after any unclean shutdown is far cheaper than reconstructing it table by table in gbase later.

Top comments (0)