Skip to content

A Stream implementation with a journal that tracks changes. Allows Commit, Rollback and Replay to provide guaranteed writes.

Notifications You must be signed in to change notification settings

LordMike/MBW.Utilities.Journal

Repository files navigation

MBW.Utilities.Journal Generic Build NuGet

An implementation of a generic transactional stream for .NET, with support for writing changes to a journal file. The journal can then be committed, rolled back or replayed to ensure consistent writes.

Packages

Package Nuget Alpha
MBW.Utilities.Journal NuGet Alpha

How to use

var myStream = File.OpenWrite("DemoFile.txt");
var myJournal = await JournaledStreamFactory.CreateSparseJournal(myStream, "DemoFile.txt.jrnl");

// Always use the Journal to write to the file
myJournal.Write("Hello world"u8);

// Remember to call Commit() to apply changes
await myJournal.Commit();

More extended examples:

Features

  • Turn any read/write stream into a journaled stream which guarantees that writes complete fully, or can be retried, assuming your streams are backed by persistent storage
  • Easy codepath for using a file as the journal
  • Exchangeable journal file implementation, so the journal can be written other places than in files
  • Fully async API
  • Ability to Commit and Apply journals in separate operations
  • Recovers unapplied journals on startup, if a previous program run did not fully apply a journal (configurable behaviour)

Notes

  • If you have a database file or similar you want to protect, it is important to always wrap streams for that in JournalStreams. The reason being that if a write happens that isn't fully written to the file, it will not be noticed by future readers, if they don't also use JournalStreams
    • It is recommended to create a producer in your app, that produces the stream (wrapped in JournalStreams) for your datafile centrally, so all users get the same behavior
    • JournalStreams does not create the journal, until a write happens, so the cost of creating a JournalStreams is an exists check (to see if a past journal exists)
  • This is not thread safe in any manner, like all other streams

About

A Stream implementation with a journal that tracks changes. Allows Commit, Rollback and Replay to provide guaranteed writes.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages