Nebula
Persistence

LocalPersistenceStore

In-process IPersistenceStore with the exact write rules of the persistence module (epoch check, version bump), optionally backed by a file so a single-process run survives a restart.

generated from the sources
public sealed class LocalPersistenceStore : IPersistenceStore

In-process IPersistenceStore with the exact write rules of the persistence module (epoch check, version bump), optionally backed by a file so a single-process run survives a restart. This is what -nebula-persistence-mode local uses (and what the tests use); a mesh wants the orchestrator's database instead (RemotePersistenceStore on every worker), because every worker needs to see the same records.

Writes land in memory at once. Ordinary writes are debounced by WriteIntervalSeconds; durability barriers are grouped for WriteBarrierIntervalSeconds and share a background rewrite from an immutable snapshot. Callbacks are delivered from Tick after that rewrite has completed, so game code sees the same main-thread ordering whichever store it runs on.

Constructors

LocalPersistenceStore

public LocalPersistenceStore();
public LocalPersistenceStore(string filePath);

An in-memory store that forgets everything when the process ends.

Fields

WriteIntervalSeconds

public float WriteIntervalSeconds = 1f;

Seconds between rewrites of the backing file while records keep changing.

WriteBarrierIntervalSeconds

public float WriteBarrierIntervalSeconds = 0.1f;

Time used to gather nearby durability barriers before starting each rewrite.

Properties

IsConnected

public bool IsConnected { get; }

Backend

public string Backend { get; }

KnownCount

public int KnownCount { get; }

FilePath

public string FilePath { get; }

Where the records are written, or "" for an in-memory store.

FileWriteCount

public long FileWriteCount { get; }

Successful full-file rewrites during this store's lifetime (useful for diagnostics).

TotalFileWriteMilliseconds

public double TotalFileWriteMilliseconds { get; }

Total milliseconds spent in successful full-file rewrites during this store's lifetime.

StaleSavesDropped

public long StaleSavesDropped { get; }

Saves refused during this store's lifetime because the stored record had a newer epoch. The first refusal of each key is also logged as a warning.

LastFileWriteMilliseconds

public double LastFileWriteMilliseconds { get; }

Milliseconds spent in the most recent successful full-file rewrite.

Methods

Connect

public void Connect();

Tick

public void Tick();

Save

public void Save(PersistedEntityRecord record);

Delete

public void Delete(string key);

WhenWritten

public void WhenWritten(Action onWritten);

Load

public void Load(string key, Action<PersistedEntityRecord> onLoaded);

LoadContainers

public void LoadContainers(IReadOnlyList<string> containerIds, Action<IReadOnlyDictionary<string, IReadOnlyList<PersistedEntityRecord>>> onLoaded);

One pass over the records, however many containers are asked for.

LoadCarried

public void LoadCarried(IReadOnlyList<string> carrierKeys, Action<IReadOnlyDictionary<string, IReadOnlyList<PersistedEntityRecord>>> onLoaded);

One pass over the records, however many carriers are asked for.

LoadWhere

public void LoadWhere(Func<PersistedEntityRecord, bool> predicate, Action<IReadOnlyList<PersistedEntityRecord>> onLoaded);

CountRecords

public void CountRecords(string scopeKey, string containerId, Action<int> onCounted);

Clear

public void Clear();

Dispose

public void Dispose();

Flush

public void Flush();

Write the backing file now instead of waiting for the debounce (shutdown, tests).

On this page