aboutsummaryrefslogtreecommitdiff
path: root/src/model/object_table.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-16 13:17:09 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:46:13 +0100
commit4d30e62db456097563c574b9dfd22b138d700087 (patch)
tree00c6790eb7dad952c8e4796731a4ff6e7c3613b6 /src/model/object_table.rs
parent0bbb6673e7ce703e470a3c2aad620ee5f009bc84 (diff)
downloadgarage-4d30e62db456097563c574b9dfd22b138d700087.tar.gz
garage-4d30e62db456097563c574b9dfd22b138d700087.zip
New buckets for 0.6.0: migration code and build files
Diffstat (limited to 'src/model/object_table.rs')
-rw-r--r--src/model/object_table.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/model/object_table.rs b/src/model/object_table.rs
index 285cb5a7..45f0daf4 100644
--- a/src/model/object_table.rs
+++ b/src/model/object_table.rs
@@ -11,6 +11,8 @@ use garage_table::*;
use crate::version_table::*;
+use garage_model_050::object_table as old;
+
/// An object
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct Object {
@@ -255,4 +257,73 @@ impl TableSchema for ObjectTable {
let deleted = !entry.versions.iter().any(|v| v.is_data());
filter.apply(deleted)
}
+
+ fn try_migrate(bytes: &[u8]) -> Option<Self::E> {
+ let old_v = match rmp_serde::decode::from_read_ref::<_, old::Object>(bytes) {
+ Ok(x) => x,
+ Err(_) => return None,
+ };
+ Some(migrate_object(old_v))
+ }
+}
+
+// vvvvvvvv migration code, stupid stuff vvvvvvvvvvvv
+// (we just want to change bucket into bucket_id by hashing it)
+
+fn migrate_object(o: old::Object) -> Object {
+ let versions = o
+ .versions()
+ .iter()
+ .cloned()
+ .map(migrate_object_version)
+ .collect();
+ Object {
+ bucket_id: blake2sum(o.bucket.as_bytes()),
+ key: o.key,
+ versions,
+ }
+}
+
+fn migrate_object_version(v: old::ObjectVersion) -> ObjectVersion {
+ ObjectVersion {
+ uuid: Uuid::try_from(v.uuid.as_slice()).unwrap(),
+ timestamp: v.timestamp,
+ state: match v.state {
+ old::ObjectVersionState::Uploading(h) => {
+ ObjectVersionState::Uploading(migrate_object_version_headers(h))
+ }
+ old::ObjectVersionState::Complete(d) => {
+ ObjectVersionState::Complete(migrate_object_version_data(d))
+ }
+ old::ObjectVersionState::Aborted => ObjectVersionState::Aborted,
+ },
+ }
+}
+
+fn migrate_object_version_headers(h: old::ObjectVersionHeaders) -> ObjectVersionHeaders {
+ ObjectVersionHeaders {
+ content_type: h.content_type,
+ other: h.other,
+ }
+}
+
+fn migrate_object_version_data(d: old::ObjectVersionData) -> ObjectVersionData {
+ match d {
+ old::ObjectVersionData::DeleteMarker => ObjectVersionData::DeleteMarker,
+ old::ObjectVersionData::Inline(m, b) => {
+ ObjectVersionData::Inline(migrate_object_version_meta(m), b)
+ }
+ old::ObjectVersionData::FirstBlock(m, h) => ObjectVersionData::FirstBlock(
+ migrate_object_version_meta(m),
+ Hash::try_from(h.as_slice()).unwrap(),
+ ),
+ }
+}
+
+fn migrate_object_version_meta(m: old::ObjectVersionMeta) -> ObjectVersionMeta {
+ ObjectVersionMeta {
+ headers: migrate_object_version_headers(m.headers),
+ size: m.size,
+ etag: m.etag,
+ }
}