Skip to content

Commit 53ba4e7

Browse files
authored
Add DbsApi wrapper to catch and retry ORA-00001, failed block publication. (#9315)
* DbsApi wrapper to retry/catch ORA-00001 failed. * random jitter between [10s, 3mins] to avoid race.
1 parent db4d4b9 commit 53ba4e7

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/python/Publisher/PublisherDbsUtils.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,41 @@
88
import logging
99
import json
1010
import time
11+
from random import uniform
1112
from datetime import datetime
1213

13-
from dbs.apis.dbsClient import DbsApi
14+
from dbs.apis.dbsClient import DbsApi as DbsApiBase
1415
from dbs.exceptions.dbsClientException import dbsClientException
1516
from RestClient.ErrorHandling.RestClientExceptions import HTTPError
1617

1718
from TaskWorker.WorkerExceptions import CannotMigrateException
1819

20+
MAX_RETRY_ATTEMPTS = 3
21+
MIN_RETRY_DELAY = 10
22+
MAX_RETRY_DELAY = 3 * 60 # 3 minutes
23+
24+
logger = logging.getLogger(__name__)
25+
26+
class DbsApi(DbsApiBase):
27+
28+
def insertBulkBlock(self, block_dump):
29+
retry_count = 0
30+
last_ex = None
31+
while retry_count < MAX_RETRY_ATTEMPTS:
32+
try:
33+
return super().insertBulkBlock(block_dump)
34+
except HTTPError as ex:
35+
last_ex = ex
36+
body = json.loads(ex.body)
37+
reason = body[0]['error']['reason']
38+
if ex.code == 400 and 'ORA-00001' in reason:
39+
block_name = block_dump['block']['block_name']
40+
logger.info(f"Retry {retry_count+1} of {MAX_RETRY_ATTEMPTS} for inserting bulk block {block_name}")
41+
time.sleep(uniform(MIN_RETRY_DELAY, MAX_RETRY_DELAY))
42+
retry_count += 1
43+
continue
44+
raise
45+
raise Exception(f"Error inserting bulk block: {last_ex} after {MAX_RETRY_ATTEMPTS} attempts") from last_ex
1946

2047
def format_file_3(file_):
2148
"""

0 commit comments

Comments
 (0)