HostController

Struct HostController 

Source
pub struct HostController {
    pub data_dir: Arc<ServerDataDir>,
    pub page_pool: PagePool,
    /* private fields */
}
Expand description

A host controller manages the lifecycle of spacetime databases and their associated modules.

This type is, and must remain, cheap to clone. All of its fields should either be Copy, enclosed in an Arc, or have some other fast Clone implementation.

Fields§

§data_dir: Arc<ServerDataDir>

The root directory for database data.

§page_pool: PagePool

The page pool all databases will use by cloning the ref counted pool.

Implementations§

Source§

impl HostController

Source

pub fn new( data_dir: Arc<ServerDataDir>, default_config: Config, program_storage: ProgramStorage, energy_monitor: Arc<impl EnergyMonitor>, durability: Arc<dyn DurabilityProvider>, db_cores: JobCores, ) -> Self

Source

pub fn set_program_storage(&mut self, ps: ProgramStorage)

Replace the ProgramStorage used by this controller.

Source

pub async fn get_or_launch_module_host( &self, database: Database, replica_id: u64, ) -> Result<ModuleHost>

Get a ModuleHost managed by this controller, or launch it from persistent state.

If the host is not running, it is started according to the default db::Config set for this controller. The underlying database is restored from existing data at its canonical filesystem location iff the default config mandates disk storage.

The module will be instantiated from the program bytes stored in an existing database. If the database is empty, the program_bytes_address of the given Database will be used to load the program from the controller’s ProgramStorage. The initialization procedure (schema creation, __init__ reducer) will be invoked on the found module, and the database will be marked as initialized.

See also: Self::get_module_host

Source

pub async fn watch_maybe_launch_module_host( &self, database: Database, replica_id: u64, ) -> Result<Receiver<ModuleHost>>

Like Self::get_or_launch_module_host, use a ModuleHost managed by this controller, or launch it if it is not running.

Instead of a ModuleHost, this returns a watch::Receiver which gets notified each time the module is updated.

See also: Self::watch_module_host

Source

pub async fn check_module_validity( &self, database: Database, program: Program, ) -> Result<Arc<ModuleInfo>>

Construct an in-memory instance of database running program, initialize it, then immediately destroy it.

This is used during an initial, fresh publish operation in order to check the program’s validity as a module, since some validity checks we’d like to do (e.g. typechecking RLS filters) require a fully instantiated database.

This is not necessary during hotswap publishes, as the automigration planner and executor accomplish the same validity checks.

Source

pub async fn using_database<F, T>( &self, database: Database, replica_id: u64, f: F, ) -> Result<T>
where F: FnOnce(&RelationalDB) -> T + Send + 'static, T: Send + 'static,

Run a computation on the RelationalDB of a ModuleHost managed by this controller, launching the host if necessary.

If the computation F panics, the host is removed from this controller, releasing its resources.

Source

pub async fn update_module_host( &self, database: Database, host_type: HostType, replica_id: u64, program_bytes: Box<[u8]>, ) -> Result<UpdateDatabaseResult>

Update the ModuleHost identified by replica_id to the given program.

The host may not be running, in which case it is spawned (see Self::get_or_launch_module_host for details on what this entails).

If the host was running, and the update fails, the previous version of the host keeps running.

Source

pub async fn init_maybe_update_module_host( &self, database: Database, replica_id: u64, expected_hash: Option<Hash>, ) -> Result<Receiver<ModuleHost>>

Start the host replica_id and conditionally update it.

If the host was not initialized before, it is initialized with the program Database::initial_program, which is loaded from the controller’s ProgramStorage.

If it was already initialized and its stored program hash matches Database::initial_program, no further action is taken.

Otherwise, if expected_hash is Some and does not match the stored hash, an error is returned.

Otherwise, the host is updated to Database::initial_program, loading the program data from the controller’s ProgramStorage.

Note that this ascribes different semantics to Database::initial_program than elsewhere, where the Database value is provided by the control database. The method is mainly useful for bootstrapping the control database itself.

Source

pub async fn exit_module_host(&self, replica_id: u64) -> Result<(), Error>

Release all resources of the ModuleHost identified by replica_id, and deregister it from the controller.

Source

pub async fn get_module_host( &self, replica_id: u64, ) -> Result<ModuleHost, NoSuchModule>

Get the ModuleHost identified by replica_id or return an error if it is not registered with the controller.

See Self::get_or_launch_module_host for a variant which launches the host if it is not running.

Source

pub async fn watch_module_host( &self, replica_id: u64, ) -> Result<Receiver<ModuleHost>, NoSuchModule>

Subscribe to updates of the ModuleHost identified by replica_id, or return an error if it is not registered with the controller.

See Self::watch_maybe_launch_module_host for a variant which launches the host if it is not running.

Source

pub async fn has_module_host(&self, replica_id: u64) -> bool

true if the module host replica_id is currently registered with the controller.

Trait Implementations§

Source§

impl Clone for HostController

Source§

fn clone(&self) -> HostController

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T