Skip to content

Commit

Permalink
Merge pull request #2794 from calebschoepp/merge-kv-impls
Browse files Browse the repository at this point in the history
Merge host component key value implementations into new factor crates
  • Loading branch information
lann authored Sep 3, 2024
2 parents 8c17f33 + 1c1f8b0 commit 855572b
Show file tree
Hide file tree
Showing 29 changed files with 504 additions and 744 deletions.
72 changes: 16 additions & 56 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ spin-common = { path = "crates/common" }
spin-doctor = { path = "crates/doctor" }
spin-expressions = { path = "crates/expressions" }
spin-http = { path = "crates/http" }
spin-key-value = { path = "crates/key-value" }
spin-key-value-sqlite = { path = "crates/key-value-sqlite" }
spin-loader = { path = "crates/loader" }
spin-locked-app = { path = "crates/locked-app" }
spin-manifest = { path = "crates/manifest" }
Expand Down
19 changes: 0 additions & 19 deletions crates/factor-key-value-azure/Cargo.toml

This file was deleted.

58 changes: 0 additions & 58 deletions crates/factor-key-value-azure/src/lib.rs

This file was deleted.

15 changes: 0 additions & 15 deletions crates/factor-key-value-redis/Cargo.toml

This file was deleted.

38 changes: 0 additions & 38 deletions crates/factor-key-value-redis/src/lib.rs

This file was deleted.

15 changes: 0 additions & 15 deletions crates/factor-key-value-spin/Cargo.toml

This file was deleted.

12 changes: 8 additions & 4 deletions crates/factor-key-value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ edition = { workspace = true }

[dependencies]
anyhow = "1.0"
lru = "0.9.0"
serde = { version = "1.0", features = ["rc"] }
spin-core = { path = "../core" }
spin-factors = { path = "../factors" }
# TODO: merge with this crate
spin-key-value = { path = "../key-value" }
spin-locked-app = { path = "../locked-app" }
spin-world = { path = "../world" }
table = { path = "../table" }
tokio = { version = "1", features = ["macros", "sync", "rt"] }
toml = "0.8"
tracing = { workspace = true }

[dev-dependencies]
spin-factor-key-value-redis = { path = "../factor-key-value-redis" }
spin-factor-key-value-spin = { path = "../factor-key-value-spin" }
spin-key-value-redis = { path = "../key-value-redis" }
spin-key-value-spin = { path = "../key-value-spin" }
spin-factors-test = { path = "../factors-test" }
tempfile = "3.12.0"
tokio = { version = "1", features = ["macros", "rt"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use crate::util::EmptyStoreManager;
use anyhow::{Context, Result};
use spin_app::MetadataKey;
use spin_core::{async_trait, wasmtime::component::Resource};
use spin_locked_app::MetadataKey;
use spin_world::v2::key_value;
use std::{collections::HashSet, sync::Arc};
use table::Table;

// TODO(factors): Code left for reference; remove after migration to factors
// mod host_component;
mod util;

pub use util::{
CachingStoreManager, DefaultManagerGetter, DelegatingStoreManager, EmptyStoreManager,
};

pub const KEY_VALUE_STORES_KEY: MetadataKey<Vec<String>> = MetadataKey::new("key_value_stores");

const DEFAULT_STORE_TABLE_CAPACITY: u32 = 256;
Expand Down
14 changes: 8 additions & 6 deletions crates/factor-key-value/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
mod host;
pub mod runtime_config;
mod util;

use std::{
collections::{HashMap, HashSet},
sync::Arc,
};

use anyhow::ensure;
use host::KEY_VALUE_STORES_KEY;
use spin_factors::{
ConfigureAppContext, Factor, FactorInstanceBuilder, InitContext, InstanceBuilders,
PrepareContext, RuntimeFactors,
};
use spin_key_value::{
CachingStoreManager, DefaultManagerGetter, DelegatingStoreManager, KeyValueDispatch,
StoreManager, KEY_VALUE_STORES_KEY,
};
use util::{CachingStoreManager, DefaultManagerGetter};

pub use host::{log_error, Error, KeyValueDispatch, Store, StoreManager};
pub use runtime_config::RuntimeConfig;
pub use util::DelegatingStoreManager;

/// A factor that provides key-value storage.
pub struct KeyValueFactor {
default_label_resolver: Arc<dyn DefaultLabelResolver>,
}

impl KeyValueFactor {
/// Create a new KeyValueFactor.
///
/// Create a new KeyValueFactor.
///
/// The `default_label_resolver` is used to resolve store managers for labels that
/// are not defined in the runtime configuration.
pub fn new(default_label_resolver: impl DefaultLabelResolver + 'static) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-key-value/src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod spin;

use std::{collections::HashMap, sync::Arc};

use spin_key_value::StoreManager;
use crate::StoreManager;

/// Runtime configuration for all key value stores.
#[derive(Default, Clone)]
Expand Down
Loading

0 comments on commit 855572b

Please sign in to comment.