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

New Golem specific host functions for implementing the Transaction API #11

Merged
merged 4 commits into from
Mar 26, 2024
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
57 changes: 57 additions & 0 deletions wit/deps/golem/golem-host.wit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package golem:[email protected];
/// the durability and transactional guarantees the executor provides.
interface host {
use golem:rpc/[email protected].{uri};
use wasi:clocks/[email protected].{duration};

/// An index into the persistent log storing all performed operations of a worker
type oplog-index = u64;
Expand Down Expand Up @@ -33,6 +34,25 @@ interface host {
low-bits: u64
}

/// Configures how the executor retries failures
record retry-policy {
/// The maximum number of retries before the worker becomes permanently failed
max-attempts: u32,
/// The minimum delay between retries (applied to the first retry)
min-delay: duration,
/// The maximum delay between retries
max-delay: duration,
/// Multiplier applied to the delay on each retry to implement exponential backoff
multiplier: u32
}

/// Configurable persistence level for workers
variant persistence-level {
persist-nothing,
persist-remote-side-effects,
smart
}

/// Create a new promise
golem-create-promise: func() -> promise-id;

Expand All @@ -56,6 +76,43 @@ interface host {
/// Makes the current worker travel back in time and continue execution from the given position in the persistent
/// op log.
set-oplog-index: func(oplog-idx: oplog-index) -> ();

/// Blocks the execution until the oplog has been written to at least the specified number of replicas,
/// or the maximum number of replicas if the requested number is higher.
oplog-commit: func(replicas: u8) -> ();

/// Marks the beginning of an atomic operation.
/// In case of a failure within the region selected by `mark-begin-operation` and `mark-end-operation`
/// the whole region will be reexecuted on retry.
/// The end of the region is when `mark-end-operation` is called with the returned oplog-index.
mark-begin-operation: func() -> oplog-index;

/// Commits this atomic operation. After `mark-end-operation` is called for a given index, further calls
/// with the same parameter will do nothing.
mark-end-operation: func(begin: oplog-index) -> ();

/// Gets the current retry policy associated with the worker
get-retry-policy: func() -> retry-policy;

/// Overrides the current retry policy associated with the worker. Following this call, `get-retry-policy` will return the
/// new retry policy.
set-retry-policy: func(new-retry-policy: retry-policy) -> ();
Copy link
Contributor

@jdegoes jdegoes Mar 26, 2024

Choose a reason for hiding this comment

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

In theory this could be a resource, too, where committing would restore the retry policy to its value at the creation of the resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was thinking about it, but I think it is confusing if you create multiple ones simultaneously, as it is not guaranteed that you drop them in opposite order.


/// Gets the worker's current persistence level.
get-oplog-persistence-level: func() -> persistence-level;

/// Sets the worker's current persistence level. This can increase the performance of execution in cases where durable
/// execution is not required.
set-oplog-persistence-level: func(new-persistence-level: persistence-level) -> ();
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory this could be a resource, too, where committing would restore the persistence level to its value at the creation of the resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking not to for the same reason as for the retry policy


/// Gets the current idempotence mode. See `set-idempotence-mode` for details.
get-idempotence-mode: func() -> bool;

/// Sets the current idempotence mode. The default is true.
/// True means side-effects are treated idempotent and Golem guarantees at-least-once semantics.
/// In case of false the executor provides at-most-once semantics, failing the worker in case it is
/// not known if the side effect was already executed.
set-idempotence-mode: func(idempotent: bool) -> ();
Copy link
Contributor

Choose a reason for hiding this comment

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

In theory this could be a resource, too, where committing would restore the idempotence level to its value at the creation of the resource.

}

world golem-host {
Expand Down
Loading