Skip to content

Commit

Permalink
support ignoring workload lock in RawEngine operation (#636)
Browse files Browse the repository at this point in the history
* support ignoring workload lock in RawEngine operation

* add UT
  • Loading branch information
yuyang0 authored Mar 8, 2024
1 parent 54bdcc9 commit 195b249
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 235 deletions.
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

0 comments on commit 195b249

Please sign in to comment.