diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-09-01 01:27:45 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-09-01 01:27:45 -0700 |
| commit | 3faaa6e3601d233805c4358b32a9b853add579ff (patch) | |
| tree | aca05f3a1f6660cfa9c77475beb1248cbd5f8b0c | |
| parent | 8e125339d51adb290ed985a4a5deb5dd223a3fdd (diff) | |
| download | seaweedfs-3faaa6e3601d233805c4358b32a9b853add579ff.tar.xz seaweedfs-3faaa6e3601d233805c4358b32a9b853add579ff.zip | |
ensure cached client with updated storage conf
| -rw-r--r-- | weed/remote_storage/remote_storage.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/weed/remote_storage/remote_storage.go b/weed/remote_storage/remote_storage.go index af65ca677..4d0b5db8d 100644 --- a/weed/remote_storage/remote_storage.go +++ b/weed/remote_storage/remote_storage.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/remote_pb" + "github.com/golang/protobuf/proto" "io" "strings" "sync" @@ -76,9 +77,14 @@ type RemoteStorageClientMaker interface { HasBucket() bool } +type CachedRemoteStorageClient struct { + *remote_pb.RemoteConf + RemoteStorageClient +} + var ( RemoteStorageClientMakers = make(map[string]RemoteStorageClientMaker) - remoteStorageClients = make(map[string]RemoteStorageClient) + remoteStorageClients = make(map[string]CachedRemoteStorageClient) remoteStorageClientsLock sync.Mutex ) @@ -107,8 +113,8 @@ func GetRemoteStorage(remoteConf *remote_pb.RemoteConf) (RemoteStorageClient, er defer remoteStorageClientsLock.Unlock() existingRemoteStorageClient, found := remoteStorageClients[remoteConf.Name] - if found { - return existingRemoteStorageClient, nil + if found && proto.Equal(existingRemoteStorageClient.RemoteConf, remoteConf) { + return existingRemoteStorageClient.RemoteStorageClient, nil } newRemoteStorageClient, err := makeRemoteStorageClient(remoteConf) @@ -116,7 +122,10 @@ func GetRemoteStorage(remoteConf *remote_pb.RemoteConf) (RemoteStorageClient, er return nil, fmt.Errorf("make remote storage client %s: %v", remoteConf.Name, err) } - remoteStorageClients[remoteConf.Name] = newRemoteStorageClient + remoteStorageClients[remoteConf.Name] = CachedRemoteStorageClient{ + RemoteConf: remoteConf, + RemoteStorageClient: newRemoteStorageClient, + } return newRemoteStorageClient, nil } |
