Struct corundum::stm::Log[][src]

pub struct Log<A: MemPool>(_, _);
Expand description

The Log type for pool A

It is pair of LogEnum and Notifier to keep a log in the Journal. A Journal comprises multiple pages with a fixed number of log slots. Each slot can be filled by one Log. The Journal object uses these logs to provide data consistency. Logs reside in the persistent region and their durability is ensured by flushing the cache lines after each log.

The default mechanism of taking logs is copy-on-write which creates a log when the object is mutably dereferenced. This requires two clflushes: one for the log, and one for the update to the original data.

Implementations

Sets the off and len of the log

This function is used for low-level atomic allocation. The algorithm is as follows:

  1. Create a neutral drop log (off = u64::MAX) in a log slot in the Journal
  2. Prepare allocation using pre_alloc()
  3. Add a low-level log for updating the off and len of the drop log using set function
  4. Perform the prepared changes to the allocator

Note that the deallocation of owned objects are handled through RAII. To reclaim the allocation of any sort on a failure, low-level DropOnFailure log is provided with the allocation.

If a crash happens before step 4, all changes are discarded and the drop log remains neutral. If a crash happens in the middle of step 4, the recovery procedure continues performing the changes, including the low-level logs for updating the drop log. Once it has the high-level drop log, the high-level recovery procedure reclaims the allocation as the crash happened inside a transaction.

Examples

P::transaction(|j| unsafe {
    // Create a neutral high-level log to drop the allocation on failure.
    // It is different from the low-level drop log which is inside the
    // allocator's ring buffer. Unlike that, this log is stored in the
    // journal object.
    let mut log = Log::drop_on_failure(u64::MAX, 1, j);
    
    // Prepare an allocation. The allocation is not durable yet. In case
    // of a crash, the prepared allocated space is gone. It is fine
    // because it has not been used. The `atomic_` functions
    // form a low-level atomic section.
    let (obj, off, len, zone) = P::atomic_new([1,2,3,4,5]);
    
    // Set the offset and size of the allocation to make the log valid.
    // Note that the changes will be effective after the allocation is
    // successfully performed.
    log.set(off, len, zone);
     
    // It is fine to work with the prepared raw pointer. All changes in
    // the low-level atomic section are considered as part of the
    // allocation and will be gone in case of a crash, as the allocation
    // will be dropped.
    obj[1] = 20;
    
    // Transaction ends here. The perform function sets the `operating`
    // flag to show that the prepared changes are being materialized.
    // This flag remains set until the end of materialization. In case
    // of a crash while operating, the recovery procedure first continues
    // the materialization, and then uses the `DropOnFailure` logs to
    // reclaim the allocation. `perform` function realizes the changes
    // made by the `pre_` function on the given memory zone.
    P::perform(zone);
}).unwrap();

Returns an string specifying the type of this log

Returns the inner value

Create a new log entry

Creates a log of x into journal and notifies the owner that log is created if notifier is specified.

Creates a log of &[x] into journal and notifies the owner that log is created if notifier is specified.

Creates a new DropOnCommit log and writes it on journal

Creates a new DropOnAbort log and writes it on journal

Creates a new DropOnFailure log and writes it on journal

Creates a new UnlockOnCommit for locking data in a thread

Creates a new RecountOnFailure log and writes it on journal

Clears this log and notifies the owner

  • If it is a DataLog, it reclaims the allocation for the log.
  • If it is a UnlockOnCommit, it unlocks the mutex.

Notify the owner that the log is created/cleared according to v

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.