4paradigm / 4paradigm/OpenMLDB
create table bug in parallel
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 331
- Avg merge
- 12d 12h
- Merged PRs (30d)
- 1
Description
## 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.
Contributor guide
Research direction
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.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100