Skip to content

Commit

Permalink
fix: unnecessary vault creation (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu committed Apr 17, 2023
1 parent d80f89b commit a9be656
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
10 changes: 3 additions & 7 deletions aquamarine/src/particle_data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ impl ParticleDataStore {
.iter()
.collect()
}

pub fn create_particle_vault(&self, key: &str) -> Result<()> {
self.vault.create(key)?;

Ok(())
}
}

const EXECUTION_TIME_THRESHOLD: Duration = Duration::from_millis(500);
Expand All @@ -83,12 +77,13 @@ impl DataStore for ParticleDataStore {
fn initialize(&mut self) -> Result<()> {
create_dir(&self.particle_data_store).map_err(CreateDataStore)?;

// self.vault.initialize()?;
self.vault.initialize()?;

Ok(())
}

fn store_data(&mut self, data: &[u8], particle_id: &str, current_peer_id: &str) -> Result<()> {
log::debug!(target: "particle_reap", "Storing data for particle {}", particle_id);
let data_path = self.data_file(particle_id, current_peer_id);
std::fs::write(&data_path, data).map_err(|err| StoreData(err, data_path))?;

Expand All @@ -102,6 +97,7 @@ impl DataStore for ParticleDataStore {
}

fn cleanup_data(&mut self, particle_id: &str, current_peer_id: &str) -> Result<()> {
log::debug!(target: "particle_reap", "Cleaning up particle data for particle {}", particle_id);
remove_file(&self.data_file(particle_id, current_peer_id)).map_err(CleanupData)?;
self.vault.cleanup(particle_id)?;

Expand Down
3 changes: 2 additions & 1 deletion aquamarine/src/plumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ impl<RT: AquaRuntime, F: ParticleFunctionStatic> Plumber<RT, F> {
// Remove expired actors
if let Some((vm_id, mut vm)) = self.vm_pool.get_vm() {
let now = now_ms();

self.actors.retain(|(particle_id, peer_id), actor| {
// if actor hasn't yet expired or is still executing, keep it
// TODO: if actor is expired, cancel execution and return VM back to pool
// https://github.com/fluencelabs/fluence/issues/1212
if !actor.is_expired(now) || actor.is_executing() {
return true; // keep actor
}

log::debug!(
target: "particle_reap",
"Reaping particle's actor particle_id={particle_id}, peer_id={peer_id})"
);
// cleanup files and dirs after particle processing (vault & prev_data)
Expand Down
12 changes: 6 additions & 6 deletions crates/server-config/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pub struct RootKeyPairArgs {
)]
path: Option<PathBuf>,
#[arg(
short('f'),
long,
value_parser(["ed25519", "secp256k1", "rsa"]),
id = "ROOT_KEY_FORMAT",
help_heading = "Node keypair",
display_order = 12,
short('f'),
long,
value_parser(["ed25519", "secp256k1", "rsa"]),
id = "ROOT_KEY_FORMAT",
help_heading = "Node keypair",
display_order = 12,
)]
format: Option<String>,

Expand Down
2 changes: 1 addition & 1 deletion particle-builtins/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ where
}

fn call_service(&self, function_args: Args, particle: ParticleParams) -> FunctionOutcome {
self.services.call_service(function_args, particle)
self.services.call_service(function_args, particle, true)
}

fn get_interface(&self, args: Args, params: ParticleParams) -> Result<JValue, JError> {
Expand Down
13 changes: 10 additions & 3 deletions particle-services/src/app_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,12 @@ impl ParticleAppServices {
Ok(())
}

pub fn call_service(&self, function_args: Args, particle: ParticleParams) -> FunctionOutcome {
pub fn call_service(
&self,
function_args: Args,
particle: ParticleParams,
create_vault: bool,
) -> FunctionOutcome {
let call_time_start = Instant::now();
let services = self.services.read();
let aliases = self.aliases.read();
Expand Down Expand Up @@ -447,7 +452,9 @@ impl ParticleAppServices {
let service_type = self.get_service_type(service, &worker_id);

// TODO: move particle vault creation to aquamarine::particle_functions
self.create_vault(&particle.id)?;
if create_vault {
self.create_vault(&particle.id)?;
}
let params = CallParameters {
host_id: worker_id.to_string(),
particle_id: particle.id,
Expand Down Expand Up @@ -553,7 +560,7 @@ impl ParticleAppServices {
signature: vec![],
};

self.call_service(args, particle)
self.call_service(args, particle, false)
}

fn add_alias_inner(
Expand Down

0 comments on commit a9be656

Please sign in to comment.