Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy doesn't need this lock #437

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cluster/calcium/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type
if err := opts.Validate(); err != nil {
return nil, logger.Err(ctx, err)
}

ch := make(chan *types.CopyMessage)
utils.SentryGo(func() {
defer close(ch)

wg := sync.WaitGroup{}
log.Infof(ctx, "[Copy] Copy %d workloads files", len(opts.Targets))

// workload one by one
for id, paths := range opts.Targets {
wg.Add(1)

utils.SentryGo(func(id string, paths []string) func() {
return func() {
defer wg.Done()
if err := c.withWorkloadLocked(ctx, id, func(ctx context.Context, workload *types.Workload) error {
for _, path := range paths {
resp, name, err := workload.Engine.VirtualizationCopyFrom(ctx, workload.ID, path)
ch <- makeCopyMessage(id, name, path, err, resp)
}
return nil
}); err != nil {

workload, err := c.GetWorkload(ctx, id)
if err != nil {
ch <- makeCopyMessage(id, "", "", logger.Err(ctx, err), nil)
return
}

for _, path := range paths {
resp, name, err := workload.Engine.VirtualizationCopyFrom(ctx, workload.ID, path)
ch <- makeCopyMessage(id, name, path, err, resp)
}
}
}(id, paths))
Expand Down
5 changes: 2 additions & 3 deletions cluster/calcium/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ func TestCopy(t *testing.T) {
store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil)
c.store = store
// failed by GetWorkload
store.On("GetWorkloads", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
store.On("GetWorkload", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
ch, err := c.Copy(ctx, opts)
assert.NoError(t, err)
for r := range ch {
assert.Error(t, r.Error)
}
workload := &types.Workload{ID: "cid"}
workloads := []*types.Workload{workload}
engine := &enginemocks.API{}
workload.Engine = engine
store.On("GetWorkloads", mock.Anything, mock.Anything).Return(workloads, nil)
store.On("GetWorkload", mock.Anything, mock.Anything).Return(workload, nil)
// failed by VirtualizationCopyFrom
engine.On("VirtualizationCopyFrom", mock.Anything, mock.Anything, mock.Anything).Return(nil, "", types.ErrNilEngine).Twice()
ch, err = c.Copy(ctx, opts)
Expand Down