Skip to content

Commit 887abdb

Browse files
authored
Merge branch 'main' into cassandra-key-value-storage-impl
2 parents c8e905b + c4ec00d commit 887abdb

File tree

115 files changed

+8363
-768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+8363
-768
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ tracing-subscriber = { version = "0.3.18", features = [
191191
] }
192192
tracing-test = "0.2.5"
193193
url = "2.5.0"
194-
uuid = { version = "1.7.0", features = ["serde", "v4"] }
194+
uuid = { version = "1.7.0", features = ["serde", "v4", "v5"] }
195195
warp = "0.3.6"
196196
wasm-wave = "=0.6.0"
197197
wasmtime = { version = "=21.0.1", features = ["component-model"] }

golem-api-grpc/proto/golem/rib/expr.proto

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,20 @@ message ResultExpr {
169169
}
170170

171171
message CallExpr {
172-
InvocationName name = 1;
172+
optional InvocationName name = 1;
173173
repeated Expr params = 2;
174+
optional CallType call_type = 3;
174175
}
175176

177+
message CallType {
178+
oneof name {
179+
golem.rib.DynamicParsedFunctionName parsed = 1;
180+
string variant_constructor = 2;
181+
string enum_constructor = 3;
182+
}
183+
}
184+
185+
/** Legacy call-type that holds fully formed function names and not dynamic functions. This is kept for backward compatibility */
176186
message InvocationName {
177187
oneof name {
178188
golem.rib.ParsedFunctionName parsed = 1;
@@ -217,3 +227,44 @@ message TupleConstructorArmPattern {
217227
message LiteralArmPattern {
218228
Expr expr = 1;
219229
}
230+
231+
message DynamicParsedFunctionName {
232+
golem.rib.ParsedFunctionSite site = 1;
233+
DynamicParsedFunctionReference function = 2;
234+
}
235+
236+
message DynamicParsedFunctionReference {
237+
oneof function_reference {
238+
golem.rib.FunctionFunctionReference function = 1;
239+
golem.rib.RawResourceConstructorFunctionReference raw_resource_constructor = 2;
240+
golem.rib.RawResourceDropFunctionReference raw_resource_drop = 3;
241+
golem.rib.RawResourceMethodFunctionReference raw_resource_method = 4;
242+
golem.rib.RawResourceStaticMethodFunctionReference raw_resource_static_method = 5;
243+
DynamicIndexedResourceConstructorFunctionReference indexed_resource_constructor = 6;
244+
DynamicIndexedResourceMethodFunctionReference indexed_resource_method = 7;
245+
DynamicIndexedResourceStaticMethodFunctionReference indexed_resource_static_method = 8;
246+
DynamicIndexedResourceDropFunctionReference indexed_resource_drop = 9;
247+
}
248+
}
249+
250+
message DynamicIndexedResourceConstructorFunctionReference {
251+
string resource = 1;
252+
repeated golem.rib.Expr resource_params = 2;
253+
}
254+
255+
message DynamicIndexedResourceMethodFunctionReference {
256+
string resource = 1;
257+
repeated golem.rib.Expr resource_params = 2;
258+
string method = 3;
259+
}
260+
261+
message DynamicIndexedResourceStaticMethodFunctionReference {
262+
string resource = 1;
263+
repeated golem.rib.Expr resource_params = 2;
264+
string method = 3;
265+
}
266+
267+
message DynamicIndexedResourceDropFunctionReference {
268+
string resource = 1;
269+
repeated golem.rib.Expr resource_params = 2;
270+
}

golem-api-grpc/proto/golem/rib/function_name.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ message IndexedResourceStaticMethodFunctionReference {
9494
message IndexedResourceDropFunctionReference {
9595
string resource = 1;
9696
repeated string resource_params = 2;
97-
}
97+
}

golem-api-grpc/proto/golem/rib/ir.proto

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import "wasm/ast/type.proto";
66

77
import "wasm/rpc/type_annotated_value.proto";
88

9+
import "golem/rib/function_name.proto";
10+
911
message RibIR {
1012
oneof instruction {
1113
wasm.rpc.TypeAnnotatedValue push_lit = 1;
@@ -39,6 +41,7 @@ message RibIR {
3941
ConcatInstruction concat = 29;
4042
EnumConstructionInstruction enum_construction = 30;
4143
And and = 31;
44+
CreateFunctionNameInstruction create_function_name = 32;
4245
}
4346
}
4447

@@ -83,7 +86,6 @@ message JumpInstruction {
8386
}
8487

8588
message CallInstruction {
86-
string function_name = 1;
8789
uint64 argument_count = 2;
8890
wasm.ast.Type return_type = 3;
8991
}
@@ -98,6 +100,12 @@ message EnumConstructionInstruction {
98100
wasm.ast.Type return_type = 2;
99101
}
100102

103+
message CreateFunctionNameInstruction {
104+
golem.rib.ParsedFunctionSite site = 1;
105+
FunctionReferenceType function_reference_details = 2;
106+
}
107+
108+
101109
message EqualTo {}
102110
message GreaterThan {}
103111
message LessThan {}
@@ -106,3 +114,61 @@ message LessThanOrEqualTo {}
106114
message GetTag {}
107115
message Negate {}
108116
message And {}
117+
118+
message FunctionReferenceType {
119+
oneof type {
120+
Function function = 1;
121+
RawResourceConstructor raw_resource_constructor = 2;
122+
RawResourceDrop raw_resource_drop = 3;
123+
RawResourceMethod raw_resource_method = 4;
124+
RawResourceStaticMethod raw_resource_static_method = 5;
125+
IndexedResourceConstructor indexed_resource_constructor = 6;
126+
IndexedResourceMethod indexed_resource_method = 7;
127+
IndexedResourceStaticMethod indexed_resource_static_method = 8;
128+
IndexedResourceDrop indexed_resource_drop = 9;
129+
}
130+
}
131+
132+
message Function {
133+
string name = 1;
134+
}
135+
136+
message RawResourceConstructor {
137+
string resource_name = 1;
138+
}
139+
140+
message RawResourceDrop {
141+
string resource_name = 1;
142+
}
143+
144+
message RawResourceMethod {
145+
string resource_name = 1;
146+
string method_name = 2;
147+
}
148+
149+
message RawResourceStaticMethod {
150+
string resource_name = 1;
151+
string method_name = 2;
152+
}
153+
154+
message IndexedResourceConstructor {
155+
string resource_name = 1;
156+
uint32 arg_size = 2;
157+
}
158+
159+
message IndexedResourceMethod {
160+
string resource_name = 1;
161+
uint32 arg_size = 2;
162+
string method_name = 3;
163+
}
164+
165+
message IndexedResourceStaticMethod {
166+
string resource_name = 1;
167+
uint32 arg_size = 2;
168+
string method_name = 3;
169+
}
170+
171+
message IndexedResourceDrop {
172+
string resource_name = 1;
173+
uint32 arg_size = 2;
174+
}

golem-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ colored = "2.1.0"
3636
derive_more = { workspace = true }
3737
dirs = "5.0.1"
3838
futures-util = { workspace = true }
39-
golem-examples = "1.0.5"
39+
golem-examples = "1.0.6"
4040
golem-wasm-ast = { workspace = true }
4141
golem-wasm-rpc = { workspace = true }
4242
golem-wasm-rpc-stubgen = { version = "1.0.3", optional = true }

golem-cli/tests/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn text_component_list(
271271
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
272272
| URN | Name | Version | Size | Exports count |
273273
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
274-
| {} | {} | 0 | 71828 | 2 |
274+
| {} | {} | 0 | 71228 | 2 |
275275
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
276276
",
277277
component.component_urn,

golem-common/src/model/mod.rs

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use poem_openapi::{Enum, Object, Union};
4242
use rand::prelude::IteratorRandom;
4343
use serde::{Deserialize, Serialize, Serializer};
4444
use serde_json::Value;
45-
use uuid::Uuid;
45+
use uuid::{uuid, Uuid};
4646

4747
pub mod component_metadata;
4848
pub mod exports;
@@ -788,6 +788,8 @@ pub struct IdempotencyKey {
788788
}
789789

790790
impl IdempotencyKey {
791+
const ROOT_NS: Uuid = uuid!("9C19B15A-C83D-46F7-9BC3-EAD7923733F4");
792+
791793
pub fn new(value: String) -> Self {
792794
Self { value }
793795
}
@@ -801,6 +803,25 @@ impl IdempotencyKey {
801803
pub fn fresh() -> Self {
802804
Self::from_uuid(Uuid::new_v4())
803805
}
806+
807+
/// Generates a deterministic new idempotency key using a base idempotency key and an oplog index.
808+
///
809+
/// The base idempotency key determines the "namespace" of the generated key UUIDv5. If
810+
/// the base idempotency key is already an UUID, it is directly used as the namespace of the v5 algorithm,
811+
/// while the name part is derived from the given oplog index.
812+
///
813+
/// If the base idempotency key is not an UUID (as it can be an arbitrary user-provided string), then first
814+
/// we generate a UUIDv5 in the ROOT_NS namespace and use that as unique namespace for generating
815+
/// the new idempotency key.
816+
pub fn derived(base: &IdempotencyKey, oplog_index: OplogIndex) -> Self {
817+
let namespace = if let Ok(base_uuid) = Uuid::parse_str(&base.value) {
818+
base_uuid
819+
} else {
820+
Uuid::new_v5(&Self::ROOT_NS, base.value.as_bytes())
821+
};
822+
let name = format!("oplog-index-{}", oplog_index);
823+
Self::from_uuid(Uuid::new_v5(&namespace, name.as_bytes()))
824+
}
804825
}
805826

806827
impl From<golem_api_grpc::proto::golem::worker::IdempotencyKey> for IdempotencyKey {
@@ -2342,9 +2363,11 @@ mod tests {
23422363
use std::time::SystemTime;
23432364
use std::vec;
23442365

2366+
use crate::model::oplog::OplogIndex;
23452367
use crate::model::{
2346-
AccountId, ComponentId, FilterComparator, ShardId, StringFilterComparator, TargetWorkerId,
2347-
Timestamp, WorkerFilter, WorkerId, WorkerMetadata, WorkerStatus, WorkerStatusRecord,
2368+
AccountId, ComponentId, FilterComparator, IdempotencyKey, ShardId, StringFilterComparator,
2369+
TargetWorkerId, Timestamp, WorkerFilter, WorkerId, WorkerMetadata, WorkerStatus,
2370+
WorkerStatusRecord,
23482371
};
23492372
use bincode::{Decode, Encode};
23502373
use rand::{thread_rng, Rng};
@@ -2620,4 +2643,49 @@ mod tests {
26202643
}
26212644
}
26222645
}
2646+
2647+
#[test]
2648+
fn derived_idempotency_key() {
2649+
let base1 = IdempotencyKey::fresh();
2650+
let base2 = IdempotencyKey::fresh();
2651+
let base3 = IdempotencyKey {
2652+
value: "base3".to_string(),
2653+
};
2654+
2655+
assert_ne!(base1, base2);
2656+
2657+
let idx1 = OplogIndex::from_u64(2);
2658+
let idx2 = OplogIndex::from_u64(11);
2659+
2660+
let derived11a = IdempotencyKey::derived(&base1, idx1);
2661+
let derived12a = IdempotencyKey::derived(&base1, idx2);
2662+
let derived21a = IdempotencyKey::derived(&base2, idx1);
2663+
let derived22a = IdempotencyKey::derived(&base2, idx2);
2664+
2665+
let derived11b = IdempotencyKey::derived(&base1, idx1);
2666+
let derived12b = IdempotencyKey::derived(&base1, idx2);
2667+
let derived21b = IdempotencyKey::derived(&base2, idx1);
2668+
let derived22b = IdempotencyKey::derived(&base2, idx2);
2669+
2670+
let derived31 = IdempotencyKey::derived(&base3, idx1);
2671+
let derived32 = IdempotencyKey::derived(&base3, idx2);
2672+
2673+
assert_eq!(derived11a, derived11b);
2674+
assert_eq!(derived12a, derived12b);
2675+
assert_eq!(derived21a, derived21b);
2676+
assert_eq!(derived22a, derived22b);
2677+
2678+
assert_ne!(derived11a, derived12a);
2679+
assert_ne!(derived11a, derived21a);
2680+
assert_ne!(derived11a, derived22a);
2681+
assert_ne!(derived12a, derived21a);
2682+
assert_ne!(derived12a, derived22a);
2683+
assert_ne!(derived21a, derived22a);
2684+
2685+
assert_ne!(derived11a, derived31);
2686+
assert_ne!(derived21a, derived31);
2687+
assert_ne!(derived12a, derived32);
2688+
assert_ne!(derived22a, derived32);
2689+
assert_ne!(derived31, derived32);
2690+
}
26232691
}

0 commit comments

Comments
 (0)