mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/backup: add MustStop() method for all remote filesystems
This commit is contained in:
parent
cf5f2874cd
commit
b449607181
7 changed files with 34 additions and 0 deletions
|
@ -91,6 +91,8 @@ func main() {
|
|||
logger.Fatalf("cannot create backup: %s", err)
|
||||
}
|
||||
srcFS.MustStop()
|
||||
dstFS.MustStop()
|
||||
originFS.MustStop()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
|
|
|
@ -52,6 +52,7 @@ func main() {
|
|||
if err := a.Run(); err != nil {
|
||||
logger.Fatalf("cannot restore from backup: %s", err)
|
||||
}
|
||||
srcFS.MustStop()
|
||||
dstFS.MustStop()
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
// This filesystem is used for performing server-side file copies
|
||||
// instead of uploading data from local filesystem.
|
||||
type OriginFS interface {
|
||||
// MustStop must be called when the RemoteFS is no longer needed.
|
||||
MustStop()
|
||||
|
||||
// String must return human-readable representation of OriginFS.
|
||||
String() string
|
||||
|
||||
|
@ -18,6 +21,9 @@ type OriginFS interface {
|
|||
|
||||
// RemoteFS is a filesystem where backups are stored.
|
||||
type RemoteFS interface {
|
||||
// MustStop must be called when the RemoteFS is no longer needed.
|
||||
MustStop()
|
||||
|
||||
// String must return human-readable representation of RemoteFS.
|
||||
String() string
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@ import (
|
|||
// FS represents nil remote filesystem.
|
||||
type FS struct{}
|
||||
|
||||
// MustStop stops fs.
|
||||
func (fs *FS) MustStop() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
// String returns human-readable string representation for fs.
|
||||
func (fs *FS) String() string {
|
||||
return "fsnil"
|
||||
|
|
|
@ -22,6 +22,11 @@ type FS struct {
|
|||
Dir string
|
||||
}
|
||||
|
||||
// MustStop stops fs.
|
||||
func (fs *FS) MustStop() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
// String returns human-readable string representation for fs.
|
||||
func (fs *FS) String() string {
|
||||
return fmt.Sprintf("fsremote %q", fs.Dir)
|
||||
|
|
|
@ -33,6 +33,8 @@ type FS struct {
|
|||
}
|
||||
|
||||
// Init initializes fs.
|
||||
//
|
||||
// The returned fs must be stopped when no long needed with MustStop call.
|
||||
func (fs *FS) Init() error {
|
||||
if fs.bkt != nil {
|
||||
logger.Panicf("BUG: fs.Init has been already called")
|
||||
|
@ -63,6 +65,11 @@ func (fs *FS) Init() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MustStop stops fs.
|
||||
func (fs *FS) MustStop() {
|
||||
fs.bkt = nil
|
||||
}
|
||||
|
||||
// String returns human-readable description for fs.
|
||||
func (fs *FS) String() string {
|
||||
return fmt.Sprintf("GCS{bucket: %q, dir: %q}", fs.Bucket, fs.Dir)
|
||||
|
|
|
@ -45,6 +45,8 @@ type FS struct {
|
|||
}
|
||||
|
||||
// Init initializes fs.
|
||||
//
|
||||
// The returned fs must be stopped when no long needed with MustStop call.
|
||||
func (fs *FS) Init() error {
|
||||
if fs.s3 != nil {
|
||||
logger.Panicf("BUG: Init is already called")
|
||||
|
@ -96,6 +98,12 @@ func (fs *FS) Init() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MustStop stops fs.
|
||||
func (fs *FS) MustStop() {
|
||||
fs.s3 = nil
|
||||
fs.uploader = nil
|
||||
}
|
||||
|
||||
// String returns human-readable description for fs.
|
||||
func (fs *FS) String() string {
|
||||
return fmt.Sprintf("S3{bucket: %q, dir: %q}", fs.Bucket, fs.Dir)
|
||||
|
|
Loading…
Reference in a new issue