Skip to content

Commit

Permalink
with panic
Browse files Browse the repository at this point in the history
  • Loading branch information
gojoy committed May 8, 2018
1 parent 69b7df0 commit 2b78fb0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
2 changes: 2 additions & 0 deletions supervisor/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ func (t *MigrationTask) startMigrationTask(c *containerInfo) error {
}
log.Printf("direct time:%v\n",time.Since(st))

panic("test done!")

log.Println("copy checkpoint dir")
if err = l.CopyCheckPointToRemote(r); err != nil {
return err
Expand Down
24 changes: 22 additions & 2 deletions supervisor/migration/containerUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,28 @@ func getmap(files []string) map[string]bool {
res[v]=true
}
}
if _,ok:=res["ib_logfile0"];ok {
delete(res,"ib_logfile0")

if _,ok:=res["ib_logfile1"];!ok {
if _,ok:=res["ib_logfile0"];ok {
delete(res,"ib_logfile0")
}
}

return res
}

func getstablerelatepath(files []string,vol Volumes) []string {
var (
res=make([]string,0)
)
if len(files)==0 {
panic("files len is 0")
}
for _,v:=range files {
right := strings.TrimPrefix(v, vol.src)
if len(right) != len(v) {
res = append(res, right[1:])
}
}
return res
}
22 changes: 17 additions & 5 deletions supervisor/migration/fdsSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"strings"
"errors"
)


Expand Down Expand Up @@ -35,7 +36,10 @@ func fdsSync(checkpointDir string, remoteVolumesDirs string, vols Volumes, ip st
log.Println(err)
return err
}
deletefromstablemap(syncfiles,smap)

log.Printf("before delete,len is %v,syncfiles is %v",len(syncfiles),syncfiles)
syncfiles=deletefromstablemap(syncfiles,smap)
log.Printf("now len is %v,syncfiles is %v\n",len(syncfiles),syncfiles)

if err = fastCopy(syncfiles, ip, remoteVolumesDirs, vols); err != nil {
log.Println(err)
Expand All @@ -44,16 +48,23 @@ func fdsSync(checkpointDir string, remoteVolumesDirs string, vols Volumes, ip st
return nil
}

func deletefromstablemap(files []string, stmap map[string]bool) {
func deletefromstablemap(files []string, stmap map[string]bool) []string {

if len(files)==0 {
panic("files is 0")
}
if len(stmap)==0 {
log.Println("stmap is 0")
}
for i:=0;i<len(files);i++ {
if stmap[files[i]]==true {
log.Printf("delete %v\n",files[i])
files[i]=files[len(files)-1]
files=files[:len(files)-1]
i--
}
i--
}
return files
}

//将打开的文件保存到/run/migration/is/openfile.jsob目录下
Expand Down Expand Up @@ -112,7 +123,6 @@ func getFiles(path string) ([]string, error) {
args = append(args, path, "fds")
cmd := exec.Command("crit", args...)
out, err := cmd.Output()
log.Println(cmd.Args)
if err != nil {
log.Println(err, string(out))
return res, err
Expand All @@ -138,6 +148,7 @@ func getFiles(path string) ([]string, error) {

//找到再数据卷中的文件
func syncNeedFiles(files []string, vol Volumes) []string {
log.Printf("dst is %v\n",vol.dst)
var (
res = make([]string, 0)
)
Expand Down Expand Up @@ -167,7 +178,8 @@ func fastCopy(files []string, ip string, remote string, vol Volumes) error {
err error
)
if len(files) == 0 {
return err
log.Println("files len is 0")
return errors.New("files nil")
}

//log.Printf("f is %v\n",files)
Expand Down
27 changes: 17 additions & 10 deletions supervisor/migration/localMigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ func (l *localMigration) CopyWriteVolToRemote(r *remoteMigration) error {
return err
}

remotepathback:=remotePath+"back"
if err = RemoteMkdirAll(remotepathback, r.sftpClient); err != nil {
log.Println(err)
return err
}
if err=RemoteCopyDirRsync(v.src,remotepathback,r.ip);err!=nil {
log.Println(err)
return err
}
//remotepathback:=remotePath+"back"
//if err = RemoteMkdirAll(remotepathback, r.sftpClient); err != nil {
// log.Println(err)
// return err
//}
//if err=RemoteCopyDirRsync(v.src,remotepathback,r.ip);err!=nil {
// log.Println(err)
// return err
//}
}
}
return nil
Expand Down Expand Up @@ -402,7 +402,14 @@ func (l *localMigration) Getstablefiles(v *volwatcher) (map[string]bool,error) {
log.Println(err)
return nil,err
}
relatepath:=syncNeedFiles(res,l.vols[l.writevolid])
//log.Printf("stablefileres is: %v\n",res)

//log.Printf("vols is %v\n",l.vols[l.writevolid])
relatepath:=getstablerelatepath(res,l.vols[l.writevolid])
log.Printf("relatepath len is %v\n",len(relatepath))
if len(relatepath)==0 {
panic("len is 0")
}

stablemap:=getmap(relatepath)

Expand Down

0 comments on commit 2b78fb0

Please sign in to comment.