forked from TrueCloudLab/rclone
dropbox: open the datastore in the background
This commit is contained in:
parent
d2f187e1a1
commit
e57a4c7c0c
1 changed files with 38 additions and 13 deletions
|
@ -100,6 +100,7 @@ type FsDropbox struct {
|
||||||
datastore *dropbox.Datastore
|
datastore *dropbox.Datastore
|
||||||
table *dropbox.Table
|
table *dropbox.Table
|
||||||
datastoreMutex sync.Mutex // lock this when using the datastore
|
datastoreMutex sync.Mutex // lock this when using the datastore
|
||||||
|
datastoreErr error // pending errors on the datastore
|
||||||
}
|
}
|
||||||
|
|
||||||
// FsObjectDropbox describes a dropbox object
|
// FsObjectDropbox describes a dropbox object
|
||||||
|
@ -171,17 +172,28 @@ func NewFs(name, path string) (fs.Fs, error) {
|
||||||
// Make a db to store rclone metadata in
|
// Make a db to store rclone metadata in
|
||||||
f.datastoreManager = db.NewDatastoreManager()
|
f.datastoreManager = db.NewDatastoreManager()
|
||||||
|
|
||||||
// Open the rclone datastore
|
// Open the datastore in the background
|
||||||
f.datastore, err = f.datastoreManager.OpenDatastore(datastoreName)
|
go func() {
|
||||||
if err != nil {
|
f.datastoreMutex.Lock()
|
||||||
return nil, err
|
defer f.datastoreMutex.Unlock()
|
||||||
}
|
fs.Debug(f, "Open rclone datastore")
|
||||||
|
// Open the rclone datastore
|
||||||
|
f.datastore, err = f.datastoreManager.OpenDatastore(datastoreName)
|
||||||
|
if err != nil {
|
||||||
|
fs.Log(f, "Failed to open datastore: %v", err)
|
||||||
|
f.datastoreErr = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get the table we are using
|
// Get the table we are using
|
||||||
f.table, err = f.datastore.GetTable(tableName)
|
f.table, err = f.datastore.GetTable(tableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
fs.Log(f, "Failed to open datastore table: %v", err)
|
||||||
}
|
f.datastoreErr = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fs.Debug(f, "Open rclone datastore finished")
|
||||||
|
}()
|
||||||
|
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
@ -368,6 +380,9 @@ func (f *FsDropbox) Purge() error {
|
||||||
func (f *FsDropbox) transaction(fn func() error) error {
|
func (f *FsDropbox) transaction(fn func() error) error {
|
||||||
f.datastoreMutex.Lock()
|
f.datastoreMutex.Lock()
|
||||||
defer f.datastoreMutex.Unlock()
|
defer f.datastoreMutex.Unlock()
|
||||||
|
if f.datastoreErr != nil {
|
||||||
|
return f.datastoreErr
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
for i := 1; i <= maxCommitRetries; i++ {
|
for i := 1; i <= maxCommitRetries; i++ {
|
||||||
err = fn()
|
err = fn()
|
||||||
|
@ -387,6 +402,18 @@ func (f *FsDropbox) transaction(fn func() error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads the record attached to key
|
||||||
|
//
|
||||||
|
// Holds datastore mutex while in progress
|
||||||
|
func (f *FsDropbox) readRecord(key string) (*dropbox.Record, error) {
|
||||||
|
f.datastoreMutex.Lock()
|
||||||
|
defer f.datastoreMutex.Unlock()
|
||||||
|
if f.datastoreErr != nil {
|
||||||
|
return nil, f.datastoreErr
|
||||||
|
}
|
||||||
|
return f.table.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
// Return the parent Fs
|
// Return the parent Fs
|
||||||
|
@ -493,9 +520,7 @@ func (o *FsObjectDropbox) readMetaData() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fs.Debug(o, "Reading metadata from datastore")
|
// fs.Debug(o, "Reading metadata from datastore")
|
||||||
o.dropbox.datastoreMutex.Lock()
|
record, err := o.dropbox.readRecord(o.metadataKey())
|
||||||
record, err := o.dropbox.table.Get(o.metadataKey())
|
|
||||||
o.dropbox.datastoreMutex.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debug(o, "Couldn't read metadata: %s", err)
|
fs.Debug(o, "Couldn't read metadata: %s", err)
|
||||||
record = nil
|
record = nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue