Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/origin-src/benches/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Repo {
author: "user:bench".parse().unwrap(),
}
.encode();
let description = EncodedObject::blob(b"");
let description = EncodedObject::attachment(b"");
self.store.write_all(&[content, tree, description]).unwrap();
self.store.write_all(&[revision]).unwrap();
change
Expand Down
8 changes: 4 additions & 4 deletions apps/origin-src/benches/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use origin_shared::api::{EventsQuery, FetchRecords, LandRequest, List};
use origin_shared::landing::{Landing, Proposal};
use origin_shared::pack::Pack;
use origin_shared::{
Base, BlobId, ChangeId, EncodedObject, EntryKind, EntryName, Kind, NodeKey, Period, Record,
RecordId, Revision, RevisionId, Statement, TargetName, Tree, TreeEntry, Verdict,
AttachmentId, Base, ChangeId, EncodedObject, EntryKind, EntryName, Kind, NodeKey, Period,
Record, RecordId, Revision, RevisionId, Statement, TargetName, Tree, TreeEntry, Verdict,
};
use origin_src::http::Api;
use origin_src::policy::Policy;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Hosted {
},
);
let tree = tree.encode();
let description = EncodedObject::blob(b"");
let description = EncodedObject::attachment(b"");
let mut change = [0; 16];
change[..8].copy_from_slice(&n.to_le_bytes());
let revision = Revision {
Expand All @@ -81,7 +81,7 @@ impl Hosted {
base: Base::Acceptance(tip),
deps: Vec::new(),
snapshot: tree.id().into(),
description: BlobId::from(description.id()),
description: AttachmentId::from(description.id()),
author: "user:bench".parse().unwrap(),
}
.encode();
Expand Down
4 changes: 2 additions & 2 deletions apps/origin-src/benches/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn land(service: &OriginService, snapshot: TreeId) -> Base {
/// A revision of a new change with `snapshot`, on `base`, and its
/// description.
fn revision(base: Base, snapshot: TreeId) -> (EncodedObject, EncodedObject) {
let description = EncodedObject::blob(b"bench");
let description = EncodedObject::attachment(b"bench");
let revision = Revision {
change: ChangeId::random().unwrap(),
predecessors: Vec::new(),
Expand Down Expand Up @@ -250,7 +250,7 @@ static HISTORY_SETUP: LazyLock<History> = LazyLock::new(|| {
let service = OriginService::create(server.path().join("demo"), node.clone(), &policy).unwrap();
let tip = service.store().head(&TargetName::MAIN).unwrap().unwrap();
let state = service.store().get(tip.acceptance).unwrap().body().state;
let description = EncodedObject::blob(b"bench");
let description = EncodedObject::attachment(b"bench");
let mut objects = vec![description.clone()];
let mut changes = Vec::new();
for change in 0..HISTORY {
Expand Down
8 changes: 4 additions & 4 deletions apps/origin-src/src/annotations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<'a, P: Platform> Annotations<'a, P> {
.iter()
.map(|head| head.to_hex() + "\n")
.collect::<String>();
let payload = EncodedObject::blob(list.as_bytes());
let payload = EncodedObject::attachment(list.as_bytes());
let statement = Statement {
subject: RecordId::Revision(heads[0]),
kind: Kind::DIVERGENT,
Expand Down Expand Up @@ -388,7 +388,7 @@ mod tests {
use std::thread;

use origin_shared::{
Base, BlobId, Digest, Inputs, ObjectId, RepoPath, Revision, RevisionId, Verdict,
AttachmentId, Base, Digest, Inputs, ObjectId, RepoPath, Revision, RevisionId, Verdict,
};

use super::*;
Expand Down Expand Up @@ -419,7 +419,7 @@ mod tests {
base: Base::Acceptance(ObjectId::from_bytes([0; 32]).into()),
deps: Vec::new(),
snapshot: build(store, files),
description: BlobId::from(EncodedObject::blob(b"").id()),
description: AttachmentId::from(EncodedObject::attachment(b"").id()),
author: principal("user:alice"),
}
.encode();
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
assert_eq!(about.len(), 1);
assert_eq!(about[0].statement.kind, Kind::DIVERGENT);
let heads = store
.try_blob(about[0].statement.payload.unwrap().into())
.try_attachment(about[0].statement.payload.unwrap())
.unwrap()
.unwrap();
let mut expected = [left, right];
Expand Down
50 changes: 23 additions & 27 deletions apps/origin-src/src/annotations/retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ pub struct Dropped {
impl<P: Platform> Annotations<'_, P> {
/// Deletes the payloads whose retention ended by `now`, counted from
/// when this node stored their statement. A payload stays while any
/// statement still keeps it, or a revision or a tree refers to the same
/// blob, such as an empty file and an empty payload. Statements stay.
/// It waits for the writers [holding objects](crate::store::Store::hold_objects),
/// which landings on `policy` are too, then reads the rules from
/// `retention` and the index again, so a writer never refers to a
/// payload deleted under it, and a policy landed meanwhile applies.
/// statement still keeps it, or a revision's description is the same
/// attachment, such as an empty description and an empty payload.
/// Attachments never share an id with a file, so no snapshot is read.
/// Statements stay. It waits for the writers [holding
/// objects](crate::store::Store::hold_objects), which landings on
/// `policy` are too, then reads the rules from `retention` and the
/// index again, so a writer never refers to a payload deleted under it,
/// and a policy landed meanwhile applies.
/// Without rules, it neither waits nor reads anything: a policy landed
/// meanwhile could only have dropped payloads that this run keeps.
///
Expand All @@ -52,20 +54,13 @@ impl<P: Platform> Annotations<'_, P> {
self.index = Index::open(self.store)?;
let mut expired = HashSet::new();
let mut live: HashSet<ObjectId> = HashSet::new();
let mut roots = Vec::new();
for &record in self.index.arrivals() {
match record {
RecordId::Revision(id) => {
let revision = self.store.get(id)?;
roots.push(revision.snapshot);
live.insert(revision.description.into());
live.insert(self.store.get(id)?.description.into());
}
RecordId::Acceptance(id) => roots.push(self.store.get(id)?.body().state),
RecordId::Statement(id) => {
let statement = self.store.get(id)?;
if let RecordId::Snapshot(tree) = statement.subject {
roots.push(tree);
}
let Some(payload) = statement.payload else {
continue;
};
Expand All @@ -82,13 +77,9 @@ impl<P: Platform> Annotations<'_, P> {
live.insert(payload.into());
}
}
RecordId::Snapshot(_) => {}
RecordId::Acceptance(_) | RecordId::Snapshot(_) => {}
}
}
if expired.is_empty() {
return Ok(Dropped::default());
}
self.store.reach(roots, &mut live)?;
let mut doomed = Vec::new();
for &id in expired.difference(&live) {
if self.store.contains(id)? {
Expand All @@ -108,7 +99,7 @@ mod tests {
use std::time::Duration;

use origin_platform::Native;
use origin_shared::{EncodedObject, Verdict};
use origin_shared::{EncodedObject, Record, Revision, Verdict};

use super::*;
use crate::annotations::tests::{FILES, check, issue, revision, store};
Expand All @@ -119,7 +110,7 @@ mod tests {
let (_dir, store) = store();
let first = revision(&store, 1, &[], &[("empty", "")]);
let with_payload = |kind: &str, payload: &[u8]| {
let payload = EncodedObject::blob(payload);
let payload = EncodedObject::attachment(payload);
let mut statement = check(first, kind, Verdict::Pass, "node:ci", None);
statement.payload = Some(payload.id().into());
let annotations = Annotations::open(&store).unwrap();
Expand All @@ -129,7 +120,7 @@ mod tests {
(id, payload.id())
};
let (log_statement, log) = with_payload("ci.test", b"a long log");
// The same blob as the empty file, which must stay.
// The same attachment as the empty description, which must stay.
let (_, empty) = with_payload("ci.lint", b"");
let (_, review) = with_payload("review", b"looks good");
let (_, shared) = with_payload("ci.bench", b"shared");
Expand Down Expand Up @@ -188,7 +179,7 @@ mod tests {
fn collection_waits_for_writers_holding_objects() {
let (_dir, store) = store();
let first = revision(&store, 1, &[], FILES);
let payload = EncodedObject::blob(b"a log, and a file");
let payload = EncodedObject::attachment(b"a log, and a description");
let mut statement = check(first, "ci.test", Verdict::Pass, "node:ci", None);
statement.payload = Some(payload.id().into());
Annotations::open(&store)
Expand All @@ -199,8 +190,9 @@ mod tests {
.unwrap()
.retention;

// A writer finds the expired payload stored as a file it snapshots,
// so it doesn't write it, then writes the revision referring to it.
// A writer finds the expired payload stored as the description it
// writes, so it doesn't write it, then writes the revision referring
// to it.
let held = store.hold_objects().unwrap();
assert_eq!(store.write_all(std::slice::from_ref(&payload)).unwrap(), 0);
let (done, collected) = std::sync::mpsc::channel();
Expand All @@ -215,7 +207,11 @@ mod tests {
});
thread::sleep(Duration::from_millis(100));
assert!(collected.try_recv().is_err(), "collection waits");
revision(&store, 2, &[], &[("log", "a log, and a file")]);
let reusing = Revision {
description: payload.id().into(),
..store.get(first).unwrap()
};
store.write_all(&[reusing.encode()]).unwrap();
drop(held);
assert_eq!(collected.recv().unwrap(), Dropped::default());
});
Expand All @@ -226,7 +222,7 @@ mod tests {
fn promotions_and_collection_exclude_each_other() {
let (_dir, store) = store();
let first = revision(&store, 1, &[], FILES);
let payload = EncodedObject::blob(b"a log to promote");
let payload = EncodedObject::attachment(b"a log to promote");
let inputs = Some((&["src"][..], false));
let mut result = check(first, "ci.test", Verdict::Pass, "node:ci", inputs);
result.payload = Some(payload.id().into());
Expand Down
4 changes: 2 additions & 2 deletions apps/origin-src/src/conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl Conflicts {
list.push_str(conflicted.path.as_str());
list.push('\0');
}
let payload = EncodedObject::blob(list.as_bytes());
let payload = EncodedObject::attachment(list.as_bytes());
let statement = Statement {
subject,
kind: Kind::CONFLICT,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Conflicts {
return Ok(Self::default());
};
let content = store
.try_blob(payload.into())?
.try_attachment(payload)?
.ok_or(StoreError::NotFound(payload.into()))?;
let conflicted = String::from_utf8_lossy(&content)
.split_terminator('\0')
Expand Down
5 changes: 4 additions & 1 deletion apps/origin-src/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ impl<'a, P: Platform> Events<'a, P> {
author: revision.author,
}),
// Its event comes once a target advances to it.
Object::Acceptance(_) | Object::Blob(_) | Object::Tree(_) => None,
Object::Acceptance(_)
| Object::Blob(_)
| Object::Tree(_)
| Object::Attachment(_) => None,
});
}
Ok(events)
Expand Down
4 changes: 2 additions & 2 deletions apps/origin-src/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl IntoResponse for PackResponse {
}
}

/// Fetches records by id, each with the blob it carries, as a pack.
/// Fetches records by id, each with the attachment it carries, as a pack.
#[utoipa::path(
post,
path = "/api/v1/repos/{repo}/records/fetch",
Expand All @@ -196,7 +196,7 @@ impl IntoResponse for PackResponse {
request_body = FetchRecords,
responses(
(status = 200, description = "The records, in the order asked, each followed by its description or payload if the repository has it, as a pack: each object a 32-byte id, a little-endian u64 length and the object's encoding. At most 64 MiB, but for a record alone", content_type = "application/octet-stream", body = Binary, headers(("origin-more" = bool, description = "Present if the pack stopped short: ask again for the records after the last it holds"))),
(status = 400, description = "An object is a blob or a tree, which only leave by walking a snapshot", body = ApiError),
(status = 400, description = "An object is a blob, a tree or an attachment, which only leave by walking a snapshot or with the record carrying them", body = ApiError),
(status = 404, description = "The repository or a record does not exist", body = ApiError)
)
)]
Expand Down
6 changes: 3 additions & 3 deletions apps/origin-src/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ impl Entry {
pub(crate) fn of(object: &EncodedObject) -> Result<Option<Self>, DecodeError> {
let id = object.id();
Ok(match object.kind()? {
ObjectKind::Blob | ObjectKind::Tree => None,
ObjectKind::Blob | ObjectKind::Tree | ObjectKind::Attachment => None,
ObjectKind::Revision => {
let revision: Revision = object.decode_as()?;
Some(Self::Revision {
Expand Down Expand Up @@ -934,7 +934,7 @@ mod tests {
use std::thread;

use origin_platform::Native;
use origin_shared::{Base, BlobId, Inputs, Kind, Record, Tree, Verdict};
use origin_shared::{AttachmentId, Base, Inputs, Kind, Record, Tree, Verdict};

use super::*;
use crate::oplog::FramePart;
Expand All @@ -958,7 +958,7 @@ mod tests {
base: Base::Acceptance(ObjectId::from_bytes([0; 32]).into()),
deps: Vec::new(),
snapshot: Tree::default().encode().id().into(),
description: BlobId::from(EncodedObject::blob(seed.as_bytes()).id()),
description: AttachmentId::from(EncodedObject::attachment(seed.as_bytes()).id()),
author: "user:alice".parse().unwrap(),
}
.encode()
Expand Down
6 changes: 3 additions & 3 deletions apps/origin-src/src/queue/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use origin_platform::Native;
use origin_shared::landing::{Blocked, Landing, Pending, Proposal};
use origin_shared::policy::Requirement;
use origin_shared::{
AcceptanceBody, Base, BlobId, ChangeId, Digest, EncodedObject, Head, Inputs, Kind, NodeKey,
PrincipalName, Record, RecordId, RepoPath, Revision, RevisionId, Source, Statement,
AcceptanceBody, AttachmentId, Base, ChangeId, Digest, EncodedObject, Head, Inputs, Kind,
NodeKey, PrincipalName, Record, RecordId, RepoPath, Revision, RevisionId, Source, Statement,
StatementId, TargetName, Tree, TreeId, Verdict,
};

Expand Down Expand Up @@ -94,7 +94,7 @@ impl Repo {
base,
deps: Vec::new(),
snapshot: self.files(files),
description: BlobId::from(EncodedObject::blob(b"").id()),
description: AttachmentId::from(EncodedObject::attachment(b"").id()),
author: "user:ada".parse().unwrap(),
}
.encode();
Expand Down
4 changes: 2 additions & 2 deletions apps/origin-src/src/queue/tests/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::thread;

use origin_shared::{BlobId, Statement};
use origin_shared::{AttachmentId, Statement};

use super::*;

Expand Down Expand Up @@ -109,7 +109,7 @@ fn policy_landings_keep_a_valid_policy() {
base: tip,
deps: Vec::new(),
snapshot: repo.files(&[("policy.toml", &requiring)]),
description: BlobId::from(EncodedObject::blob(b"").id()),
description: AttachmentId::from(EncodedObject::attachment(b"").id()),
author: "user:ada".parse().unwrap(),
}
.encode();
Expand Down
4 changes: 2 additions & 2 deletions apps/origin-src/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ calls! {
fn targets() -> Vec<TargetInfo> = targets(), targets();
/// The acceptances of a target, oldest first.
fn log(query: &LogQuery) -> Vec<LogEntry> = log(query), log(query);
/// Records by id, each followed by the blob it carries: those up to the
/// last record of the part, if it stops short.
/// Records by id, each followed by the attachment it carries: those up
/// to the last record of the part, if it stops short.
fn records(request: &FetchRecords) -> Part = fetch_records(request), records(&request.ids);
/// The trees and blobs of a snapshot that the request's snapshots lack,
/// in parts.
Expand Down
Loading