From a7dbf32c538db8d57b8c0a4088934ba5c0ec431d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 8 Mar 2018 12:16:18 +0000 Subject: [PATCH] cache: Implement --cache-db-wait-time flag This can be used to make the cache wait for other running cache backends to finish rather than erroring after 1 second. --- backend/cache/cache.go | 3 +++ backend/cache/storage_persistent.go | 2 +- docs/content/cache.md | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/cache/cache.go b/backend/cache/cache.go index d25e83892..a554ec316 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -50,6 +50,8 @@ const ( DefCacheWrites = false // DefCacheTmpWaitTime says how long should files be stored in local cache before being uploaded DefCacheTmpWaitTime = "15m" + // DefCacheDbWaitTime defines how long the cache backend should wait for the DB to be available + DefCacheDbWaitTime = 1 * time.Second ) // Globals @@ -69,6 +71,7 @@ var ( cacheStoreWrites = flags.BoolP("cache-writes", "", DefCacheWrites, "Will cache file data on writes through the FS") cacheTempWritePath = flags.StringP("cache-tmp-upload-path", "", "", "Directory to keep temporary files until they are uploaded to the cloud storage") cacheTempWaitTime = flags.StringP("cache-tmp-wait-time", "", DefCacheTmpWaitTime, "How long should files be stored in local cache before being uploaded") + cacheDbWaitTime = flags.DurationP("cache-db-wait-time", "", DefCacheDbWaitTime, "How long to wait for the DB to be available - 0 is unlimited") ) // Register with Fs diff --git a/backend/cache/storage_persistent.go b/backend/cache/storage_persistent.go index bbc77c2a4..894d79e92 100644 --- a/backend/cache/storage_persistent.go +++ b/backend/cache/storage_persistent.go @@ -122,7 +122,7 @@ func (b *Persistent) connect() error { if err != nil { return errors.Wrapf(err, "failed to create a data directory %q", b.dataPath) } - b.db, err = bolt.Open(b.dbPath, 0644, &bolt.Options{Timeout: 1 * time.Second}) + b.db, err = bolt.Open(b.dbPath, 0644, &bolt.Options{Timeout: *cacheDbWaitTime}) if err != nil { return errors.Wrapf(err, "failed to open a cache connection to %q", b.dbPath) } diff --git a/docs/content/cache.md b/docs/content/cache.md index 49cfc27a2..23a9d947c 100644 --- a/docs/content/cache.md +++ b/docs/content/cache.md @@ -397,3 +397,13 @@ Note that only one file is uploaded at a time and it can take longer to start the upload if a queue formed for this purpose. **Default**: 15m + +#### --cache-db-wait-time=DURATION #### + +Only one process can have the DB open at any one time, so rclone waits +for this duration for the DB to become available before it gives an +error. + +If you set it to 0 then it will wait forever. + +**Default**: 1s