Skip to main content

VersioningManager

Struct VersioningManager 

Source
pub struct VersioningManager { /* private fields */ }
Expand description

per-bucket versioning state + per-(bucket, key) version chain を一元管理する 上位 manager。すべての書き込み操作は RwLock write 経由で atomic、すべての 読み出しは read 経由 (chain は Vec<VersionEntry> の clone を返す)。

Implementations§

Source§

impl VersioningManager

Source

pub fn new() -> Self

空 manager。bucket 毎の state も空 (= 全 bucket Unversioned 扱い)。

Source

pub fn new_version_id() -> String

新 version_id を採番 (UUIDv4 を simple() = 32-char hex で表現)。

AWS S3 の x-amz-version-id は base64-url 風の不透明文字列だが、S4 では 「URL-safe な短い hex」を採用する。32 char で衝突確率は実用上ゼロ (UUIDv4 = 122-bit randomness)、versionId query param で escape 不要、 debug log にそのまま貼れる。

Source

pub fn state(&self, bucket: &str) -> VersioningState

Bucket の versioning state を取得。未設定は Unversioned

Source

pub fn set_state(&self, bucket: &str, state: VersioningState)

put_bucket_versioning handler から呼ぶ。

Source

pub fn record_put( &self, bucket: &str, key: &str, etag: String, size: u64, ) -> PutOutcome

PUT 経路 (テスト / state machine 単独実証用)。state に応じて新 version_id を 採番 (Enabled) / "null" を使う (Suspended / Unversioned)。Suspended は既存 null version を overwrite する (chain 中の null version を 1 件まで restrict)。

service.rs の handler は backend write の前後で new_version_id の 事前採番 + [commit_put_with_version] を使うので本関数を直接は呼ばないが、 state machine 単体テスト + 公開 API として残しておく (snapshot loader 等から programmatic に index を組む経路で便利)。

Source

pub fn commit_put_with_version( &self, bucket: &str, key: &str, entry: VersionEntry, )

事前採番済 VersionEntry を chain に commit する。service.rs の PUT handler は backend write の に [new_version_id] で vid を確保し (rewrite 用)、backend write が成功したら本関数で commit する。これにより response の x-amz-version-id と shadow backend key (<key>.__s4ver__/<vid>) が同じ vid で揃う。

Suspended (vid = "null") を commit する場合は既存 null version を物理 overwrite する (S3 仕様: Suspended bucket の null version は唯一)。Enabled の vid (UUIDv4) を commit する場合は単純に末尾 push。

Source

pub fn record_delete(&self, bucket: &str, key: &str) -> DeleteOutcome

version_id 指定なしの DELETE 経路。

  • Enabled → 新 version_id を採番した delete marker を chain 末尾に push。 DeleteOutcome.version_id = Some(<new_vid>)is_delete_marker = true
  • Suspended → null delete marker を 1 件追加 (既存 null version を replace、 S3 仕様)。
  • Unversioned → chain 全消し (= 単純物理削除)。
Source

pub fn record_delete_specific( &self, bucket: &str, key: &str, version_id: &str, ) -> Option<DeleteOutcome>

version_id 指定 DELETE 経路。当該 entry を chain から物理削除する。 Enabled / Suspended / Unversioned 関係なく動く (specific-version DELETE は state に依存しない S3 仕様)。chain が空になった場合は entry を index から 削除する (cleanup)。

Source

pub fn lookup_version( &self, bucket: &str, key: &str, version_id: &str, ) -> Option<VersionEntry>

version_id 指定 GET 経路。当該 entry の clone を返す。

Source

pub fn lookup_latest(&self, bucket: &str, key: &str) -> Option<VersionEntry>

最新 (= chain 末尾) の version を返す。chain 末尾が delete marker の場合 もそのまま返す — 客側 (handler) が is_delete_marker を見て 404 を 投げるかどうか決める。

Source

pub fn list_versions( &self, bucket: &str, prefix: Option<&str>, key_marker: Option<&str>, version_id_marker: Option<&str>, max_keys: usize, ) -> ListVersionsPage

list_object_versions 経路。bucket 内の全 (key, version) を S3 仕様の 順序 (key asc → 同 key 内は新→旧) に展開する。

prefix で key 先頭一致 filter、key_marker (key より大), version_id_marker (key_marker と組で使う、当該 version より後の entry から) で paginate、 max_keys 件で truncate。

戻り値は (versions, delete_markers, is_truncated, next_key_marker, next_version_id_marker)is_truncated = true の時のみ next_* が Some(...) を返す。

Source

pub fn to_json(&self) -> Result<String, Error>

snapshot を JSON 文字列にして返す。--versioning-state-file を将来追加 する時に SIGUSR1 等で dump するために使える。今 task では in-memory 専用 なので公開 API としてのみ提供。

Source

pub fn from_json(s: &str) -> Result<Self, Error>

snapshot JSON から restore。起動時に --versioning-state-file を読み 込む経路で使える。

Trait Implementations§

Source§

impl Debug for VersioningManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VersioningManager

Source§

fn default() -> VersioningManager

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromExt for T

Source§

fn from_<T>(t: T) -> Self
where Self: From<T>,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoExt for T

Source§

fn into_<T>(self) -> T
where Self: Into<T>,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromExt for T

Source§

fn try_from_<T>(t: T) -> Result<Self, Self::Error>
where Self: TryFrom<T>,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TryIntoExt for T

Source§

fn try_into_<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more