-
Notifications
You must be signed in to change notification settings - Fork 42
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
Overhaul wal for create workload #534
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6833570
wal for createworkload will clean resources
jschwinger233 a4096f9
wal for resource consistancy during creating
jschwinger233 607336a
wal for processing
jschwinger233 1f31358
handle created WAL by distinguishing status
jschwinger233 fc584f7
revise unittest set
jschwinger233 cd21b45
engine VirtualizationRemove return ErrWorkloadNotExists
jschwinger233 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,14 +55,33 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio | |
defer func() { | ||
cctx, cancel := context.WithTimeout(utils.InheritTracingInfo(ctx, context.TODO()), c.config.GlobalTimeout) | ||
for nodename := range deployMap { | ||
if e := c.store.DeleteProcessing(cctx, opts.GetProcessing(nodename)); e != nil { | ||
processing := opts.GetProcessing(nodename) | ||
if e := c.store.DeleteProcessing(cctx, processing); e != nil { | ||
logger.Errorf(ctx, "[Calcium.doCreateWorkloads] delete processing failed for %s: %+v", nodename, e) | ||
} | ||
} | ||
close(ch) | ||
cancel() | ||
}() | ||
|
||
var resourceCommit wal.Commit | ||
defer func() { | ||
if resourceCommit != nil { | ||
if err := resourceCommit(); err != nil { | ||
logger.Errorf(ctx, "commit wal failed: %s, %+v", eventWorkloadResourceAllocated, err) | ||
} | ||
} | ||
}() | ||
|
||
var processingCommits map[string]wal.Commit | ||
defer func() { | ||
for nodename := range processingCommits { | ||
if err := processingCommits[nodename](); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make sure the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加了一个判断 |
||
logger.Errorf(ctx, "commit wal failed: %s, %s, %+v", eventProcessingCreated, nodename, err) | ||
} | ||
} | ||
}() | ||
|
||
_ = utils.Txn( | ||
ctx, | ||
|
||
|
@@ -81,15 +100,23 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio | |
|
||
// commit changes | ||
nodes := []*types.Node{} | ||
processingCommits = make(map[string]wal.Commit) | ||
for nodename, deploy := range deployMap { | ||
for _, plan := range plans { | ||
plan.ApplyChangesOnNode(nodeMap[nodename], utils.Range(deploy)...) | ||
} | ||
nodes = append(nodes, nodeMap[nodename]) | ||
if err = c.store.CreateProcessing(ctx, opts.GetProcessing(nodename), deploy); err != nil { | ||
processing := opts.GetProcessing(nodename) | ||
if processingCommits[nodename], err = c.wal.Log(eventProcessingCreated, processing); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
if err = c.store.CreateProcessing(ctx, processing, deploy); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
} | ||
if resourceCommit, err = c.wal.Log(eventWorkloadResourceAllocated, nodes); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
return errors.WithStack(c.store.UpdateNodes(ctx, nodes...)) | ||
}) | ||
}, | ||
|
@@ -246,6 +273,7 @@ func (c *Calcium) doDeployOneWorkload( | |
config *enginetypes.VirtualizationCreateOptions, | ||
decrProcessing bool, | ||
) (err error) { | ||
logger := log.WithField("Calcium", "doDeployWorkload").WithField("nodename", node.Name).WithField("opts", opts).WithField("msg", msg) | ||
workload := &types.Workload{ | ||
ResourceMeta: types.ResourceMeta{ | ||
CPU: msg.CPU, | ||
|
@@ -276,7 +304,7 @@ func (c *Calcium) doDeployOneWorkload( | |
defer func() { | ||
if commit != nil { | ||
if err := commit(); err != nil { | ||
log.Errorf(ctx, "[doDeployOneWorkload] Commit WAL %s failed: %v", eventCreateWorkload, err) | ||
logger.Errorf(ctx, "Commit WAL %s failed: %+v", eventWorkloadCreated, err) | ||
} | ||
} | ||
}() | ||
|
@@ -292,10 +320,11 @@ func (c *Calcium) doDeployOneWorkload( | |
// We couldn't WAL the workload ID above VirtualizationCreate temporarily, | ||
// so there's a time gap window, once the core process crashes between | ||
// VirtualizationCreate and logCreateWorkload then the worload is leaky. | ||
if commit, err = c.wal.logCreateWorkload(workload.ID, node.Name); err != nil { | ||
return err | ||
} | ||
return nil | ||
commit, err = c.wal.Log(eventWorkloadCreated, &types.Workload{ | ||
ID: workload.ID, | ||
Nodename: workload.Nodename, | ||
}) | ||
return errors.WithStack(err) | ||
}, | ||
|
||
func(ctx context.Context) (err error) { | ||
|
@@ -375,13 +404,13 @@ func (c *Calcium) doDeployOneWorkload( | |
|
||
// remove workload | ||
func(ctx context.Context, _ bool) error { | ||
log.Errorf(ctx, "[doDeployOneWorkload] failed to deploy workload %s, rollback", workload.ID) | ||
logger.Errorf(ctx, "[doDeployOneWorkload] failed to deploy workload %s, rollback", workload.ID) | ||
if workload.ID == "" { | ||
return nil | ||
} | ||
|
||
if err := c.store.RemoveWorkload(ctx, workload); err != nil { | ||
log.Errorf(ctx, "[doDeployOneWorkload] failed to remove workload %s") | ||
logger.Errorf(ctx, "[doDeployOneWorkload] failed to remove workload %s", workload.ID) | ||
} | ||
|
||
return workload.Remove(ctx, true) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err 统一