Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
feat(add piece expiry time, in secs since epoch, to API) (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
laser authored Jul 29, 2019
1 parent 558ad8e commit 9388fbc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions sector-builder-ffi/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ unsafe fn create_and_add_piece(
c_piece_key,
piece_bytes.len() as u64,
c_piece_path,
5000000000,
),
)
}
Expand Down
4 changes: 3 additions & 1 deletion sector-builder-ffi/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use slog::*;

use ffi_toolkit::rust_str_to_c_str;
use ffi_toolkit::{c_str_to_rust_str, raw_ptr};
use sector_builder::{PieceMetadata, SealStatus, SectorBuilder};
use sector_builder::{PieceMetadata, SealStatus, SecondsSinceEpoch, SectorBuilder};

use crate::responses::{
self, err_code_and_msg, FCPResponseStatus, FFIPieceMetadata, FFISealStatus,
Expand All @@ -30,6 +30,7 @@ pub unsafe extern "C" fn sector_builder_ffi_add_piece(
piece_key: *const libc::c_char,
piece_bytes_amount: u64,
piece_path: *const libc::c_char,
store_until_utc_secs: u64,
) -> *mut responses::AddPieceResponse {
let piece_key = c_str_to_rust_str(piece_key);
let piece_path = c_str_to_rust_str(piece_path);
Expand All @@ -40,6 +41,7 @@ pub unsafe extern "C" fn sector_builder_ffi_add_piece(
String::from(piece_key),
piece_bytes_amount,
String::from(piece_path),
SecondsSinceEpoch(store_until_utc_secs),
) {
Ok(sector_id) => {
response.status_code = FCPResponseStatus::FCPNoError;
Expand Down
9 changes: 4 additions & 5 deletions sector-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ impl SectorBuilder {
piece_key: String,
piece_bytes_amount: u64,
piece_path: String,
store_until: SecondsSinceEpoch,
) -> Result<SectorId> {
log_unrecov(
self.run_blocking(|tx| {
Request::AddPiece(piece_key, piece_bytes_amount, piece_path, tx)
}),
)
log_unrecov(self.run_blocking(|tx| {
Request::AddPiece(piece_key, piece_bytes_amount, piece_path, store_until, tx)
}))
}

// Returns sealing status for the sector with specified id. If no sealed or
Expand Down
3 changes: 2 additions & 1 deletion sector-builder/src/helpers/add_piece.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use filecoin_proofs::types::UnpaddedBytesAmount;

use crate::builder::*;
use crate::error::*;
use crate::metadata::{self, SealStatus, StagedSectorMetadata};
use crate::metadata::{self, SealStatus, SecondsSinceEpoch, StagedSectorMetadata};
use crate::state::StagedState;
use crate::store::{SectorManager, SectorStore};

Expand All @@ -19,6 +19,7 @@ pub fn add_piece(
piece_key: String,
piece_bytes_amount: u64,
piece_path: String,
_store_until: SecondsSinceEpoch,
) -> Result<SectorId> {
let sector_mgr = sector_store.manager();
let sector_max = sector_store.sector_config().max_unsealed_bytes_per_sector();
Expand Down
3 changes: 3 additions & 0 deletions sector-builder/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum SealStatus {
Sealing,
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct SecondsSinceEpoch(pub u64);

impl PartialEq for SealedSectorMetadata {
fn eq(&self, other: &SealedSectorMetadata) -> bool {
self.sector_id == other.sector_id
Expand Down
17 changes: 13 additions & 4 deletions sector-builder/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::metadata::{SealStatus, SealedSectorMetadata, StagedSectorMetadata};
use crate::sealer::SealerInput;
use crate::state::{SectorBuilderState, StagedState};
use crate::store::SectorStore;
use crate::{PaddedBytesAmount, UnpaddedBytesAmount};
use crate::{PaddedBytesAmount, SecondsSinceEpoch, UnpaddedBytesAmount};

const FATAL_NOLOAD: &str = "could not load snapshot";
const FATAL_NORECV: &str = "could not receive task";
Expand All @@ -34,7 +34,13 @@ pub struct Scheduler {

#[derive(Debug)]
pub enum Request {
AddPiece(String, u64, String, mpsc::SyncSender<Result<SectorId>>),
AddPiece(
String,
u64,
String,
SecondsSinceEpoch,
mpsc::SyncSender<Result<SectorId>>,
),
GetSealedSectors(mpsc::SyncSender<Result<Vec<SealedSectorMetadata>>>),
GetStagedSectors(mpsc::SyncSender<Result<Vec<StagedSectorMetadata>>>),
GetSealStatus(SectorId, mpsc::SyncSender<Result<SealStatus>>),
Expand Down Expand Up @@ -100,8 +106,9 @@ impl Scheduler {

// Dispatch to the appropriate task-handler.
match task {
Request::AddPiece(key, amt, path, tx) => {
tx.send(m.add_piece(key, amt, path)).expects(FATAL_NOSEND);
Request::AddPiece(key, amt, path, store_until, tx) => {
tx.send(m.add_piece(key, amt, path, store_until))
.expects(FATAL_NOSEND);
}
Request::GetSealStatus(sector_id, tx) => {
tx.send(m.get_seal_status(sector_id)).expects(FATAL_NOSEND);
Expand Down Expand Up @@ -234,13 +241,15 @@ impl<T: KeyValueStore, S: SectorStore> SectorMetadataManager<T, S> {
piece_key: String,
piece_bytes_amount: u64,
piece_path: String,
store_until: SecondsSinceEpoch,
) -> Result<u64> {
let destination_sector_id = add_piece(
&self.sector_store,
&mut self.state.staged,
piece_key,
piece_bytes_amount,
piece_path,
store_until,
)?;

self.check_and_schedule(false)?;
Expand Down

0 comments on commit 9388fbc

Please sign in to comment.