Skip to content

Commit 632bc85

Browse files
Liubov Dmitrievafacebook-github-bot
authored andcommitted
implement support for eagerepo: part #2 (new store)
Summary: implement support for eagerepo - add a store Reviewed By: quark-zju Differential Revision: D58870596 fbshipit-source-id: 4d2f9d7cdaa3993f17304711188cea1cfb41887f
1 parent 45124d1 commit 632bc85

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

eden/scm/lib/eagerepo/src/api.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,46 @@ impl EagerRepo {
13261326
Ok(())
13271327
}
13281328

1329+
fn opt_augmented_tree_blob_with_digest_for_api(
1330+
&self,
1331+
id: HgId,
1332+
handler: &str,
1333+
) -> edenapi::Result<Option<minibytes::Bytes>> {
1334+
// Emulate the HTTP errors.
1335+
match self.get_augmented_tree_blob(id) {
1336+
Ok(None) => {
1337+
trace!(" not found: {}", id.to_hex());
1338+
// TODO: try to derive it recursively from the sapling manifest
1339+
Ok(None)
1340+
}
1341+
Ok(Some(data)) => {
1342+
trace!(" found: {}, {} bytes", id.to_hex(), data.len());
1343+
Ok(Some(data))
1344+
}
1345+
Err(e) => Err(SaplingRemoteApiError::HttpError {
1346+
status: StatusCode::INTERNAL_SERVER_ERROR,
1347+
message: format!("{:?}", e),
1348+
headers: Default::default(),
1349+
url: self.url(handler),
1350+
}),
1351+
}
1352+
}
1353+
13291354
async fn get_augmented_tree_blob_with_digest_for_api(
13301355
&self,
1331-
_id: HgId,
1332-
_handler: &str,
1356+
id: HgId,
1357+
handler: &str,
13331358
) -> edenapi::Result<minibytes::Bytes> {
1334-
unimplemented!()
1359+
// Emulate the HTTP errors.
1360+
match self.opt_augmented_tree_blob_with_digest_for_api(id, handler)? {
1361+
None => Err(SaplingRemoteApiError::HttpError {
1362+
status: StatusCode::NOT_FOUND,
1363+
message: format!("{} cannot be found", id.to_hex()),
1364+
headers: Default::default(),
1365+
url: self.url(handler),
1366+
}),
1367+
Some(data) => Ok(data),
1368+
}
13351369
}
13361370

13371371
async fn flush_for_api(&self, handler: &str) -> edenapi::Result<()> {

eden/scm/lib/eagerepo/src/eager_repo.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ use crate::Result;
7070
pub struct EagerRepo {
7171
pub(crate) dag: Mutex<Dag>,
7272
pub(crate) store: EagerRepoStore,
73+
// Additional store for the Augmented Trees, since they are addressed by
74+
// the same sha1 hashes, making it impossible to store in the primary store
75+
pub(crate) secondary_tree_store: EagerRepoStore,
7376
metalog: RwLock<MetaLog>,
7477
pub(crate) dir: PathBuf,
7578
pub(crate) mut_store: Mutex<MutationStore>,
@@ -232,12 +235,15 @@ impl EagerRepo {
232235
let store_dir = hg_dir.join("store");
233236
let dag = Dag::open(store_dir.join("segments").join("v1"))?;
234237
let store = EagerRepoStore::open(&store_dir.join("hgcommits").join("v1"))?;
238+
let secondary_tree_store =
239+
EagerRepoStore::open(&store_dir.join("augmentedtrees").join("v1"))?;
235240
let metalog = MetaLog::open(store_dir.join("metalog"), None)?;
236241
let mut_store = MutationStore::open(store_dir.join("mutation"))?;
237242

238243
let repo = Self {
239244
dag: Mutex::new(dag),
240245
store,
246+
secondary_tree_store,
241247
metalog: RwLock::new(metalog),
242248
dir: dir.to_path_buf(),
243249
mut_store: Mutex::new(mut_store),
@@ -328,6 +334,7 @@ impl EagerRepo {
328334
/// Write pending changes to disk.
329335
pub async fn flush(&self) -> Result<()> {
330336
self.store.flush()?;
337+
self.secondary_tree_store.flush()?;
331338
let master_heads = {
332339
let books = self.get_bookmarks_map()?;
333340
let mut heads = Vec::new();
@@ -362,6 +369,17 @@ impl EagerRepo {
362369
self.store.get_sha1_blob(id)
363370
}
364371

372+
/// Insert SHA1 blob to zstore for augmented trees.
373+
/// These blobs are not content addressed
374+
pub fn add_augmented_tree_blob(&self, id: Id20, data: &[u8]) -> Result<()> {
375+
self.secondary_tree_store.add_arbitrary_blob(id, data)
376+
}
377+
378+
/// Read SHA1 blob from zstore for augmented trees.
379+
pub fn get_augmented_tree_blob(&self, id: Id20) -> Result<Option<Bytes>> {
380+
self.secondary_tree_store.get_sha1_blob(id)
381+
}
382+
365383
/// Insert a commit. Return the commit hash.
366384
pub async fn add_commit(&self, parents: &[Id20], raw_text: &[u8]) -> Result<Id20> {
367385
let parents: Vec<Vertex> = parents

0 commit comments

Comments
 (0)