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

feat: implement ExperimentalStableMemory.stableVarQuery for estimating stable variable storage requirements during upgrade #365

Merged
merged 3 commits into from
Jun 3, 2022
Merged
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
11 changes: 10 additions & 1 deletion src/ExperimentalStableMemory.mo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// page size reported by Motoko function `size()`.
/// This (and the cap on growth) are to accommodate Motoko's stable variables.
/// Applications that plan to use Motoko stable variables sparingly or not at all can
/// increase `--max-stable-pages` as desired, approaching the IC maximum (currently 8GiB).
/// increase `--max-stable-pages` as desired, approaching the IC maximum (currently 8GiB).
/// All applications should reserve at least one page for stable variable data, even when no stable variables are used.

import Prim "mo:⛔";
Expand All @@ -54,6 +54,15 @@ module {
public let grow : (new_pages : Nat64) -> (oldpages : Nat64) =
Prim.stableMemoryGrow;

/// Returns a query that, when called, returns the number of bytes of (real) IC stable memory that would be
/// occupied by persisting its current stable variables before an upgrade.
/// This function may be used to monitor or limit real stable memory usage.
/// The query computes the estimate by running the first half of an upgrade, including any `preupgrade` system method.
/// Like any other query, its state changes are discarded so no actual upgrade (or other state change) takes place.
/// The query can only be called by the enclosing actor and will trap for other callers.
public let stableVarQuery : () -> (shared query () -> async {size : Nat64}) =
Prim.stableVarQuery;

public let loadNat32 : (offset : Nat64) -> Nat32 =
Prim.stableMemoryLoadNat32;
public let storeNat32 : (offset : Nat64, value: Nat32) -> () =
Expand Down