4paradigm / 4paradigm/OpenMLDB

create table bug in parallel

Offen
#3,121 2 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @vagetablechicken Auf GitHub ansehen
bug storage-engine
Vorherrschende Sprache
C++
Sterne
1.7k
Forks
331
Ø Merge
12 T. 12 Std.
Gemergte PRs (30 T.)
1

Beschreibung

## Reproduce steps(demo docker is recommended)
```
./init.sh
openmldb/bin/openmldb --zk_cluster=127.0.0.1:2181 --zk_root_path=/openmldb --role=sql_client --cmd="create database db"
# exec in background, so it can be parallel
openmldb/bin/openmldb --zk_cluster=127.0.0.1:2181 --zk_root_path=/openmldb --role=sql_client --database=db --cmd="create table t1(c1 string, c2 int, c3 bigint, c4 float, c5 double, c6 timestamp, c7 date)" &
openmldb/bin/openmldb --zk_cluster=127.0.0.1:2181 --zk_root_path=/openmldb --role=sql_client --database=db --cmd="create table t1(c1 string, c2 int, c3 bigint, c4 float, c5 double, c6 timestamp, c7 date)" &
```
Here, we'll create two tables with the same name, and nameserver will miss the second table, only cache the first table in `db_table_info_`. (the newer table is not inserted, cuz we use std::map::insert)
But there're two tables, tid is different, you can check it in zookeeper by
```
/work/openmldb/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181
get /openmldb/table/db_table_data/6
get /openmldb/table/db_table_data/7
```

You can check the only table in nameserver by
```
curl http://localhost:7527/NameServer/ShowTable -d'{"db":"db","table":"t1"}' | grep -Eo '"tid":[0-9]*'
```
For example, in my env, it shows `"tid":6`, so table tid 7 is missing.

The problem is that, you can drop table
```
openmldb/bin/openmldb --zk_cluster=127.0.0.1:2181 --zk_root_path=/openmldb --role=sql_client --database=db --cmd="drop table t1"
```
And the table 6 is deleted, you can't find it in nameserver:
```
curl http://localhost:7527/NameServer/ShowTable -d'{"db":"db","table":"t1"}'
{"code":0,"msg":"ok"}
```
But sql client will find the table 7 after refresh the catalog, cuz zookeeper has table 7.
```
openmldb/bin/openmldb --zk_cluster=127.0.0.1:2181 --zk_root_path=/openmldb --role=sql_client --database=db --cmd="show tables"
--------
Tables
--------
t1
--------

1 rows in set
```
Not the same table, but it looks like we can't drop the table.

## How to fix
We can restart the nameserver, it'll recover the missing table.

But we should avoid to create tables with the same name in parallel.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

The issue involves the nameserver's table cache (`db_table_info_`) using std::map::insert, which fails on concurrent creation. Examine the nameserver code handling table creation and caching, likely in a file like nameserver/table_manager.cc or similar. Reproduce with the provided steps using the demo docker. Check zookeeper paths /openmldb/table/db_table_data/ to see both table entries. The fix must ensure atomicity or conflict detection for parallel CREATE TABLE with the same name.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
sql
Bereich
databases, distributed-systems
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.