-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Record Upgrade Instructions for Classical Persistence (#4676)
Also support `Prim.rts_upgrade_instructions()` on classical persistence, to inspect the instructions consumed by the last upgrade (including stabilization plus destabilization) for performance measurements. This functionality is already supported with enhanced orthogonal persistence. ## Mechanism 1. The pre-upgrade records its consumed instructions, in particular for stabilization, in the stable memory metadata. The location depends on the stable memory version. 2. The post-upgrade loads this information, if present, and adds its consumed instructions, in particular for destabilization. 3. `Prim.rts_upgrade_instructions()` returns the sum of those costs. ## Backwards Compatibility The record of upgrade instructions is optional in the stable memory. This is to ensure backwards compatibility to older Motoko programs that do not record this information. When upgrading from such an older Motoko program, `Prim.rts_upgrade_instructions()` returns `Nat64.maximumValue`. ## Notes * `Prim.rts_upgrade_instructions()` currently returns >0 after installation because some upgrade check needs to be performed there too. * This function is to be exposed to the Motoko base library together with the other diagnostic runtime information, since `Prim` is only intended for internal use.
- Loading branch information
1 parent
15a4ac2
commit 79c5b25
Showing
18 changed files
with
212 additions
and
34 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CLASSICAL-PERSISTENCE-ONLY | ||
# SKIP ic-ref-run | ||
install $ID migrate-upgrade-instr-stable-mem/old.wasm "" | ||
upgrade $ID migrate-upgrade-instr-stable-mem/test.mo "" | ||
ingress $ID test "DIDL\x00\x00" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
`old.wasm` has been generated by `moc -o old.wasm test.mo` using classical persistence without `rts_upgrade_instructions()` support (e.g. commit 247aa05). |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Prim "mo:prim"; | ||
|
||
import StableMemory "../stable-mem/StableMemory"; | ||
|
||
|
||
actor { | ||
ignore StableMemory.grow(10); | ||
Prim.debugPrint("Stable memory size: " # debug_show(StableMemory.size())); | ||
|
||
public func test() : async () { | ||
Prim.debugPrint("Upgrade instructions: " # debug_show (Prim.rts_upgrade_instructions())); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CLASSICAL-PERSISTENCE-ONLY | ||
# SKIP ic-ref-run | ||
install $ID migrate-upgrade-instr-stable-region/old.wasm "" | ||
upgrade $ID migrate-upgrade-instr-stable-region/test.mo "" | ||
ingress $ID test "DIDL\x00\x00" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
`old.wasm` has been generated by `moc -o old.wasm test.mo` using classical persistence without `rts_upgrade_instructions()` support (e.g. commit 247aa05). |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Prim "mo:prim"; | ||
import Region "../stable-region/Region"; | ||
|
||
actor { | ||
stable var region = Region.new(); | ||
ignore Region.grow(region, 1); | ||
Prim.debugPrint("Region size: " # debug_show(Region.size(region))); | ||
|
||
public func test() : async () { | ||
Prim.debugPrint("Upgrade instructions: " # debug_show (Prim.rts_upgrade_instructions())); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CLASSICAL-PERSISTENCE-ONLY | ||
# SKIP ic-ref-run | ||
install $ID migrate-upgrade-instr-stable-var/old.wasm "" | ||
upgrade $ID migrate-upgrade-instr-stable-var/test.mo "" | ||
ingress $ID test "DIDL\x00\x00" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
`old.wasm` has been generated by `moc -o old.wasm test.mo` using classical persistence without `rts_upgrade_instructions()` support (e.g. commit 247aa05). |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Prim "mo:prim"; | ||
|
||
actor { | ||
stable let state = { | ||
var number = 0; | ||
var text = "Test"; | ||
}; | ||
state.number += 1; | ||
state.text #= "Test"; | ||
Prim.debugPrint(debug_show(state)); | ||
|
||
public func test() : async () { | ||
Prim.debugPrint("Upgrade instructions: " # debug_show (Prim.rts_upgrade_instructions())); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
debug.print: Stable memory size: 10 | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: Stable memory size: 20 | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: Upgrade instructions: 18_446_744_073_709_551_615 | ||
ingress Completed: Reply: 0x4449444c0000 |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
debug.print: Region size: 1 | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: Region size: 2 | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: Upgrade instructions: 18_446_744_073_709_551_615 | ||
ingress Completed: Reply: 0x4449444c0000 |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
debug.print: {number = 1; text = "TestTest"} | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: {number = 2; text = "TestTestTest"} | ||
ingress Completed: Reply: 0x4449444c0000 | ||
debug.print: Upgrade instructions: 18_446_744_073_709_551_615 | ||
ingress Completed: Reply: 0x4449444c0000 |
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