Skip to content

Commit 5e94076

Browse files
authored
Merge pull request #6802 from fstagni/80_fix_ES_updateDoc
[8.0] fix: wait and retry on ConflictError
2 parents 1aae0b2 + 3ef776a commit 5e94076

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/DIRAC/Core/Utilities/ElasticSearchDB.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import copy
77
import functools
88
import json
9+
import time
910
from datetime import datetime, timedelta
1011
from urllib import parse as urlparse
1112

@@ -15,7 +16,7 @@
1516
from opensearch_dsl import A, Q, Search
1617
from opensearchpy import OpenSearch as Elasticsearch
1718
from opensearchpy.exceptions import ConnectionError as ElasticConnectionError
18-
from opensearchpy.exceptions import NotFoundError, RequestError, TransportError
19+
from opensearchpy.exceptions import NotFoundError, RequestError, TransportError, ConflictError
1920
from opensearchpy.helpers import BulkIndexError, bulk
2021
except ImportError:
2122
from elasticsearch_dsl import Search, Q, A
@@ -25,6 +26,7 @@
2526
TransportError,
2627
NotFoundError,
2728
RequestError,
29+
ConflictError,
2830
)
2931
from elasticsearch.helpers import BulkIndexError, bulk
3032

@@ -76,7 +78,7 @@ def generateDocs(data, withTimeStamp=True):
7678
sLog.error("Wrong timestamp", e)
7779
doc["timestamp"] = int(TimeUtilities.toEpochMilliSeconds())
7880

79-
sLog.debug(f"yielding {doc}")
81+
sLog.debug("yielding", doc)
8082
yield doc
8183

8284

@@ -265,9 +267,15 @@ def updateDoc(self, index: str, docID: str, body) -> dict:
265267
"""
266268
sLog.debug(f"Updating document {docID} in index {index}")
267269
try:
268-
return S_OK(self.client.update(index, docID, body))
270+
self.client.update(index, docID, body)
271+
except ConflictError:
272+
# updates are rather "heavy" operations from ES point of view, needing seqNo to be updated.
273+
# Not ideal, but we just wait and retry.
274+
time.sleep(1)
275+
self.client.update(index, docID, body, params={"retry_on_conflict": 3})
269276
except RequestError as re:
270277
return S_ERROR(re)
278+
return S_OK()
271279

272280
@ifConnected
273281
def deleteDoc(self, index: str, docID: str):

0 commit comments

Comments
 (0)