nikepan / clickhouse-bulk

Collects many small inserts to ClickHouse and send in big inserts
Apache License 2.0
474 stars 86 forks source link

Deadlocks while trying to write dumps and uploading them to database at the same time #64

Open gauzy-gossamer opened 1 year ago

gauzy-gossamer commented 1 year ago

There are two locks (FileDumper.mu and Clickhouse.mu) that are called in different order.

When dumping files to disk Clickhouse.Dump locks Clickhouse.mu, then FileDumper.Dump is called with a lock on FileDumper.mu. At the same time, FileDumper.Listen calls ProcessNextDump with a FileDumper.mu lock and then calls SendQuery->GetNextQuery with a Clickhouse.mu lock.

One potential solution is to remove a lock from Clickhouse.Dump, since it already locks FileDumper.mu in FileDumper.Dump.