Conversation
@fstagni regarding issue #401. I checked the main repository code and what is described in this issue is not there the issue is based on commit outside of any branch, most likely in fork outside of the repository diracx/diracx-routers/src/diracx/routers/jobs/status.py Lines 174 to 180 in 7c260cc |
|
Hi, since #410 was created, the mentioned code has been moved and refactored, and can now be found in https://github.com/DIRACGrid/diracx/blob/main/diracx-logic/src/diracx/logic/jobs/status.py#L643. The issue anyway still holds, can you have a look? |
for more information, see https://pre-commit.ci
…mentation for MockOSDBMixin class
| response, | ||
| ) | ||
|
|
||
| async def bulk_upsert( |
There was a problem hiding this comment.
bulk_upsert would need to overridden within job_parameters_db because we are inserting a JobID and a timestamp:
diracx/diracx-db/src/diracx/db/os/job_parameters.py
Lines 37 to 43 in 202f84c
Here it would not work I think (and it looks like it's not spotted within the tests).
I actually wonder whether upsert is useful now that we have bulk_upsert.
I would suggest we just drop upsert and replace it everywhere with bulk_upsert, what do you think?
There was a problem hiding this comment.
This is fixed now in 6d2984c
But I against dropping upsert in favor of bulk_upsert for simple reason. The code, e.g. https://github.com/DIRACGrid/diracx/blob/main/diracx-logic/src/diracx/logic/jobs/status.py#L225, uses external for loop and insert each document individually while going through that loop. To use bulk_upsert would require in this place to either use generator or allocate more memory to collect all documents and then insert them in bulk. There are cases when one API is preferable vs another. Since I can't find usage of generators I think the upsert has its place in a code.
| if new_application: | ||
| job_data["ApplicationStatus"] = new_application | ||
|
|
||
| await job_parameters_db.upsert(res["VO"], job_id, {"Status": new_status}) |
There was a problem hiding this comment.
bulk_upsert could (should) be used here too I think
There was a problem hiding this comment.
It can but it would either refactor code to use generators or use additional memory allocation to collect all documents. Either task seems beyond this PR scope.
| self.client, | ||
| actions, | ||
| raise_on_error=False, | ||
| raise_on_exception=False, |
There was a problem hiding this comment.
I'm just wondering what happens if there is a connection issue with the DB and no exception is raised.
I guess you would get 0 success, N errors but would get any information to know that there is an issue with the DB itself?
There was a problem hiding this comment.
Also I am wondering whether it would make sense to use max_retries and initial_backoff:
https://github.com/opensearch-project/opensearch-py/blob/213b7d6b2890c19bc83ebce0a9886d7571760240/opensearchpy/_async/helpers/actions.py#L188-L192
There was a problem hiding this comment.
in order to use this features it would be desired to have them configurable rather using hard-coded defaults. At the moment (based on my limited scope of the code) I don't know how configuration work and if desired this can be done through a separate issue/PR.
There was a problem hiding this comment.
I'm just wondering what happens if there is a connection issue with the DB and no exception is raised. I guess you would get 0 success, N errors but would get any information to know that there is an issue with the DB itself?
this is up to upstream code. Since it is external we can't reliably tell what is current and future functionality would be.
| if errors: | ||
| for error in errors: | ||
| logger.error("bulk insert error %s", error) | ||
| raise DocumentUpsertError("Failed to perform bulk insert operation") |
There was a problem hiding this comment.
I assume this piece of code is generic because will be reused every time there is an error.
Wouldn't it make sense to raise the DocumentUpsertError from diracx-db itself? So that this part of the code only lives in db/os/utils and is automatically reused by the callers
There was a problem hiding this comment.
this is architectural choice, your suggestion to through exception in base bulk_upsert API while mine is to pass errors to upstream and let this code decide what to do. If you can provide specific use-case when exception is better I'll be happy to move this part down the stream and through exception in a base class.
There was a problem hiding this comment.
Isn't there some duplication with https://github.com/DIRACGrid/diracx/blob/d72016500fb6cfd73350aa7b2582c5dd2cdcf2d2/diracx-db/tests/opensearch/test_search.py?
This PR fixes issue #401 by introducing the
bulk_upsertAPI to BaseOSDB class. It is also complement by full set of unit tests for BaseOSDB class which were missing. The unit test introduces mock client and different classes for different use cases.Depends on #1007
Please note: it is my first PR and I'm happy to adjust it according to requirements/guidelines of DiracX community.