From 4d2b42d8b75049d2098fda7c01437f55368efb86 Mon Sep 17 00:00:00 2001 From: zhangl Date: Fri, 6 Aug 2021 14:57:09 -0400 Subject: [PATCH] Issue 78 - Change MongoSleepTimeBetweenRetry from Seconds to Milliseconds Signed-off-by: zhangl --- common/config.go | 4 ++-- core/storage/mongoStorage.go | 22 +++++++++++----------- samples/send-receive-files/css-http.conf | 4 ++-- samples/send-receive-files/ess-http.conf | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common/config.go b/common/config.go index c1f14a8..05c35d7 100644 --- a/common/config.go +++ b/common/config.go @@ -278,7 +278,7 @@ type Config struct { // MongoSessionCacheSize specifies the number of MongoDB session copies to use MongoSessionCacheSize int `env:"MONGO_SESSION_CACHE_SIZE"` - // MongoSleepTimeBetweenRetry specifies the time in seconds between each retry of updating data in mongodb + // MongoSleepTimeBetweenRetry specifies the time in milliseconds between each retry of updating data in mongodb MongoSleepTimeBetweenRetry int `env:"MONGO_SLEEP_TIME_BETWEEN_RETRY"` // DatabaseConnectTimeout specifies that the timeout in seconds of database connection attempts on startup @@ -698,7 +698,7 @@ func SetDefaultConfig(config *Config) { config.MongoCACertificate = "" config.MongoAllowInvalidCertificates = false config.MongoSessionCacheSize = 1 - config.MongoSleepTimeBetweenRetry = 2 + config.MongoSleepTimeBetweenRetry = 2000 config.DatabaseConnectTimeout = 300 config.StorageMaintenanceInterval = 30 config.ObjectActivationInterval = 30 diff --git a/core/storage/mongoStorage.go b/core/storage/mongoStorage.go index a98c986..65381cc 100644 --- a/core/storage/mongoStorage.go +++ b/core/storage/mongoStorage.go @@ -105,7 +105,7 @@ type aclObject struct { const maxUpdateTries = 5 -var sleepInSec int +var sleepInMS int // Init initializes the MongoStorage store func (store *MongoStorage) Init() common.SyncServiceError { @@ -249,7 +249,7 @@ func (store *MongoStorage) Init() common.SyncServiceError { store.openFiles = make(map[string]*fileHandle) - sleepInSec = common.Configuration.MongoSleepTimeBetweenRetry + sleepInMS = common.Configuration.MongoSleepTimeBetweenRetry if trace.IsLogging(logger.TRACE) { trace.Trace("Successfully initialized mongo driver") @@ -431,7 +431,7 @@ func (store *MongoStorage) UpdateObjectDestinations(orgID string, objectType str } if err := store.update(objects, bson.M{"_id": id, "last-update": result.LastUpdate}, query); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return nil, "", nil, nil, &Error{fmt.Sprintf("Failed to update object's destinations. Error: %s.", err)} @@ -463,7 +463,7 @@ func (store *MongoStorage) AddObjectDestinations(orgID string, objectType string } if err := store.update(objects, bson.M{"_id": id, "last-update": result.LastUpdate}, query); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return nil, "", nil, &Error{fmt.Sprintf("Failed to add destinations to object's destinations list. Error: %s.", err)} @@ -495,7 +495,7 @@ func (store *MongoStorage) DeleteObjectDestinations(orgID string, objectType str } if err := store.update(objects, bson.M{"_id": id, "last-update": result.LastUpdate}, query); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return nil, "", nil, &Error{fmt.Sprintf("Failed to delete destinations from object's destinations list. Error: %s.", err)} @@ -561,7 +561,7 @@ func (store *MongoStorage) UpdateObjectDeliveryStatus(status string, message str } if err := store.update(objects, bson.M{"_id": id, "last-update": result.LastUpdate}, query); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return false, &Error{fmt.Sprintf("Failed to update object's destinations. Error: %s.", err)} @@ -591,7 +591,7 @@ func (store *MongoStorage) UpdateObjectDelivering(orgID string, objectType strin "$currentDate": bson.M{"last-update": bson.M{"$type": "timestamp"}}, }); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return &Error{fmt.Sprintf("Failed to update object's destinations. Error: %s.", err)} @@ -925,7 +925,7 @@ OUTER: "$currentDate": bson.M{"last-update": bson.M{"$type": "timestamp"}}, }); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue OUTER } return nil, &Error{fmt.Sprintf("Failed to update object's destinations. Error: %s.", err)} @@ -1325,7 +1325,7 @@ func (store *MongoStorage) AddWebhook(orgID string, objectType string, url strin result.ID = id if err = store.insert(webhooks, result); err != nil { if mgo.IsDup(err) { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return &Error{fmt.Sprintf("Failed to insert a webhook. Error: %s.", err)} @@ -1348,7 +1348,7 @@ func (store *MongoStorage) AddWebhook(orgID string, objectType string, url strin "$currentDate": bson.M{"last-update": bson.M{"$type": "timestamp"}}, }); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return &Error{fmt.Sprintf("Failed to add a webhook. Error: %s.", err)} @@ -1387,7 +1387,7 @@ func (store *MongoStorage) DeleteWebhook(orgID string, objectType string, url st "$currentDate": bson.M{"last-update": bson.M{"$type": "timestamp"}}, }); err != nil { if err == mgo.ErrNotFound { - time.Sleep(time.Duration(sleepInSec) * time.Second) + time.Sleep(time.Duration(sleepInMS) * time.Millisecond) continue } return &Error{fmt.Sprintf("Failed to delete a webhook. Error: %s.", err)} diff --git a/samples/send-receive-files/css-http.conf b/samples/send-receive-files/css-http.conf index 70197dd..ce64e67 100644 --- a/samples/send-receive-files/css-http.conf +++ b/samples/send-receive-files/css-http.conf @@ -362,8 +362,8 @@ MongoAuthDbName d_edge # Environment variable: MONGO_ALLOW_INVALID_CERTIFICATES # MongoAllowInvalidCertificates -# MongoSleepTimeBetweenRetry specifies the time in seconds between each retry of updating data in mongodb -# Default is 2 +# MongoSleepTimeBetweenRetry specifies the time in milliseconds between each retry of updating data in mongodb +# Default is 2000 # Environment variable: MONGO_SLEEP_TIME_BETWEEN_RETRY # MongoSleepTimeBetweenRetry diff --git a/samples/send-receive-files/ess-http.conf b/samples/send-receive-files/ess-http.conf index d1a73fd..f27bd73 100644 --- a/samples/send-receive-files/ess-http.conf +++ b/samples/send-receive-files/ess-http.conf @@ -362,8 +362,8 @@ TraceRootPath ./trace1 # Environment variable: MONGO_ALLOW_INVALID_CERTIFICATES # MongoAllowInvalidCertificates -# MongoSleepTimeBetweenRetry specifies the time in seconds between each retry of updating data in mongodb -# Default is 2 +# MongoSleepTimeBetweenRetry specifies the time in milliseconds between each retry of updating data in mongodb +# Default is 2000 # Environment variable: MONGO_SLEEP_TIME_BETWEEN_RETRY # MongoSleepTimeBetweenRetry