4paradigm / 4paradigm/OpenMLDB

create table bug in parallel

Abierto
#3,121 2 comentarios 0 reacciones 1 asignado Reclamado por @vagetablechicken Ver en GitHub
bug storage-engine
Lenguaje dominante
C++
Estrellas
1.7k
Forks
331
Merge medio
12 d 12 h
PR fusionados (30 d)
1

Descripción

## 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.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
sql
Área
databases, distributed-systems
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.