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

Added process status handler #3975

Merged
merged 8 commits into from
Apr 13, 2022
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • 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.

@sstanculeanu sstanculeanu self-requested a review April 7, 2022 08:15
@@ -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())
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -758,6 +762,9 @@ func (sp *shardProcessor) CreateBlock(
return nil, nil, process.ErrWrongTypeAssertion
}

sp.processStatusHandler.SetToBusy("shardProcessor.ProcessBlock")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sp.processStatusHandler.SetToBusy("shardProcessor.ProcessBlock")
sp.processStatusHandler.SetToBusy("shardProcessor.CreateBlock")

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

sstanculeanu
sstanculeanu previously approved these changes Apr 8, 2022
@ssd04 ssd04 self-requested a review April 11, 2022 05:59
ssd04
ssd04 previously approved these changes Apr 11, 2022
Copy link
Contributor

@ssd04 ssd04 left a 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 👍

// 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)
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answered above

Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System test passed.

@gabi-vuls gabi-vuls merged commit 49244eb into feat/release-2022-April Apr 13, 2022
@gabi-vuls gabi-vuls deleted the start-stop-snapshot branch April 13, 2022 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants