-
Notifications
You must be signed in to change notification settings - Fork 197
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
Added process status handler #3975
Conversation
iulianpascalau
commented
Apr 6, 2022
- added process status handler in BlockProcessors and trie storage manager. This component should be able to suspend/resume the snapshot/checkpoint process while the block processor is executing blocks, either Create, Process or Commit.
@@ -59,6 +59,8 @@ func TestManagedCoreComponents_Create_ShouldWork(t *testing.T) { | |||
require.NotEqual(t, "", managedCoreComponents.ChainID()) | |||
require.NotNil(t, managedCoreComponents.AddressPubKeyConverter()) | |||
require.NotNil(t, managedCoreComponents.RoundNotifier()) | |||
require.NotNil(t, managedCoreComponents.ArwenChangeLocker()) | |||
require.NotNil(t, managedCoreComponents.ProcessStatusHandler()) |
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.
require.Nil(t, managedCoreComponents.ArwenChangeLocker())
require.Nil(t, managedCoreComponents.ProcessStatusHandler())
as well at L47
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.
done
process/block/shardblock.go
Outdated
@@ -758,6 +762,9 @@ func (sp *shardProcessor) CreateBlock( | |||
return nil, nil, process.ErrWrongTypeAssertion | |||
} | |||
|
|||
sp.processStatusHandler.SetToBusy("shardProcessor.ProcessBlock") |
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.
sp.processStatusHandler.SetToBusy("shardProcessor.ProcessBlock") | |
sp.processStatusHandler.SetToBusy("shardProcessor.CreateBlock") |
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.
done, thanks.
|
||
type processStatusHandler struct { | ||
mutStatus sync.RWMutex | ||
isIdle bool |
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.
as discussed on Slack, perhaps it would be safer to have a counter here, which will be incremented/decremented on SetToBusy/SetToIdle
, even though Create/Process/Commit
operations are "forced" to be serialized
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.
right, will do
Having a second thought, I would leave it as it is for one reason: in case we misused the SetToBusy/SetToIdle calls and we end up calling more SetToBusy, we will end up never creating a snapshot which is very dangerous. Instead, at the first SetToIdle call, we will unlock the snapshot process.
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.
Looks good for me 👍
common/interface.go
Outdated
// ProcessStatusHandler defines the behavior of a component able to hold the current status of the node and | ||
// able to tell if the node is idle or processing/committing a block | ||
type ProcessStatusHandler interface { | ||
SetToBusy(reason string) |
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.
can you rename?
SetBusy
SetIdle
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.
done
@@ -460,7 +460,7 @@ func (sesb *storageEpochStartBootstrap) applyCurrentShardIDOnMiniblocksCopy(meta | |||
|
|||
for i := range originalMiniblocksHeaders { | |||
mb := originalMiniblocksHeaders[i].ShallowClone() | |||
err = mb.SetSenderShardID(sesb.importDbConfig.ImportDBTargetShardID) //it is safe to modify here as mbh is passed by value | |||
err = mb.SetSenderShardID(sesb.importDbConfig.ImportDBTargetShardID) // it is safe to modify here as mbh is passed by value |
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.
maybe remove comment or rephrase?
as mb is a shallow clone.
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.
done, renamed to:
// it is safe to modify here as mb is a shallow clone
@@ -80,7 +80,7 @@ func TestHardForkWithoutTransactionInMultiShardedEnvironment(t *testing.T) { | |||
time.Sleep(time.Second) | |||
|
|||
nrRoundsToPropagateMultiShard := 5 | |||
/////////----- wait for epoch end period | |||
// ///////----- wait for epoch end period |
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.
can you clean the slashes?
below as well.
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.
cleaned
@@ -46,8 +46,8 @@ type node interface { | |||
getValue() []byte | |||
|
|||
commitDirty(level byte, maxTrieLevelInMemory uint, originDb common.DBWriteCacher, targetDb common.DBWriteCacher) error | |||
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler) error | |||
commitSnapshot(originDb common.DBWriteCacher, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler) error | |||
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler, idleProvider IdleNodeProvider) error |
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.
can you check if the idleNodeProvider can be added on the receiver, instead of as parameter, as this does not change.
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.
can be done but the resulting trie implementations will all require this idleNodeProvider:
For example, the decodeNode function will need this parameter, then, all 3 implementations of the trie node interface, the patriciaMerkleTrie, interceptedTrieNode (along with the interceptors - and maybe the trie nodes resolvers), the trie syncers and others.
This will add significant complexity when only the snapshot/checkpoint process needs this control
@@ -59,8 +59,8 @@ type node interface { | |||
} | |||
|
|||
type snapshotNode interface { | |||
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler) error | |||
commitSnapshot(originDb common.DBWriteCacher, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler) error | |||
commitCheckpoint(originDb common.DBWriteCacher, targetDb common.DBWriteCacher, checkpointHashes CheckpointHashesHolder, leavesChan chan core.KeyValueHolder, ctx context.Context, stats common.SnapshotStatisticsHandler, idleProvider IdleNodeProvider) error |
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.
same as for the node interface, maybe idleNodeProvider can be added on the receiver instead,
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.
answered above
30f5f42
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.
System test passed.