-
Notifications
You must be signed in to change notification settings - Fork 227
add trySetBusy #7815
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
add trySetBusy #7815
Changes from all commits
93df6ac
5aa64ab
6bfb296
b656f3b
bcca331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,6 +255,7 @@ type StateStatisticsHandler interface { | |
| // able to tell if the node is idle or processing/committing a block | ||
| type ProcessStatusHandler interface { | ||
| SetBusy(reason string) | ||
| TrySetBusy(reason string) bool | ||
| SetIdle() | ||
| IsIdle() bool | ||
| IsInterfaceNil() bool | ||
|
Comment on lines
255
to
261
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2637,7 +2637,9 @@ func (bp *baseProcessor) Close() error { | |
| // ProcessScheduledBlock processes a scheduled block | ||
| func (bp *baseProcessor) ProcessScheduledBlock(headerHandler data.HeaderHandler, bodyHandler data.BodyHandler, haveTime func() time.Duration) error { | ||
| var err error | ||
| bp.processStatusHandler.SetBusy("baseProcessor.ProcessScheduledBlock") | ||
| if !bp.processStatusHandler.TrySetBusy("baseProcessor.ProcessScheduledBlock") { | ||
| return process.ErrBlockProcessorBusy | ||
| } | ||
| defer func() { | ||
|
Comment on lines
2638
to
2643
|
||
| if err != nil { | ||
| bp.RevertCurrentBlock() | ||
|
|
@@ -3562,14 +3564,16 @@ func (bp *baseProcessor) setCurrentBlockInfo( | |
| func (bp *baseProcessor) getLastExecutedRootHash( | ||
| header data.HeaderHandler, | ||
| ) []byte { | ||
| rootHash := bp.getRootHash() | ||
| var rootHash []byte | ||
| if !header.IsHeaderV3() { | ||
| rootHash = bp.getRootHash() | ||
| return rootHash | ||
| } | ||
|
|
||
| lastExecutionResult, err := common.GetLastBaseExecutionResultHandler(header) | ||
| if err != nil { | ||
| log.Warn("failed to get last execution result for header", "err", err) | ||
| _, _, rootHash = bp.blockChain.GetLastExecutedBlockInfo() | ||
| return rootHash | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,7 +159,9 @@ func (mp *metaProcessor) ProcessBlock( | |
| return process.ErrNilHaveTimeHandler | ||
| } | ||
|
|
||
| mp.processStatusHandler.SetBusy("metaProcessor.ProcessBlock") | ||
| if !mp.processStatusHandler.TrySetBusy("metaProcessor.ProcessBlock") { | ||
| return process.ErrBlockProcessorBusy | ||
| } | ||
| defer mp.processStatusHandler.SetIdle() | ||
|
Comment on lines
+162
to
165
|
||
|
|
||
| err := mp.checkBlockValidity(headerHandler, bodyHandler) | ||
|
|
@@ -724,7 +726,9 @@ func (mp *metaProcessor) CreateBlock( | |
| return nil, nil, process.ErrWrongTypeAssertion | ||
| } | ||
|
|
||
| mp.processStatusHandler.SetBusy("metaProcessor.CreateBlock") | ||
| if !mp.processStatusHandler.TrySetBusy("metaProcessor.CreateBlock") { | ||
| return nil, nil, process.ErrBlockProcessorBusy | ||
| } | ||
| defer mp.processStatusHandler.SetIdle() | ||
|
|
||
| metaHdr.SoftwareVersion = []byte(mp.headerIntegrityVerifier.GetVersion(metaHdr.Epoch, metaHdr.Round)) | ||
|
|
@@ -1227,7 +1231,9 @@ func (mp *metaProcessor) CommitBlock( | |
| prevBlockHeaderHash := mp.blockChain.GetCurrentBlockHeaderHash() | ||
|
|
||
| if !headerHandler.IsHeaderV3() { | ||
| mp.processStatusHandler.SetBusy("metaProcessor.CommitBlock") | ||
| if !mp.processStatusHandler.TrySetBusy("metaProcessor.CommitBlock") { | ||
raduchis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return process.ErrBlockProcessorBusy | ||
| } | ||
| defer func() { | ||
| if err != nil { | ||
| mp.RevertCurrentBlock() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,7 +308,9 @@ func (mp *metaProcessor) ProcessBlockProposal( | |
| return nil, process.ErrInvalidHeader | ||
| } | ||
|
|
||
| mp.processStatusHandler.SetBusy("metaProcessor.ProcessBlockProposal") | ||
| if !mp.processStatusHandler.TrySetBusy("metaProcessor.ProcessBlockProposal") { | ||
| return nil, process.ErrBlockProcessorBusy | ||
| } | ||
| defer mp.processStatusHandler.SetIdle() | ||
|
|
||
|
Comment on lines
+311
to
315
|
||
| mp.roundNotifier.CheckRound(headerHandler) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,9 @@ func (sp *shardProcessor) ProcessBlock( | |
| return process.ErrNilHaveTimeHandler | ||
| } | ||
|
|
||
| sp.processStatusHandler.SetBusy("shardProcessor.ProcessBlock") | ||
| if !sp.processStatusHandler.TrySetBusy("shardProcessor.ProcessBlock") { | ||
| return process.ErrBlockProcessorBusy | ||
| } | ||
| defer sp.processStatusHandler.SetIdle() | ||
|
Comment on lines
+101
to
104
|
||
|
|
||
| err := sp.checkBlockValidity(headerHandler, bodyHandler) | ||
|
|
@@ -836,7 +838,9 @@ func (sp *shardProcessor) CreateBlock( | |
| return nil, nil, process.ErrWrongTypeAssertion | ||
| } | ||
|
|
||
| sp.processStatusHandler.SetBusy("shardProcessor.CreateBlock") | ||
| if !sp.processStatusHandler.TrySetBusy("shardProcessor.CreateBlock") { | ||
| return nil, nil, process.ErrBlockProcessorBusy | ||
| } | ||
| defer sp.processStatusHandler.SetIdle() | ||
|
|
||
| err := sp.createBlockStarted() | ||
|
|
@@ -942,7 +946,9 @@ func (sp *shardProcessor) CommitBlock( | |
| prevBlockHeaderHash := sp.blockChain.GetCurrentBlockHeaderHash() | ||
|
|
||
| if !headerHandler.IsHeaderV3() { | ||
| sp.processStatusHandler.SetBusy("shardProcessor.CommitBlock") | ||
| if !sp.processStatusHandler.TrySetBusy("shardProcessor.CommitBlock") { | ||
raduchis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return process.ErrBlockProcessorBusy | ||
| } | ||
| defer func() { | ||
| if err != nil { | ||
| sp.RevertCurrentBlock() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,7 +286,9 @@ func (sp *shardProcessor) ProcessBlockProposal( | |
| return nil, process.ErrInvalidHeader | ||
| } | ||
|
|
||
| sp.processStatusHandler.SetBusy("shardProcessor.ProcessBlockProposal") | ||
| if !sp.processStatusHandler.TrySetBusy("shardProcessor.ProcessBlockProposal") { | ||
| return nil, process.ErrBlockProcessorBusy | ||
| } | ||
| defer sp.processStatusHandler.SetIdle() | ||
|
|
||
|
Comment on lines
+289
to
293
|
||
| sp.roundNotifier.CheckRound(headerHandler) | ||
|
|
||
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.
Is the SetBusy still needed? Could it be deleted?
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.
yes can be removed, only used in some tests now. Currently left it in.