Skip to content

Commit

Permalink
version1
Browse files Browse the repository at this point in the history
  • Loading branch information
gojoy committed Mar 16, 2018
1 parent 0d0c9fe commit b5aea88
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
41 changes: 41 additions & 0 deletions supervisor/migration/lazycopydir/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lazycopydir

import "time"


//crwdir 挂载的nfs目录 monidiruper读写层目录 lazydir 惰复制目录
func StartLazyCopy(crwdir, monidir, lazydir string) error {

Expand Down Expand Up @@ -36,3 +37,43 @@ func StartLazyCopy(crwdir, monidir, lazydir string) error {
glog.Println("finish lazycopy!")
return nil
}

func (replicator *LazyReplicator) Prelazy() error {
var (
err error
)

if err = replicator.Crawler(); err != nil {
glog.Println(err)
return err
}

go func() {
err = replicator.Monitor()
if err != nil {
glog.Println(err)
panic(err)
}
}()

return nil
}
func (replicator *LazyReplicator) Dolazycopy() error {

var (
err error
)

if err = replicator.Replicate(); err != nil {
glog.Println(err)
panic(err)
}

replicator.CancelMonitor()

time.Sleep(1 * time.Second)

glog.Println("finish lazycopy!")

return nil
}
33 changes: 30 additions & 3 deletions supervisor/migration/preMigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type PreMigrationInTargetMachine struct {
SrcIp string
}

var (
lazyreplicator=make([]*lazycopydir.LazyReplicator,0)
)

func (p *PreMigrationInTargetMachine) StartPre() error {
var (
err error
Expand Down Expand Up @@ -58,6 +62,12 @@ func (p *PreMigrationInTargetMachine) StartPre() error {
return err
}

glog.Println("pre lazycopy")
if err=p.StartPreLazyCopy();err!=nil {
glog.Println(err)
return err
}

glog.Println("start docker container")
if err=p.StartDockerContainer();err!=nil {
glog.Println(err)
Expand Down Expand Up @@ -252,22 +262,39 @@ func (p *PreMigrationInTargetMachine) PreLazyDir() error {
return nil
}

func (p *PreMigrationInTargetMachine) StartLazyCopy() error {
func (p *PreMigrationInTargetMachine) StartPreLazyCopy() error {
var (
err error
crwdir, monidir, lazydir string

)

for i := 0; i < len(p.Vol); i++ {
glog.Printf("start lazy vol %d\n", i)
crwdir = filepath.Join(RemoteGetVolume(p.Id, i), "nfs")
monidir = filepath.Join(RemoteGetVolume(p.Id, i), "upper")
lazydir = filepath.Join(RemoteGetVolume(p.Id, i), "lazy")
if err = lazycopydir.StartLazyCopy(crwdir, monidir, lazydir); err != nil {
r:=lazycopydir.NewLazyReplicator(crwdir,monidir,lazydir)
if err=r.Prelazy();err!=nil {
glog.Println(err)
return err
}
lazyreplicator=append(lazyreplicator,r)

}
glog.Printf("finish start lazy copy:%v",time.Now())
glog.Printf("finish pre lazy copy:%v",time.Now())
return nil
}

func (p *PreMigrationInTargetMachine) StartLazyCopy() error {
var (
err error
)
for _,v:=range lazyreplicator {
if err=v.Dolazycopy();err!=nil {
glog.Println(err)
return err
}
}
return nil
}
3 changes: 2 additions & 1 deletion supervisor/preMigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package supervisor
import (
"github.com/containerd/containerd/supervisor/migration"
"github.com/sirupsen/logrus"
"time"
)

const preVolume = "/var/lib/migration/mvolume"
Expand Down Expand Up @@ -45,7 +46,7 @@ func (s *Supervisor) PreMigration(t *PreMigrationTask) error {
SrcIp: t.SrcIp,
}

logrus.Println("start preMigration")
logrus.Printf("start preMigration at %v\n",time.Now())
if err = pre.StartPre(); err != nil {
logrus.Printf("start pre in supervisor error:%v\n", err)
return err
Expand Down

0 comments on commit b5aea88

Please sign in to comment.