Skip to main content

Spine

Struct Spine 

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

Spine file handle. Clone-like sharing is by Arc inside crate::consciousness_stream; a second process opens its own handle over the same file and coordinates through the seqlock.

Implementations§

Source§

impl Spine

Source

pub fn begin_publish(&self) -> Publish<'_>

Start an exclusive batch. Only use the returned guard while it lives; calling back into this Spine would deadlock its mapping mutex.

Source

pub fn publish_lock_is_advisory(&self) -> bool

Whether this platform supports the publisher lock and its sidecar was opened. A runtime lock failure is reported by PublishGuard::is_advisory. Without exclusion, independent handles must not publish concurrently.

Source

pub fn open(output_dir: impl AsRef<Path>) -> Result<Self>

Open for writing: create the file, lay out or upgrade the superblock, and mark this process as a live writer.

Source

pub fn open_ro(output_dir: impl AsRef<Path>) -> Result<Self>

Open an existing spine for reading: no create, no sizing, no writer mark, and no resize. Readers need no lock to be safe, because Spine::read_snapshot validates against the seqlock instead.

Source

pub fn write_slot(&self, slot: Slot, bytes: &[u8; 16384])

Publish one page in its own window. For related updates, use begin_publish instead. Superblock writes exclude the counter bytes.

Source

pub fn read_stream(&self) -> StreamHeader

Source

pub fn write_stream(&self, h: &StreamHeader)

Source

pub fn tick( &self, cycle: u64, surprise: f32, curiosity: f32, predicted_hash: u64, predicted_confidence: f32, last_query_hash: u64, last_query_ms: u64, hebbian_total_energy: f64, )

Publish the stream and superblock in one exclusive window. Use begin_publish to include layer headers in the same window.

Source

pub fn read_snapshot(&self) -> Option<PublishSnapshot>

The stream and superblock copied under one even counter value. Returns None after the retry/time budget or for an invalid payload.

Source

pub fn read_store_snapshot(&self) -> Option<StoreSnapshot>

All eleven headers and the superblock from one validated copy. This does not imply equal freshness of infrequently updated layers.

Source

pub fn publish_window_open(&self) -> bool

Whether the store’s publish window is open: while a writer is inside one, and — the reason this is worth exposing — while a writer that was killed leaves one open. Spine::recover_stalled_publish clears the second case.

Source

pub fn recover_stalled_publish(&self) -> bool

Close a publish window whose writer is gone.

A SIGKILL between the odd store and the even one leaves the counter odd, and every reader would then spend its whole budget on a window that never closes, forever. This is the repair: take the publisher lock (blocking, which is also what proves no live writer is inside a window) and, if the counter is still the odd value found without the lock, close it.

Returns true only when a window was actually closed. There is no timeout involved, so a writer that is merely slow is never interrupted: tick() opens and closes its window with the publisher lock held, and the lock is what makes that argument work.

Source

pub fn publish_sequence(&self) -> u64

Publish counter right now. 0 on a file too short to carry one.

Source

pub fn publish_in_flight(&self) -> bool

True while some writer is mid-publish. Readers never have to act on it — read_snapshot retries on its own — but the live viewer uses it to explain a stalled tick_seq without claiming a torn read.

Source

pub fn read_hebbian(&self) -> HebbianHeader

Source

pub fn write_hebbian(&self, h: &HebbianHeader)

Source

pub fn read_attention(&self) -> AttentionHeader

Source

pub fn write_attention(&self, h: &AttentionHeader)

Source

pub fn read_emotion(&self) -> EmotionHeader

Source

pub fn write_emotion(&self, h: &EmotionHeader)

Source

pub fn read_resonance(&self) -> ResonanceHeader

Source

pub fn write_resonance(&self, h: &ResonanceHeader)

Source

pub fn read_graph(&self) -> GraphHeader

Source

pub fn write_graph(&self, h: &GraphHeader)

Source

pub fn read_cache(&self) -> CacheHeader

Source

pub fn write_cache(&self, h: &CacheHeader)

Source

pub fn read_archetype(&self) -> ArchetypeHeader

Source

pub fn write_archetype(&self, h: &ArchetypeHeader)

Source

pub fn read_mirror(&self) -> MirrorHeader

Source

pub fn write_mirror(&self, h: &MirrorHeader)

Source

pub fn read_merkle(&self) -> MerkleHeader

Source

pub fn write_merkle(&self, h: &MerkleHeader)

Source

pub fn read_meta(&self) -> MetaHeader

Source

pub fn write_meta(&self, h: &MetaHeader)

Source

pub fn read_superblock(&self) -> Option<Superblock>

The superblock as stored. Prefer Spine::read_snapshot when the value has to agree with a stream header.

Source

pub fn sync(&self) -> Result<()>

Source

pub fn size_bytes(&self) -> usize

Source

pub fn output_dir(&self) -> &Path

Source

pub fn path(&self) -> PathBuf

Source

pub fn resize(&self, new_len: usize) -> Result<()>

Grow the file and remap. Refuses unless this handle is a writer and no peer holds the lock exclusively, because remapping invalidates page 0 — including the seqlock counter — for every other mapping.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Spine

§

impl !UnwindSafe for Spine

§

impl Freeze for Spine

§

impl Send for Spine

§

impl Sync for Spine

§

impl Unpin for Spine

§

impl UnsafeUnpin for Spine

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<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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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 = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
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<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