Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a bug was finded when create query_id for clickhouse where I use multiprocessing Pool #99

Closed
crystalxiaoou opened this issue Jul 22, 2020 · 1 comment

Comments

@crystalxiaoou
Copy link

crystalxiaoou commented Jul 22, 2020

Describe the bug
when I execute query statement from clickhouse by six Process Simultaneously. I get this error message:
【Orig exception: Code: 216, e.displayText() = DB::Exception: Query with id = cefe5212-cc01-11ea-b502-6c92bfbaaded is already running. (version 19.16.10.44)】

Then I find the six process create the same query_id in this code frame above:

https://github.com/xzkostyan/clickhouse-sqlalchemy/blob/08eb01c6b308aa6ba6b7827116a6a93beeeec5cb/clickhouse_sqlalchemy/drivers/http/connector.py

def _begin_query(self):
       self._state = self._states.RUNNING
        self._query_id = uuid1()

To Reproduce
when use multiprocessing.Pool() to create multi Process, uuid1() print the same uuid string。

import multiprocessing
import uuid

def myPrint():
    print(uuid.uuid1())

def test():
   pool = multiprocessing.Pool(5)
   tasks =[]
   tasks.append(pool.apply_async(myPrint))
   tasks.append(pool.apply_async(myPrint))
   tasks.append(pool.apply_async(myPrint))
   tasks.append(pool.apply_async(myPrint))
   tasks.append(pool.apply_async(myPrint))

   pool.close()
   pool.join()

   for task in tasks:
       task.get()


if __name__ == "__main__":
    test()

Result:

25b5ff20-cc24-11ea-ac37-acde48001122
25b61064-cc24-11ea-bbb8-acde48001122
25b5f7dc-cc24-11ea-9a4c-acde48001122
25b61ef6-cc24-11ea-8e7b-acde48001122

Expected behavior
I think that diffrent query_id should be create when call _begin_query() in https://github.com/xzkostyan/clickhouse-sqlalchemy/blob/08eb01c6b308aa6ba6b7827116a6a93beeeec5cb/clickhouse_sqlalchemy/drivers/http/connector.py

otherwise, clickhouse will return a error about "Query with id = cefe5212-cc01-11ea-b502-6c92bfbaaded is already running. (version 19.16.10.44)
"

Versions

  • clickhouse-sqlalchemy : 0.1.2
  • clickhouse : 19.16.10.44

Version of package with the problem

  • Python version: 3.7
@xzkostyan
Copy link
Owner

Fixed in latest master. UUID1 replaced with UUID4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants