Skip to content

Commit

Permalink
fix: Restore Appspace stops sandbox first
Browse files Browse the repository at this point in the history
- fixes #131
  • Loading branch information
teleclimber committed Aug 14, 2024
1 parent e27ba99 commit 9585ea7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/ds-host/appspaceops/restoreappspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type RestoreAppspace struct {
CheckDataFiles(dataDir string) error
ReplaceData(appspace domain.Appspace, source string) error
} `checkinject:"required"`
SandboxManager interface {
StopAppspace(domain.AppspaceID)
} `checkinject:"required"`
AppspaceStatus interface {
WaitTempPaused(appspaceID domain.AppspaceID, reason string) chan struct{}
IsTempPaused(appspaceID domain.AppspaceID) bool
Expand Down Expand Up @@ -188,6 +191,8 @@ func (r *RestoreAppspace) GetMetaInfo(tok string) (domain.AppspaceMetaInfo, erro

// ReplaceData stops the appspace and replaces the data files
func (r *RestoreAppspace) ReplaceData(tok string, appspaceID domain.AppspaceID) error {
r.SandboxManager.StopAppspace(appspaceID)

closedCh, ok := r.AppspaceStatus.LockClosed(appspaceID)
if !ok {
return errors.New("failed to get lock closed")
Expand Down
7 changes: 5 additions & 2 deletions cmd/ds-host/appspaceops/restoreappspace_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package appspaceops

import (
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -12,7 +11,7 @@ import (
)

func TestDelete(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -53,6 +52,9 @@ func TestReplaceData(t *testing.T) {

closedChan := make(chan struct{})

sandboxManager := testmocks.NewMockSandboxManager(mockCtrl)
sandboxManager.EXPECT().StopAppspace(asID)

appspaceStatus := testmocks.NewMockAppspaceStatus(mockCtrl)
appspaceStatus.EXPECT().LockClosed(asID).Return(closedChan, true)

Expand All @@ -69,6 +71,7 @@ func TestReplaceData(t *testing.T) {
appspaceFilesModels.EXPECT().ReplaceData(appspace, tempDir).Return(nil)

r := &RestoreAppspace{
SandboxManager: sandboxManager,
AppspaceStatus: appspaceStatus,
AppspaceMetaDB: appspaceMetaDB,
AppspaceLogger: appspaceLogger,
Expand Down
1 change: 1 addition & 0 deletions cmd/ds-host/ds-host.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func main() {
InfoModel: appspaceInfoModel,
AppspaceModel: appspaceModel,
AppspaceFilesModel: appspaceFilesModel,
SandboxManager: sandboxManager,
AppspaceStatus: nil,
AppspaceMetaDB: appspaceMetaDb,
AppspaceLogger: appspaceLogger,
Expand Down

0 comments on commit 9585ea7

Please sign in to comment.