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

feat(si-fs): support deno #5491

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
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
256 changes: 218 additions & 38 deletions lib/sdf-server/src/service/v2/fs.rs

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions lib/sdf-server/src/service/v2/fs/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use super::{
pub async fn get_bindings_for_func_and_schema_variant(
ctx: &DalContext,
func_id: FuncId,
schema_variant_id: SchemaVariantId,
schema_variant_id: Option<SchemaVariantId>,
) -> FsResult<Vec<FuncBinding>> {
let func = dal::Func::get_by_id_or_error(ctx, func_id).await?;

Expand Down Expand Up @@ -80,7 +80,13 @@ pub async fn get_bindings_for_func_and_schema_variant(
dal::func::FuncKind::Unknown | dal::func::FuncKind::SchemaVariantDefinition => vec![],
}
.into_iter()
.filter(|binding| binding.get_schema_variant() == Some(schema_variant_id))
.filter(|binding| {
if let Some(schema_variant_id) = schema_variant_id {
binding.get_schema_variant() == Some(schema_variant_id)
} else {
true
}
})
.map(Into::into)
.collect())
}
Expand All @@ -96,10 +102,11 @@ pub async fn get_bindings(
let bindings = if func.is_locked {
if let Some(locked) = lookup_variant_for_schema(ctx, schema_id, false).await? {
let bindings =
get_bindings_for_func_and_schema_variant(ctx, func_id, locked.id()).await?;
get_bindings_for_func_and_schema_variant(ctx, func_id, Some(locked.id())).await?;
if bindings.is_empty() {
if let Some(unlocked) = lookup_variant_for_schema(ctx, schema_id, true).await? {
get_bindings_for_func_and_schema_variant(ctx, func_id, unlocked.id()).await?
get_bindings_for_func_and_schema_variant(ctx, func_id, Some(unlocked.id()))
.await?
} else {
vec![]
}
Expand All @@ -110,7 +117,7 @@ pub async fn get_bindings(
vec![]
}
} else if let Some(unlocked) = lookup_variant_for_schema(ctx, schema_id, true).await? {
get_bindings_for_func_and_schema_variant(ctx, func_id, unlocked.id()).await?
get_bindings_for_func_and_schema_variant(ctx, func_id, Some(unlocked.id())).await?
} else {
vec![]
};
Expand All @@ -128,7 +135,7 @@ pub async fn get_bindings(
))
}

async fn func_binding_to_fs_binding(
pub async fn func_binding_to_fs_binding(
ctx: &DalContext,
func_id: FuncId,
binding: FuncBinding,
Expand Down Expand Up @@ -1033,12 +1040,12 @@ pub async fn get_identity_bindings_for_variant(
let unset_func_id = Func::find_intrinsic(ctx, IntrinsicFunc::Unset).await?;

let identity_bindings =
get_bindings_for_func_and_schema_variant(ctx, identity_func_id, variant_id).await?;
get_bindings_for_func_and_schema_variant(ctx, identity_func_id, Some(variant_id)).await?;
let identity_func_arg = FuncArgument::find_by_name_for_func(ctx, "identity", identity_func_id)
.await?
.ok_or(FsError::ResourceNotFound)?;
let unset_bindings =
get_bindings_for_func_and_schema_variant(ctx, unset_func_id, variant_id).await?;
get_bindings_for_func_and_schema_variant(ctx, unset_func_id, Some(variant_id)).await?;
let mut result = IdentityBindings {
props: BTreeMap::new(),
output_sockets: BTreeMap::new(),
Expand Down Expand Up @@ -1186,7 +1193,7 @@ pub async fn set_func_bindings(
if !current_bindings.is_empty() && request.is_attaching_existing {
let types_size = func_types_size(&ctx, func.id).await?;
return Ok(Json(Some(dal_func_to_fs_func(
func,
&func,
fs_bindings.byte_size(),
types_size,
))));
Expand Down Expand Up @@ -1283,7 +1290,7 @@ pub async fn set_func_bindings(
ctx.commit().await?;

Ok(Json(Some(dal_func_to_fs_func(
func,
&func,
fs_bindings.byte_size(),
types_size,
))))
Expand Down
1 change: 1 addition & 0 deletions lib/si-filesystem/src/async_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Filesystem for AsyncFuseWrapper {
_req: &fuser::Request<'_>,
_config: &mut fuser::KernelConfig,
) -> Result<(), nix::libc::c_int> {
self.tx.send(FilesystemCommand::HydrateChangeSets).unwrap();
Ok(())
}

Expand Down
16 changes: 14 additions & 2 deletions lib/si-filesystem/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use si_frontend_types::{
fs::{
AssetFuncs, Binding, Bindings, CategoryFilter, ChangeSet, CreateChangeSetRequest,
CreateChangeSetResponse, CreateFuncRequest, CreateSchemaRequest, CreateSchemaResponse,
FsApiError, Func, IdentityBindings, ListChangeSetsResponse, Schema, SchemaAttributes,
SetFuncBindingsRequest, SetFuncCodeRequest, VariantQuery,
FsApiError, Func, HydratedChangeSet, IdentityBindings, ListChangeSetsResponse, Schema,
SchemaAttributes, SetFuncBindingsRequest, SetFuncCodeRequest, VariantQuery,
},
FuncKind,
};
Expand Down Expand Up @@ -359,6 +359,18 @@ impl SiFsClient {
)
}

pub async fn hydrate_change_sets(&self) -> SiFsClientResult<Vec<HydratedChangeSet>> {
Ok(self
.client
.get(self.fs_api_url("hydrate"))
.bearer_auth(&self.token)
.send()
.await?
.error_for_status()?
.json()
.await?)
}

/// Fetches including the active change sets
pub async fn list_change_sets(&self) -> SiFsClientResult<ListChangeSetsResponse> {
let url = self.fs_api_url("change-sets");
Expand Down
3 changes: 3 additions & 0 deletions lib/si-filesystem/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{FileHandle, Inode};
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum FilesystemCommand {
HydrateChangeSets,
GetAttr {
ino: Inode,
fh: Option<FileHandle>,
Expand Down Expand Up @@ -262,6 +263,7 @@ impl FilesystemCommand {
#[allow(unused)]
pub fn name(&self) -> &'static str {
match self {
FilesystemCommand::HydrateChangeSets => "hydrate_change_sets",
FilesystemCommand::GetAttr { .. } => "getattr",
FilesystemCommand::ReadDir { .. } => "readdir",
FilesystemCommand::Lookup { .. } => "lookup",
Expand Down Expand Up @@ -303,6 +305,7 @@ impl FilesystemCommand {

pub fn error(self, errno: c_int) {
match self {
FilesystemCommand::HydrateChangeSets => {}
FilesystemCommand::GetAttr { reply, .. } => reply.error(errno),
FilesystemCommand::ReadDir { reply, .. } => reply.error(errno),
FilesystemCommand::Lookup { reply, .. } => reply.error(errno),
Expand Down
34 changes: 32 additions & 2 deletions lib/si-filesystem/src/inode_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub enum InodeEntryData {
change_set_id: ChangeSetId,
func_id: FuncId,
},
FuncTypesDenoConfig,
FuncTypesTsConfig,
InstalledSchemaMarker,
SchemaAttrsJson {
Expand Down Expand Up @@ -183,6 +184,9 @@ pub enum InodeEntryData {
SchemasDir {
change_set_id: ChangeSetId,
},
VsCodeDir,
VsCodeSettingsJson,
WorkspaceDenoJson,
WorkspaceRoot {
workspace_id: WorkspaceId,
},
Expand All @@ -194,14 +198,17 @@ impl InodeEntryData {
self,
InodeEntryData::FuncCode { .. }
| InodeEntryData::FuncTypes { .. }
| InodeEntryData::FuncTypesTsConfig { .. }
| InodeEntryData::FuncTypesDenoConfig
| InodeEntryData::FuncTypesTsConfig
| InodeEntryData::AssetFuncCode { .. }
| InodeEntryData::AssetFuncTypes { .. }
| InodeEntryData::SchemaAttrsJson { .. }
| InodeEntryData::SchemaBindingsJson { .. }
| InodeEntryData::SchemaFuncBindings { .. }
| InodeEntryData::SchemaFuncBindingsPending { .. }
| InodeEntryData::InstalledSchemaMarker
| InodeEntryData::VsCodeSettingsJson
| InodeEntryData::WorkspaceDenoJson
)
}
}
Expand All @@ -213,6 +220,7 @@ pub struct InodeTable {
entries_by_path: Arc<DashMap<PathBuf, InodeEntry>>,
uid: Uid,
gid: Gid,
root_path: PathBuf,
}

pub enum Size {
Expand All @@ -235,6 +243,7 @@ impl InodeTable {
entries_by_path: Arc::new(DashMap::new()),
uid,
gid,
root_path: root_path.clone(),
};

table.upsert(
Expand All @@ -248,6 +257,10 @@ impl InodeTable {
table
}

pub fn root_path(&self) -> &Path {
self.root_path.as_path()
}

pub fn entries_by_path(&self) -> &DashMap<PathBuf, InodeEntry> {
&self.entries_by_path
}
Expand Down Expand Up @@ -312,6 +325,17 @@ impl InodeTable {
.and_then(|entry| entry.pending_buf())
}

pub fn filter_entries<L>(&self, lambda: L) -> Vec<(PathBuf, InodeEntry)>
where
L: Fn(&Path, &InodeEntry) -> bool,
{
self.entries_by_path
.iter()
.filter(|ref_multi| lambda(ref_multi.key().as_path(), ref_multi.value()))
.map(|ref_multi| (ref_multi.key().to_owned(), ref_multi.value().to_owned()))
.collect()
}

pub fn modify_ino<L>(&self, ino: Inode, lambda: L)
where
L: FnOnce(&mut InodeEntry),
Expand Down Expand Up @@ -372,7 +396,13 @@ impl InodeTable {
Size::Directory => 512,
Size::UseExisting(fallback) => self
.entry_for_ino(ino)
.map(|entry| entry.attrs.size)
.map(|entry| {
if entry.attrs.size > 0 {
entry.attrs.size
} else {
fallback
}
})
.unwrap_or(fallback),
Size::Force(forced_size) => forced_size,
};
Expand Down
Loading