Skip to content

Commit

Permalink
modern sync: pipe identical changesets on edenapi
Browse files Browse the repository at this point in the history
Summary: So I can actually use it, added retries

Reviewed By: markbt

Differential Revision: D67373643

fbshipit-source-id: b75bec26891523d6689424c77db32993b911b514
  • Loading branch information
lmvasquezg authored and facebook-github-bot committed Dec 19, 2024
1 parent 65ff253 commit 181a071
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
42 changes: 42 additions & 0 deletions eden/scm/lib/edenapi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use edenapi_types::HistoricalVersionsResponse;
use edenapi_types::HistoryEntry;
use edenapi_types::HistoryRequest;
use edenapi_types::HistoryResponseChunk;
use edenapi_types::IdenticalChangesetContent;
use edenapi_types::IndexableId;
use edenapi_types::LandStackRequest;
use edenapi_types::LandStackResponse;
Expand Down Expand Up @@ -104,6 +105,7 @@ use edenapi_types::UploadBonsaiChangesetRequest;
use edenapi_types::UploadHgChangeset;
use edenapi_types::UploadHgChangesetsRequest;
use edenapi_types::UploadHgFilenodeRequest;
use edenapi_types::UploadIdenticalChangesetsRequest;
use edenapi_types::UploadToken;
use edenapi_types::UploadTokenMetadata;
use edenapi_types::UploadTokensResponse;
Expand Down Expand Up @@ -197,6 +199,7 @@ mod paths {
pub const UPLOAD_CHANGESETS: &str = "upload/changesets";
pub const UPLOAD_FILENODES: &str = "upload/filenodes";
pub const UPLOAD_TREES: &str = "upload/trees";
pub const UPLOAD_IDENTICAL_CHANGESET: &str = "upload/changesets/identical";
pub const UPLOAD: &str = "upload/";
}

Expand Down Expand Up @@ -692,6 +695,34 @@ impl Client {
self.fetch::<UploadTokensResponse>(vec![request])
}

// the request isn't batched, batching should be done outside if needed
async fn upload_identical_changesets_attempt(
&self,
changesets: Vec<IdenticalChangesetContent>,
) -> Result<Response<UploadTokensResponse>, SaplingRemoteApiError> {
tracing::info!(
"Requesting identical changesets upload for {} item(s)",
changesets.len(),
);

if changesets.is_empty() {
return Ok(Response::empty());
}

let url = self.build_url(paths::UPLOAD_IDENTICAL_CHANGESET)?;
let req = UploadIdenticalChangesetsRequest { changesets }.to_wire();

// Currently, server sends the "upload_changesets" response once it is fully completed,
// disable min speed transfer check to avoid premature termination of requests.
let request = self
.configure_request(self.inner.client.post(url))?
.min_transfer_speed(None)
.cbor(&req)
.map_err(SaplingRemoteApiError::RequestSerializationFailed)?;

self.fetch::<UploadTokensResponse>(vec![request])
}

async fn commit_revlog_data_attempt(
&self,
hgids: Vec<HgId>,
Expand Down Expand Up @@ -1797,6 +1828,17 @@ impl SaplingRemoteApi for Client {
.await
}

async fn upload_identical_changesets(
&self,
changesets: Vec<IdenticalChangesetContent>,
) -> Result<Response<UploadTokensResponse>, SaplingRemoteApiError> {
self.with_retry(|this| {
this.upload_identical_changesets_attempt(changesets.clone())
.boxed()
})
.await
}

async fn upload_bonsai_changeset(
&self,
changeset: BonsaiChangesetContent,
Expand Down
10 changes: 10 additions & 0 deletions eden/scm/lib/edenapi/trait/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use edenapi_types::HgMutationEntryContent;
use edenapi_types::HistoricalVersionsParams;
use edenapi_types::HistoricalVersionsResponse;
use edenapi_types::HistoryEntry;
use edenapi_types::IdenticalChangesetContent;
use edenapi_types::LandStackResponse;
use edenapi_types::LookupResponse;
use edenapi_types::ReferencesDataResponse;
Expand Down Expand Up @@ -302,6 +303,15 @@ pub trait SaplingRemoteApi: Send + Sync + 'static {
Err(SaplingRemoteApiError::NotSupported)
}

/// Upload list of changesets with bonsai and hg info
async fn upload_identical_changesets(
&self,
changesets: Vec<IdenticalChangesetContent>,
) -> Result<Response<UploadTokensResponse>, SaplingRemoteApiError> {
let _ = changesets;
Err(SaplingRemoteApiError::NotSupported)
}

async fn upload_bonsai_changeset(
&self,
changeset: BonsaiChangesetContent,
Expand Down
1 change: 1 addition & 0 deletions eden/scm/lib/edenapi/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub use crate::commit::FetchSnapshotRequest;
pub use crate::commit::FetchSnapshotResponse;
pub use crate::commit::HgChangesetContent;
pub use crate::commit::HgMutationEntryContent;
pub use crate::commit::IdenticalChangesetContent;
pub use crate::commit::SnapshotRawData;
pub use crate::commit::SnapshotRawFiles;
pub use crate::commit::UploadBonsaiChangesetRequest;
Expand Down

0 comments on commit 181a071

Please sign in to comment.