MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / upload_raw_segment

Function upload_raw_segment

nodedb/src/control/cold_tier.rs:174–204  ·  view source on GitHub ↗

Upload the raw bytes of a local segment file to the object store at `object_path`.

(
    cold: &crate::storage::cold::ColdStorage,
    local_path: &std::path::Path,
    object_path: &str,
)

Source from the content-addressed store, hash-verified

172
173/// Upload the raw bytes of a local segment file to the object store at `object_path`.
174async fn upload_raw_segment(
175 cold: &crate::storage::cold::ColdStorage,
176 local_path: &std::path::Path,
177 object_path: &str,
178) -> crate::Result<()> {
179 let path_buf = local_path.to_path_buf();
180 let data = tokio::task::spawn_blocking(move || std::fs::read(&path_buf))
181 .await
182 .map_err(|e| crate::Error::Internal {
183 detail: format!("spawn_blocking join: {e}"),
184 })?
185 .map_err(|e| crate::Error::Internal {
186 detail: format!("read segment file: {e}"),
187 })?;
188
189 let store = cold.object_store();
190 let opath = object_store::path::Path::from(object_path.to_owned());
191
192 store
193 .put_opts(
194 &opath,
195 object_store::PutPayload::from(data),
196 object_store::PutOptions::default(),
197 )
198 .await
199 .map_err(|e| crate::Error::Internal {
200 detail: format!("object store put: {e}"),
201 })?;
202
203 Ok(())
204}
205
206/// Read a directory on a blocking thread, returning paths of all regular files.
207async fn read_dir_sync(dir: &std::path::Path) -> std::io::Result<Vec<PathBuf>> {

Callers 1

run_tier_cycle_atFunction · 0.85

Calls 2

object_storeMethod · 0.80
readFunction · 0.50

Tested by

no test coverage detected