Skip to content

Commit

Permalink
Merge pull request #79 from LiilyZhang/issue78
Browse files Browse the repository at this point in the history
Issue 78 - Change MongoSleepTimeBetweenRetry from Seconds to Millisec…
  • Loading branch information
dabooz authored Aug 6, 2021
2 parents b294c51 + 4d2b42d commit ca1fc8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions core/storage/mongoStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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)}
Expand All @@ -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)}
Expand Down Expand Up @@ -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)}
Expand Down
4 changes: 2 additions & 2 deletions samples/send-receive-files/css-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions samples/send-receive-files/ess-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ca1fc8a

Please sign in to comment.