From 19b41a9433e95f1b65ffc11e16662d24af1f269b Mon Sep 17 00:00:00 2001 From: Todor Ivanov Date: Tue, 1 Mar 2022 14:51:48 +0100 Subject: [PATCH] Swap NotMasterError with NotPrimaryError. Fix a depricated interface client.database_names() && Rename NotPrimaryError at MSUnmerged.py --- requirements.txt | 2 +- src/python/WMCore/Database/MongoDB.py | 2 +- .../WMCore/MicroService/MSUnmerged/MSUnmerged.py | 6 +++--- .../WMCore/MicroService/MSUnmerged/MSUnmergedRSE.py | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0a31c8a4a6..8465dd717c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ pep8~=1.7.1 # wmagent-devtools psutil~=5.8.0 # wmagent,wmagent-devtools,reqmgr2,reqmon,global-workqueue pycurl~=7.43.0.6 # wmagent,reqmgr2,reqmon,global-workqueue,reqmgr2ms pylint~=2.7.0 # wmagent-devtools -pymongo~=3.10.1 # wmagent-devtools,reqmgr2ms +pymongo~=4.0.1 # wmagent-devtools,reqmgr2ms pyOpenSSL~=18.0.0 # wmagent pyzmq~=19.0.2 # wmagent retry~=0.9.2 # wmagent,wmagent-devtools,reqmgr2,reqmon,global-workqueue,reqmgr2ms diff --git a/src/python/WMCore/Database/MongoDB.py b/src/python/WMCore/Database/MongoDB.py index 43f3b4611c..36d83e69e4 100644 --- a/src/python/WMCore/Database/MongoDB.py +++ b/src/python/WMCore/Database/MongoDB.py @@ -138,7 +138,7 @@ def _dbTest(self, db): raise ex # Test for database existence - if db not in self.client.database_names(): + if db not in self.client.list_database_names(): msg = "Missing MongoDB databases: %s" % db self.logger.error(msg) raise errors.InvalidName diff --git a/src/python/WMCore/MicroService/MSUnmerged/MSUnmerged.py b/src/python/WMCore/MicroService/MSUnmerged/MSUnmerged.py index d9557328ea..8f4b901945 100644 --- a/src/python/WMCore/MicroService/MSUnmerged/MSUnmerged.py +++ b/src/python/WMCore/MicroService/MSUnmerged/MSUnmerged.py @@ -29,7 +29,7 @@ gfal2 = None from pymongo import IndexModel -from pymongo.errors import NotMasterError +from pymongo.errors import NotPrimaryError # WMCore modules from WMCore.MicroService.DataStructs.DefaultStructs import UNMERGED_REPORT @@ -517,7 +517,7 @@ def consRecordAge(self, rse): self.logger.info(msg) try: rse.resetRSE(self.msUnmergedColl, keepTimestamps=True, retryCount=self.msConfig['mongoDBRetryCount']) - except NotMasterError: + except NotPrimaryError: msg = "Could not reset RSE to MongoDB for the maximum of %s mongoDBRetryCounts configured." % self.msConfig['mongoDBRetryCount'] msg += "Giving up now. The whole cleanup process will be retried for this RSE on the next run." msg += "Duplicate deletion retries may cause error messages from false positives and wrong counters during next polling cycle." @@ -803,7 +803,7 @@ def uploadRSEToMongoDB(self, rse, fullRSEToDB=False, overwrite=True): try: self.logger.info("RSE: %s Writing rse data to MongoDB." % rse['name']) rse.writeRSEToMongoDB(self.msUnmergedColl, fullRSEToDB=fullRSEToDB, overwrite=overwrite, retryCount=self.msConfig['mongoDBRetryCount']) - except NotMasterError: + except NotPrimaryError: msg = "Could not write RSE to MongoDB for the maximum of %s mongoDBRetryCounts configured." % self.msConfig['mongoDBRetryCount'] msg += "Giving up now. The whole cleanup process will be retried for this RSE on the next run." msg += "Duplicate deletion retries may cause error messages from false positives and wrong counters during next polling cycle." diff --git a/src/python/WMCore/MicroService/MSUnmerged/MSUnmergedRSE.py b/src/python/WMCore/MicroService/MSUnmerged/MSUnmergedRSE.py index 743e20fc09..94252cf062 100644 --- a/src/python/WMCore/MicroService/MSUnmerged/MSUnmergedRSE.py +++ b/src/python/WMCore/MicroService/MSUnmerged/MSUnmergedRSE.py @@ -3,7 +3,7 @@ Description: Provides a document Template for the MSUnmerged MicroServices """ -from pymongo.errors import NotMasterError +from pymongo.errors import NotPrimaryError # from pymongo.results import results as MongoResults @@ -130,7 +130,7 @@ def writeRSEToMongoDB(self, collection, fullRSEToDB=False, overwrite=False, retr the database is about to be completely replaced or just fields update is to happen. :param retryCount: The number of retries for the write operation if failed due to - `NotMasterError. Possible values: + `NotPrimaryError. Possible values: 0 - the write operation will be tried exactly once and no retries will happen > 0 - the write operation will be retried this number of times < 0 - the write operation will never be tried @@ -166,7 +166,7 @@ def writeRSEToMongoDB(self, collection, fullRSEToDB=False, overwrite=False, retr updateFields[field] = self[field] updateOps = {'$set': updateFields} - # NOTE: NotMasterError is a recoverable error, caused by a session to a + # NOTE: NotPrimaryError is a recoverable error, caused by a session to a # non primary backend part of a replicaset. while retryCount >= 0: try: @@ -175,7 +175,7 @@ def writeRSEToMongoDB(self, collection, fullRSEToDB=False, overwrite=False, retr else: result = collection.update_one(self.mongoFilter, updateOps, upsert=True) break - except NotMasterError: + except NotPrimaryError: if retryCount: # msg = "Failed write operation to MongoDB. %s retries left." # self.logger.warning(msg, retryCount) @@ -198,7 +198,7 @@ def resetRSE(self, collection, keepTimestamps=False, keepCounters=False, retryCo document to MongoDB :param keepTimestamps: Bool flag to keep the timestamps :param keepCounters: Bool flag to keep the counters - :param retryCount: The number of retries for the write operation if failed due to `NotMasterError. + :param retryCount: The number of retries for the write operation if failed due to `NotPrimaryError. :return: True if operation succeeded. """ resetDoc = self.defaultDoc()