MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / put

Method put

crates/core/src/host/disk_storage.rs:52–69  ·  view source on GitHub ↗
(&self, value: &[u8])

Source from the content-addressed store, hash-verified

50
51 #[tracing::instrument(level = "trace", skip(self, value))]
52 pub async fn put(&self, value: &[u8]) -> io::Result<Hash> {
53 let h = hash_bytes(value);
54 let path = self.object_path(&h);
55 fs::create_dir_all(path.parent().expect("object path must have a parent")).await?;
56
57 // to ensure it doesn't conflict with a concurrent call to put() - suffix with nanosecond timestamp
58 let ts = std::time::UNIX_EPOCH.elapsed().unwrap().as_nanos();
59 let tmp = path.with_extension(format!("tmp{ts}"));
60 {
61 let mut f = fs::File::options().write(true).create_new(true).open(&tmp).await?;
62 f.write_all(value).await?;
63 f.sync_data().await?;
64 }
65
66 fs::rename(tmp, path).await?;
67
68 Ok(h)
69 }
70
71 #[tracing::instrument(level = "trace", skip(self))]
72 pub async fn prune(&self, key: &Hash) -> anyhow::Result<()> {

Callers 4

try_putMethod · 0.45
execute_publish_configsFunction · 0.45
execFunction · 0.45
routerFunction · 0.45

Calls 9

hash_bytesFunction · 0.85
renameFunction · 0.85
object_pathMethod · 0.80
elapsedMethod · 0.80
sync_dataMethod · 0.80
openMethod · 0.65
OkFunction · 0.50
unwrapMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected