-
Notifications
You must be signed in to change notification settings - Fork 152
Support Multi-DB-Backends for LibCache #1019
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi, could you please provide us with the test script you're using here? It looks like a database problem with duplicated primary keys. @ArashiFeng |
Sorry that I can't provide the test script because it's for internal testing. In short, this problem is caused by this line https://github.com/FlagOpen/FlagGems/blob/11efecfcfa04c8c6d509adf04a4a067f1e6da524/src/flag_gems/utils/models/sql.py#L176. from sqlalchemy.dialects.postgresql import insert
obj: Base = ConfigCls(**key_dict, **config)
cmd = insert(ConfigCls).values(**key_dict, **config)
primary_keys = [col for col in ConfigCls.__table__.primary_key.columns]
update_fields = {k: getattr(cmd.excluded, k) for k in key_dict.keys() if k not in [c.name for c in primary_keys]}
update_fields.update({k: getattr(cmd.excluded, k) for k in config.keys() if k not in [c.name for c in primary_keys]})
cmd = cmd.on_conflict_do_update(index_elements=primary_keys, set_=update_fields)
session.execute(cmd)
session.commit()The following code may also work, but not validated. with Session(engine) as session:
obj = session.get(ConfigCls, key_dict["xxx"])
if obj is None:
obj = ConfigCls(**key_dict, **config)
session.add(obj)
else:
for k, v in config.items():
setattr(obj, k, v)
session.commit() |
Hi thank you for your reply and comment! I'll try this solution later. My machine is broken so I need to wait for the repair😭. I'll let you know when there is any new update. |
86a07c1 to
8348894
Compare
|
@ArashiFeng Hi Arashi! Please take a look at the latest commit. We replaced |
|
Btw, |
Thanks. I'll try the latest commit later. |
|
|
We tested |
Sounds great! If it looks good to you we'll plan to merge it into the main stream after some tests. Please let us know if there is any other problem! |
Signed-off-by: jinjieliu <[email protected]>
Signed-off-by: jinjieliu <[email protected]>
Signed-off-by: jinjieliu <[email protected]>
Signed-off-by: Jinjie Liu <[email protected]>
Signed-off-by: Jinjie Liu <[email protected]>
8348894 to
05ccd51
Compare
PR Category
Other
Type of Change
New Feature
Description
This PR supports multi-sql-backends for
libcache. It's powered bysqlalchemy. The previous SQL backend is sqlite3, which doesn't support multi-writers at the same time, and may lead to some writing conflicts in the multi-workers cases. By introducing PostgreSQL as an available option forlibcache, which supports several writings at the same time, it could solve the problem.The details are recored in the document
docs/libcache_db_backend.md. Please refer to it for more details.Issue
Progress
Performance