4paradigm / 4paradigm/OpenMLDB

create table bug in parallel

Ouverte
#3,121 2 commentaires 0 réactions 1 personne assignée Réclamée par @vagetablechicken Voir sur GitHub
bug storage-engine
Langage dominant
C++
Étoiles
1.7k
Forks
331
Merge moyen
12 j 12 h
PR mergées (30 j)
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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
sql
Domaine
databases, distributed-systems
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.