Skip to content

Commit

Permalink
Merge branch 'main' into cassandra-key-value-storage-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
irach-ramos authored Sep 26, 2024
2 parents c8e905b + c4ec00d commit 887abdb
Show file tree
Hide file tree
Showing 115 changed files with 8,363 additions and 768 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ tracing-subscriber = { version = "0.3.18", features = [
] }
tracing-test = "0.2.5"
url = "2.5.0"
uuid = { version = "1.7.0", features = ["serde", "v4"] }
uuid = { version = "1.7.0", features = ["serde", "v4", "v5"] }
warp = "0.3.6"
wasm-wave = "=0.6.0"
wasmtime = { version = "=21.0.1", features = ["component-model"] }
Expand Down
53 changes: 52 additions & 1 deletion golem-api-grpc/proto/golem/rib/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,20 @@ message ResultExpr {
}

message CallExpr {
InvocationName name = 1;
optional InvocationName name = 1;
repeated Expr params = 2;
optional CallType call_type = 3;
}

message CallType {
oneof name {
golem.rib.DynamicParsedFunctionName parsed = 1;
string variant_constructor = 2;
string enum_constructor = 3;
}
}

/** Legacy call-type that holds fully formed function names and not dynamic functions. This is kept for backward compatibility */
message InvocationName {
oneof name {
golem.rib.ParsedFunctionName parsed = 1;
Expand Down Expand Up @@ -217,3 +227,44 @@ message TupleConstructorArmPattern {
message LiteralArmPattern {
Expr expr = 1;
}

message DynamicParsedFunctionName {
golem.rib.ParsedFunctionSite site = 1;
DynamicParsedFunctionReference function = 2;
}

message DynamicParsedFunctionReference {
oneof function_reference {
golem.rib.FunctionFunctionReference function = 1;
golem.rib.RawResourceConstructorFunctionReference raw_resource_constructor = 2;
golem.rib.RawResourceDropFunctionReference raw_resource_drop = 3;
golem.rib.RawResourceMethodFunctionReference raw_resource_method = 4;
golem.rib.RawResourceStaticMethodFunctionReference raw_resource_static_method = 5;
DynamicIndexedResourceConstructorFunctionReference indexed_resource_constructor = 6;
DynamicIndexedResourceMethodFunctionReference indexed_resource_method = 7;
DynamicIndexedResourceStaticMethodFunctionReference indexed_resource_static_method = 8;
DynamicIndexedResourceDropFunctionReference indexed_resource_drop = 9;
}
}

message DynamicIndexedResourceConstructorFunctionReference {
string resource = 1;
repeated golem.rib.Expr resource_params = 2;
}

message DynamicIndexedResourceMethodFunctionReference {
string resource = 1;
repeated golem.rib.Expr resource_params = 2;
string method = 3;
}

message DynamicIndexedResourceStaticMethodFunctionReference {
string resource = 1;
repeated golem.rib.Expr resource_params = 2;
string method = 3;
}

message DynamicIndexedResourceDropFunctionReference {
string resource = 1;
repeated golem.rib.Expr resource_params = 2;
}
2 changes: 1 addition & 1 deletion golem-api-grpc/proto/golem/rib/function_name.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ message IndexedResourceStaticMethodFunctionReference {
message IndexedResourceDropFunctionReference {
string resource = 1;
repeated string resource_params = 2;
}
}
68 changes: 67 additions & 1 deletion golem-api-grpc/proto/golem/rib/ir.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "wasm/ast/type.proto";

import "wasm/rpc/type_annotated_value.proto";

import "golem/rib/function_name.proto";

message RibIR {
oneof instruction {
wasm.rpc.TypeAnnotatedValue push_lit = 1;
Expand Down Expand Up @@ -39,6 +41,7 @@ message RibIR {
ConcatInstruction concat = 29;
EnumConstructionInstruction enum_construction = 30;
And and = 31;
CreateFunctionNameInstruction create_function_name = 32;
}
}

Expand Down Expand Up @@ -83,7 +86,6 @@ message JumpInstruction {
}

message CallInstruction {
string function_name = 1;
uint64 argument_count = 2;
wasm.ast.Type return_type = 3;
}
Expand All @@ -98,6 +100,12 @@ message EnumConstructionInstruction {
wasm.ast.Type return_type = 2;
}

message CreateFunctionNameInstruction {
golem.rib.ParsedFunctionSite site = 1;
FunctionReferenceType function_reference_details = 2;
}


message EqualTo {}
message GreaterThan {}
message LessThan {}
Expand All @@ -106,3 +114,61 @@ message LessThanOrEqualTo {}
message GetTag {}
message Negate {}
message And {}

message FunctionReferenceType {
oneof type {
Function function = 1;
RawResourceConstructor raw_resource_constructor = 2;
RawResourceDrop raw_resource_drop = 3;
RawResourceMethod raw_resource_method = 4;
RawResourceStaticMethod raw_resource_static_method = 5;
IndexedResourceConstructor indexed_resource_constructor = 6;
IndexedResourceMethod indexed_resource_method = 7;
IndexedResourceStaticMethod indexed_resource_static_method = 8;
IndexedResourceDrop indexed_resource_drop = 9;
}
}

message Function {
string name = 1;
}

message RawResourceConstructor {
string resource_name = 1;
}

message RawResourceDrop {
string resource_name = 1;
}

message RawResourceMethod {
string resource_name = 1;
string method_name = 2;
}

message RawResourceStaticMethod {
string resource_name = 1;
string method_name = 2;
}

message IndexedResourceConstructor {
string resource_name = 1;
uint32 arg_size = 2;
}

message IndexedResourceMethod {
string resource_name = 1;
uint32 arg_size = 2;
string method_name = 3;
}

message IndexedResourceStaticMethod {
string resource_name = 1;
uint32 arg_size = 2;
string method_name = 3;
}

message IndexedResourceDrop {
string resource_name = 1;
uint32 arg_size = 2;
}
2 changes: 1 addition & 1 deletion golem-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ colored = "2.1.0"
derive_more = { workspace = true }
dirs = "5.0.1"
futures-util = { workspace = true }
golem-examples = "1.0.5"
golem-examples = "1.0.6"
golem-wasm-ast = { workspace = true }
golem-wasm-rpc = { workspace = true }
golem-wasm-rpc-stubgen = { version = "1.0.3", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion golem-cli/tests/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn text_component_list(
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
| URN | Name | Version | Size | Exports count |
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
| {} | {} | 0 | 71828 | 2 |
| {} | {} | 0 | 71228 | 2 |
+----------------------------------------------------+-------------------------------+---------+-------+---------------+
",
component.component_urn,
Expand Down
74 changes: 71 additions & 3 deletions golem-common/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use poem_openapi::{Enum, Object, Union};
use rand::prelude::IteratorRandom;
use serde::{Deserialize, Serialize, Serializer};
use serde_json::Value;
use uuid::Uuid;
use uuid::{uuid, Uuid};

pub mod component_metadata;
pub mod exports;
Expand Down Expand Up @@ -788,6 +788,8 @@ pub struct IdempotencyKey {
}

impl IdempotencyKey {
const ROOT_NS: Uuid = uuid!("9C19B15A-C83D-46F7-9BC3-EAD7923733F4");

pub fn new(value: String) -> Self {
Self { value }
}
Expand All @@ -801,6 +803,25 @@ impl IdempotencyKey {
pub fn fresh() -> Self {
Self::from_uuid(Uuid::new_v4())
}

/// Generates a deterministic new idempotency key using a base idempotency key and an oplog index.
///
/// The base idempotency key determines the "namespace" of the generated key UUIDv5. If
/// the base idempotency key is already an UUID, it is directly used as the namespace of the v5 algorithm,
/// while the name part is derived from the given oplog index.
///
/// If the base idempotency key is not an UUID (as it can be an arbitrary user-provided string), then first
/// we generate a UUIDv5 in the ROOT_NS namespace and use that as unique namespace for generating
/// the new idempotency key.
pub fn derived(base: &IdempotencyKey, oplog_index: OplogIndex) -> Self {
let namespace = if let Ok(base_uuid) = Uuid::parse_str(&base.value) {
base_uuid
} else {
Uuid::new_v5(&Self::ROOT_NS, base.value.as_bytes())
};
let name = format!("oplog-index-{}", oplog_index);
Self::from_uuid(Uuid::new_v5(&namespace, name.as_bytes()))
}
}

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

use crate::model::oplog::OplogIndex;
use crate::model::{
AccountId, ComponentId, FilterComparator, ShardId, StringFilterComparator, TargetWorkerId,
Timestamp, WorkerFilter, WorkerId, WorkerMetadata, WorkerStatus, WorkerStatusRecord,
AccountId, ComponentId, FilterComparator, IdempotencyKey, ShardId, StringFilterComparator,
TargetWorkerId, Timestamp, WorkerFilter, WorkerId, WorkerMetadata, WorkerStatus,
WorkerStatusRecord,
};
use bincode::{Decode, Encode};
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -2620,4 +2643,49 @@ mod tests {
}
}
}

#[test]
fn derived_idempotency_key() {
let base1 = IdempotencyKey::fresh();
let base2 = IdempotencyKey::fresh();
let base3 = IdempotencyKey {
value: "base3".to_string(),
};

assert_ne!(base1, base2);

let idx1 = OplogIndex::from_u64(2);
let idx2 = OplogIndex::from_u64(11);

let derived11a = IdempotencyKey::derived(&base1, idx1);
let derived12a = IdempotencyKey::derived(&base1, idx2);
let derived21a = IdempotencyKey::derived(&base2, idx1);
let derived22a = IdempotencyKey::derived(&base2, idx2);

let derived11b = IdempotencyKey::derived(&base1, idx1);
let derived12b = IdempotencyKey::derived(&base1, idx2);
let derived21b = IdempotencyKey::derived(&base2, idx1);
let derived22b = IdempotencyKey::derived(&base2, idx2);

let derived31 = IdempotencyKey::derived(&base3, idx1);
let derived32 = IdempotencyKey::derived(&base3, idx2);

assert_eq!(derived11a, derived11b);
assert_eq!(derived12a, derived12b);
assert_eq!(derived21a, derived21b);
assert_eq!(derived22a, derived22b);

assert_ne!(derived11a, derived12a);
assert_ne!(derived11a, derived21a);
assert_ne!(derived11a, derived22a);
assert_ne!(derived12a, derived21a);
assert_ne!(derived12a, derived22a);
assert_ne!(derived21a, derived22a);

assert_ne!(derived11a, derived31);
assert_ne!(derived21a, derived31);
assert_ne!(derived12a, derived32);
assert_ne!(derived22a, derived32);
assert_ne!(derived31, derived32);
}
}
Loading

0 comments on commit 887abdb

Please sign in to comment.