Skip to content

Commit 9bd9c7f

Browse files
committed
factor out reverse index
1 parent ffb9e08 commit 9bd9c7f

13 files changed

Lines changed: 220 additions & 407 deletions

File tree

golem-common/src/base_model/mod.rs

Lines changed: 0 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -797,226 +797,6 @@ impl FromStr for ScanCursor {
797797
Err("Invalid cursor, must have 'layer/cursor' format".to_string())
798798
}
799799
}
800-
<<<<<<< HEAD
801-
||||||| parent of f66678cfc (further cleanups)
802-
}
803-
804-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
805-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
806-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
807-
#[serde(rename_all = "camelCase")]
808-
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
809-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
810-
#[cfg_attr(feature = "full", desert(evolution()))]
811-
pub struct QueuedCardEventCard {
812-
pub card_id: CardId,
813-
#[cfg_attr(feature = "full", oai(skip))]
814-
pub card: Option<StoredCard>,
815-
}
816-
817-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
818-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
819-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
820-
#[serde(rename_all = "camelCase")]
821-
#[wit(
822-
name = "public-queued-card-event-card",
823-
owner = "golem:api@1.5.0/oplog"
824-
)]
825-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
826-
#[cfg_attr(feature = "full", desert(evolution()))]
827-
pub struct PublicQueuedCardEventCard {
828-
pub card_id: CardId,
829-
}
830-
831-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
832-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
833-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
834-
#[serde(tag = "type")]
835-
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
836-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
837-
#[cfg_attr(feature = "full", desert(evolution()))]
838-
pub enum QueuedCardEvent {
839-
Install(QueuedCardEventCard),
840-
Revoke(QueuedCardEventCard),
841-
}
842-
843-
impl QueuedCardEvent {
844-
pub fn card_id(&self) -> CardId {
845-
match self {
846-
Self::Install(event) | Self::Revoke(event) => event.card_id,
847-
}
848-
}
849-
850-
pub fn install(card: impl Into<StoredCard>) -> Self {
851-
let card = card.into();
852-
Self::Install(QueuedCardEventCard {
853-
card_id: card.card_id(),
854-
card: Some(card),
855-
})
856-
}
857-
858-
pub fn revoke(card_id: CardId) -> Self {
859-
Self::Revoke(QueuedCardEventCard {
860-
card_id,
861-
card: None,
862-
})
863-
}
864-
}
865-
866-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
867-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
868-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
869-
#[serde(tag = "type")]
870-
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
871-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
872-
#[cfg_attr(feature = "full", desert(evolution()))]
873-
pub enum PublicQueuedCardEvent {
874-
Install(PublicQueuedCardEventCard),
875-
Revoke(PublicQueuedCardEventCard),
876-
}
877-
878-
impl PublicQueuedCardEvent {
879-
pub fn card_id(&self) -> CardId {
880-
match self {
881-
Self::Install(event) | Self::Revoke(event) => event.card_id,
882-
}
883-
}
884-
}
885-
886-
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
887-
fn from(value: QueuedCardEvent) -> Self {
888-
match value {
889-
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
890-
card_id: event.card_id,
891-
}),
892-
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
893-
card_id: event.card_id,
894-
}),
895-
}
896-
}
897-
}
898-
899-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
900-
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
901-
#[serde(rename_all = "camelCase")]
902-
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
903-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
904-
#[cfg_attr(feature = "full", desert(evolution()))]
905-
pub enum CardInstallFailure {
906-
CardRevoked,
907-
NotFound,
908-
RecipientMismatch,
909-
NotPermitted,
910-
=======
911-
}
912-
913-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
914-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
915-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
916-
#[serde(rename_all = "camelCase")]
917-
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
918-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
919-
#[cfg_attr(feature = "full", desert(evolution()))]
920-
pub struct QueuedCardEventCard {
921-
pub card_id: CardId,
922-
#[cfg_attr(feature = "full", oai(skip))]
923-
pub card: Option<StoredCard>,
924-
}
925-
926-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
927-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
928-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
929-
#[serde(rename_all = "camelCase")]
930-
#[wit(
931-
name = "public-queued-card-event-card",
932-
owner = "golem:api@1.5.0/oplog"
933-
)]
934-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
935-
#[cfg_attr(feature = "full", desert(evolution()))]
936-
pub struct PublicQueuedCardEventCard {
937-
pub card_id: CardId,
938-
}
939-
940-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
941-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
942-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
943-
#[serde(tag = "type")]
944-
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
945-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
946-
#[cfg_attr(feature = "full", desert(evolution()))]
947-
pub enum QueuedCardEvent {
948-
Install(QueuedCardEventCard),
949-
Revoke(QueuedCardEventCard),
950-
}
951-
952-
impl QueuedCardEvent {
953-
pub fn card_id(&self) -> CardId {
954-
match self {
955-
Self::Install(event) | Self::Revoke(event) => event.card_id,
956-
}
957-
}
958-
959-
pub fn install(card: impl Into<StoredCard>) -> Self {
960-
let card = card.into();
961-
Self::Install(QueuedCardEventCard {
962-
card_id: card.card_id(),
963-
card: Some(card),
964-
})
965-
}
966-
967-
pub fn revoke(card_id: CardId) -> Self {
968-
Self::Revoke(QueuedCardEventCard {
969-
card_id,
970-
card: None,
971-
})
972-
}
973-
}
974-
975-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
976-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
977-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
978-
#[serde(tag = "type")]
979-
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
980-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
981-
#[cfg_attr(feature = "full", desert(evolution()))]
982-
pub enum PublicQueuedCardEvent {
983-
Install(PublicQueuedCardEventCard),
984-
Revoke(PublicQueuedCardEventCard),
985-
}
986-
987-
impl PublicQueuedCardEvent {
988-
pub fn card_id(&self) -> CardId {
989-
match self {
990-
Self::Install(event) | Self::Revoke(event) => event.card_id,
991-
}
992-
}
993-
}
994-
995-
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
996-
fn from(value: QueuedCardEvent) -> Self {
997-
match value {
998-
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
999-
card_id: event.card_id,
1000-
}),
1001-
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
1002-
card_id: event.card_id,
1003-
}),
1004-
}
1005-
}
1006-
}
1007-
1008-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
1009-
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
1010-
#[serde(rename_all = "camelCase")]
1011-
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
1012-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
1013-
#[cfg_attr(feature = "full", desert(evolution()))]
1014-
pub enum CardInstallFailure {
1015-
CardRevoked,
1016-
NotFound,
1017-
RecipientMismatch,
1018-
NotPermitted,
1019-
>>>>>>> f66678cfc (further cleanups)
1020800
}
1021801

1022802
#[cfg(feature = "full")]

golem-debugging-service/src/debug_context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use golem_worker_executor::services::agent_types::AgentTypesService;
5050
use golem_worker_executor::services::agent_webhooks::AgentWebhooksService;
5151
use golem_worker_executor::services::blob_store::BlobStoreService;
5252
use golem_worker_executor::services::card::CardService;
53+
use golem_worker_executor::services::card_interest::CardInterestIndex;
5354
use golem_worker_executor::services::component::ComponentService;
5455
use golem_worker_executor::services::environment_state::EnvironmentStateService;
5556
use golem_worker_executor::services::file_loader::FileLoader;
@@ -564,6 +565,7 @@ impl WorkerCtx for DebugContext {
564565
rpc: Arc<dyn Rpc>,
565566
worker_proxy: Arc<dyn WorkerProxy>,
566567
card_service: Arc<dyn CardService>,
568+
card_interest_index: Arc<CardInterestIndex>,
567569
component_service: Arc<dyn ComponentService>,
568570
_extra_deps: Self::ExtraDeps,
569571
config: Arc<GolemConfig>,
@@ -607,6 +609,7 @@ impl WorkerCtx for DebugContext {
607609
rpc,
608610
worker_proxy,
609611
card_service,
612+
card_interest_index,
610613
component_service,
611614
account_resource_limits,
612615
config,

golem-worker-executor-test-utils/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ use golem_worker_executor::services::blob_store::{
9393
BlobStoreError, BlobStoreService, DefaultBlobStoreService,
9494
};
9595
use golem_worker_executor::services::card::{CardService, NoopCardService};
96+
use golem_worker_executor::services::card_interest::CardInterestIndex;
9697
use golem_worker_executor::services::component::ComponentService;
9798
use golem_worker_executor::services::direct_invocation_auth::{
9899
DirectInvocationAuthService, NoOpDirectInvocationAuthService,
@@ -1485,6 +1486,7 @@ impl WorkerCtx for TestWorkerCtx {
14851486
rpc: Arc<dyn Rpc>,
14861487
worker_proxy: Arc<dyn WorkerProxy>,
14871488
card_service: Arc<dyn CardService>,
1489+
card_interest_index: Arc<CardInterestIndex>,
14881490
component_service: Arc<dyn ComponentService>,
14891491
extra_deps: Self::ExtraDeps,
14901492
config: Arc<GolemConfig>,
@@ -1538,6 +1540,7 @@ impl WorkerCtx for TestWorkerCtx {
15381540
rpc,
15391541
worker_proxy,
15401542
card_service,
1543+
card_interest_index,
15411544
component_service,
15421545
account_resource_limits,
15431546
config,
@@ -1852,7 +1855,6 @@ impl Bootstrap<TestWorkerCtx> for TestServerBootstrap {
18521855
fn create_active_workers(
18531856
&self,
18541857
golem_config: &GolemConfig,
1855-
card_service: Arc<dyn CardService>,
18561858
shutdown_token: tokio_util::sync::CancellationToken,
18571859
) -> Arc<ActiveWorkers<TestWorkerCtx>> {
18581860
// The in-process test harness shares its process (and RSS) with the test
@@ -1869,14 +1871,12 @@ impl Bootstrap<TestWorkerCtx> for TestServerBootstrap {
18691871
&golem_config.memory,
18701872
&golem_config.filesystem_storage,
18711873
&golem_config.agent_status_flush,
1872-
card_service,
18731874
shutdown_token,
18741875
)),
18751876
None => Arc::new(ActiveWorkers::new(
18761877
&golem_config.memory,
18771878
&golem_config.filesystem_storage,
18781879
&golem_config.agent_status_flush,
1879-
card_service,
18801880
shutdown_token,
18811881
)),
18821882
}

golem-worker-executor/src/durable_host/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::services::agent_types::AgentTypesService;
5252
use crate::services::agent_webhooks::AgentWebhooksService;
5353
use crate::services::blob_store::BlobStoreService;
5454
use crate::services::card::{CardService, CardState};
55+
use crate::services::card_interest::CardInterestIndex;
5556
use crate::services::component::ComponentService;
5657
use crate::services::environment_state::EnvironmentStateService;
5758
use crate::services::file_loader::{FileLoader, FileUseToken};
@@ -388,6 +389,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
388389
rpc: Arc<dyn Rpc>,
389390
worker_proxy: Arc<dyn WorkerProxy>,
390391
card_service: Arc<dyn CardService>,
392+
card_interest_index: Arc<CardInterestIndex>,
391393
component_service: Arc<dyn ComponentService>,
392394
resource_limits: Arc<AtomicResourceEntry>,
393395
config: Arc<GolemConfig>,
@@ -554,6 +556,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
554556
rdbms_service,
555557
quota_service,
556558
card_service,
559+
card_interest_index,
557560
component_service,
558561
agent_types_service,
559562
environment_state_service,
@@ -772,7 +775,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
772775
candidate_wallet_card_ids.push(card_id);
773776
}
774777
self.state
775-
.card_service
778+
.card_interest_index
776779
.set_card_interest(self.owned_agent_id.clone(), &candidate_wallet_card_ids)
777780
.await;
778781

@@ -791,7 +794,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
791794
.copied()
792795
.collect::<Vec<_>>();
793796
self.state
794-
.card_service
797+
.card_interest_index
795798
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
796799
.await;
797800

@@ -821,7 +824,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
821824
.copied()
822825
.collect::<Vec<_>>();
823826
self.state
824-
.card_service
827+
.card_interest_index
825828
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
826829
.await;
827830

@@ -853,7 +856,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
853856
.copied()
854857
.collect::<Vec<_>>();
855858
self.state
856-
.card_service
859+
.card_interest_index
857860
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
858861
.await;
859862

@@ -2674,7 +2677,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
26742677
.copied()
26752678
.collect::<Vec<_>>();
26762679
self.state
2677-
.card_service
2680+
.card_interest_index
26782681
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
26792682
.await;
26802683

@@ -4657,6 +4660,7 @@ struct PrivateDurableWorkerState {
46574660
rdbms_service: Arc<dyn RdbmsService>,
46584661
quota_service: Arc<dyn QuotaService>,
46594662
card_service: Arc<dyn CardService>,
4663+
card_interest_index: Arc<CardInterestIndex>,
46604664
component_service: Arc<dyn ComponentService>,
46614665
agent_types_service: Arc<dyn AgentTypesService>,
46624666
agent_webhooks_service: Arc<AgentWebhooksService>,
@@ -4840,6 +4844,7 @@ impl PrivateDurableWorkerState {
48404844
rdbms_service: Arc<dyn RdbmsService>,
48414845
quota_service: Arc<dyn QuotaService>,
48424846
card_service: Arc<dyn CardService>,
4847+
card_interest_index: Arc<CardInterestIndex>,
48434848
component_service: Arc<dyn ComponentService>,
48444849
agent_types_service: Arc<dyn AgentTypesService>,
48454850
environment_state_service: Arc<dyn EnvironmentStateService>,
@@ -4936,6 +4941,7 @@ impl PrivateDurableWorkerState {
49364941
rdbms_service,
49374942
quota_service,
49384943
card_service,
4944+
card_interest_index,
49394945
component_service,
49404946
agent_types_service,
49414947
environment_state_service,

0 commit comments

Comments
 (0)