Добавлена возможность асинхронного создания снапшотов
А также обновлены зависимости
This commit is contained in:
50
api.go
50
api.go
@@ -227,6 +227,56 @@ func (a *Agate) SaveSnapshot(ctx context.Context, name string, parentID string)
|
||||
return snapshot.ID, nil
|
||||
}
|
||||
|
||||
// SnapshotAsync creates a new snapshot asynchronously.
|
||||
// It returns the job ID (which is also the snapshot ID) immediately.
|
||||
// The actual snapshot creation happens in a background goroutine.
|
||||
// Use GetSnapshotStatus to check the progress.
|
||||
func (a *Agate) SnapshotAsync(ctx context.Context, name string, parentID string) (string, error) {
|
||||
a.options.Logger.Printf("Starting async snapshot creation with name: %s", name)
|
||||
|
||||
// If parentID is not provided, use the current snapshot ID
|
||||
if parentID == "" {
|
||||
parentID = a.currentSnapshotID
|
||||
}
|
||||
|
||||
return a.manager.CreateSnapshotAsync(ctx, a.options.BlobStore.GetActiveDir(), name, parentID,
|
||||
func() {
|
||||
// onStart: Lock mutex and close resources
|
||||
a.mutex.Lock()
|
||||
if a.options.CloseFunc != nil {
|
||||
if err := a.options.CloseFunc(); err != nil {
|
||||
a.options.Logger.Printf("ERROR: failed to close resources before async snapshot: %v", err)
|
||||
}
|
||||
}
|
||||
},
|
||||
func(id string, err error) {
|
||||
// onFinish: Open resources, update state, and unlock mutex
|
||||
defer a.mutex.Unlock()
|
||||
|
||||
if a.options.OpenFunc != nil {
|
||||
if err := a.options.OpenFunc(a.options.BlobStore.GetActiveDir()); err != nil {
|
||||
a.options.Logger.Printf("ERROR: failed to open resources after async snapshot: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
a.currentSnapshotID = id
|
||||
if err := a.saveCurrentSnapshotID(); err != nil {
|
||||
a.options.Logger.Printf("ERROR: failed to save current snapshot ID: %v", err)
|
||||
}
|
||||
a.options.Logger.Printf("Async snapshot %s created successfully", id)
|
||||
} else {
|
||||
a.options.Logger.Printf("Async snapshot creation failed: %v", err)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GetSnapshotStatus returns the status of an asynchronous snapshot creation job.
|
||||
func (a *Agate) GetSnapshotStatus(ctx context.Context, jobID string) (*store.SnapshotStatus, error) {
|
||||
return a.manager.GetSnapshotStatus(ctx, jobID)
|
||||
}
|
||||
|
||||
// RestoreSnapshot extracts a snapshot to the active directory.
|
||||
func (a *Agate) RestoreSnapshot(ctx context.Context, snapshotID string) error {
|
||||
a.mutex.Lock()
|
||||
|
||||
Reference in New Issue
Block a user