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

Add Storage.NondeterministicCommit for faster migrations #3348

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrations/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m *StorageMigration) WithErrorStacktrace(stacktraceEnabled bool) *StorageM
}

func (m *StorageMigration) Commit() error {
return m.storage.Commit(m.interpreter, false)
return m.storage.NondeterministicCommit(m.interpreter, false)
}

func (m *StorageMigration) Migrate(migrator StorageMapKeyMigrator) {
Expand Down
17 changes: 16 additions & 1 deletion runtime/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ func (s *Storage) writeContractUpdate(

// Commit serializes/saves all values in the readCache in storage (through the runtime interface).
func (s *Storage) Commit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
return s.commit(inter, commitContractUpdates, true)
}

// NondeterministicCommit serializes and commits all values in the deltas storage
// in nondeterministic order. This function is used when commit ordering isn't
// required (e.g. migration programs).
func (s *Storage) NondeterministicCommit(inter *interpreter.Interpreter, commitContractUpdates bool) error {
return s.commit(inter, commitContractUpdates, false)
}

func (s *Storage) commit(inter *interpreter.Interpreter, commitContractUpdates bool, deterministic bool) error {

if commitContractUpdates {
s.commitContractUpdates(inter)
Expand All @@ -252,7 +263,11 @@ func (s *Storage) Commit(inter *interpreter.Interpreter, commitContractUpdates b
common.UseMemory(s.memoryGauge, common.NewAtreeEncodedSlabMemoryUsage(deltas))

// TODO: report encoding metric for all encoded slabs
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
if deterministic {
return s.PersistentSlabStorage.FastCommit(runtime.NumCPU())
} else {
return s.PersistentSlabStorage.NondeterministicFastCommit(runtime.NumCPU())
}
}

func (s *Storage) commitNewStorageMaps() error {
Expand Down
Loading