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

support ignoring workload lock in RawEngine operation #636

Merged
merged 2 commits into from
Mar 8, 2024
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
14 changes: 11 additions & 3 deletions cluster/calcium/raw_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ func (c *Calcium) RawEngine(ctx context.Context, opts *types.RawEngineOptions) (
wg.Add(1)
_ = c.pool.Invoke(func() {
defer wg.Done()
err = c.withWorkloadLocked(ctx, ID, func(ctx context.Context, workload *types.Workload) error {
if opts.IgnoreLock {
var workload *types.Workload
if workload, err = c.store.GetWorkload(ctx, ID); err != nil {
return
}
msg, err = workload.RawEngine(ctx, opts)
return err
})
} else {
err = c.withWorkloadLocked(ctx, ID, func(ctx context.Context, workload *types.Workload) error {
msg, err = workload.RawEngine(ctx, opts)
return err
})
}

if err == nil {
logger.Infof(ctx, "Workload %s", ID)
Expand Down
16 changes: 16 additions & 0 deletions cluster/calcium/raw_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ func TestRawEngine(t *testing.T) {
_, err := c.RawEngine(ctx, &types.RawEngineOptions{ID: "id1", Op: "xxxx"})
assert.NoError(t, err)
}

func TestRawEngineIgnoreLock(t *testing.T) {
c := NewTestCluster()
ctx := context.Background()
store := c.store.(*storemocks.Store)
workload := &types.Workload{
ID: "id1",
Privileged: true,
}
engine := &enginemocks.API{}
workload.Engine = engine
store.On("GetWorkload", mock.Anything, mock.Anything).Return(workload, nil)
engine.On("RawEngine", mock.Anything, mock.Anything).Return(&enginetypes.RawEngineResult{}, nil).Once()
_, err := c.RawEngine(ctx, &types.RawEngineOptions{ID: "id1", Op: "xxxx", IgnoreLock: true})
assert.NoError(t, err)
}
Loading
Loading