diff --git a/src/NexusMods.MnemonicDB.Abstractions/Models/ModelDefinition.cs b/src/NexusMods.MnemonicDB.Abstractions/Models/ModelDefinition.cs
new file mode 100644
index 00000000..c0c5449f
--- /dev/null
+++ b/src/NexusMods.MnemonicDB.Abstractions/Models/ModelDefinition.cs
@@ -0,0 +1,61 @@
+namespace NexusMods.MnemonicDB.Abstractions.Models;
+
+public class ModelDefinition
+{
+ ///
+ /// Creates a new ModelDefinition, with the given name.
+ ///
+ public static ModelDefinition New(string name)
+ {
+ return new ModelDefinition();
+ }
+
+ public ModelDefinition Composes()
+ {
+ return this;
+ }
+
+ public ModelDefinition Composes(string name)
+ {
+ return this;
+ }
+
+ public ModelDefinition Composes(string name)
+ {
+ return this;
+ }
+
+ public ModelDefinition Composes(string name)
+ {
+ return this;
+ }
+
+ public ModelDefinition Composes(string name)
+ {
+ return this;
+ }
+
+ ///
+ /// Defines a new attribute on the model of the given attribute type with the given parameters
+ ///
+ public ModelDefinition WithAttribute(string name, bool isIndexed = false, bool noHistory = false)
+ where TAttribute : IAttribute
+ {
+ return this;
+ }
+
+ ///
+ /// Defines a reference in another model that points to this class. These references will be exposed
+ /// in the `name` property of this model.
+ ///
+ public ModelDefinition WithBackReference(string name)
+ {
+ return this;
+ }
+
+ public ModelDefinition Build()
+ {
+ return this;
+ }
+
+}
diff --git a/src/NexusMods.MnemonicDB.Queryable/NexusMods.MnemonicDB.Queryable.csproj b/src/NexusMods.MnemonicDB.Queryable/NexusMods.MnemonicDB.Queryable.csproj
deleted file mode 100644
index 3a635329..00000000
--- a/src/NexusMods.MnemonicDB.Queryable/NexusMods.MnemonicDB.Queryable.csproj
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
- net8.0
- enable
- enable
-
-
-
diff --git a/src/NexusMods.MnemonicDB.Storage/DatomStore.cs b/src/NexusMods.MnemonicDB.Storage/DatomStore.cs
index d8f35912..9d1b3c38 100644
--- a/src/NexusMods.MnemonicDB.Storage/DatomStore.cs
+++ b/src/NexusMods.MnemonicDB.Storage/DatomStore.cs
@@ -43,6 +43,8 @@ public class DatomStore : IDatomStore, IHostedService
private readonly PooledMemoryBufferWriter _prevWriter;
private TxId _asOfTx = TxId.MinValue;
+ private Task? _bootStrapTask = null;
+
private static readonly TimeSpan TransactionTimeout = TimeSpan.FromMinutes(120);
///
@@ -55,8 +57,6 @@ public class DatomStore : IDatomStore, IHostedService
///
private NextIdCache _nextIdCache;
- private bool _isStarted = false;
-
///
/// The task consuming and logging transactions
///
@@ -241,18 +241,21 @@ private async Task Bootstrap()
// Call directly into `Log` as the transaction channel is not yet set up
Log(pending, out _);
_currentSnapshot = _backend.GetSnapshot();
- return;
}
-
- _logger.LogInformation("Bootstrapping the datom store, existing state found, last tx: {LastTx}",
- lastTx.Value.ToString("x"));
- _asOfTx = TxId.From(lastTx.Value);
- _currentSnapshot = snapshot;
+ else
+ {
+ _logger.LogInformation("Bootstrapping the datom store, existing state found, last tx: {LastTx}",
+ lastTx.Value.ToString("x"));
+ _asOfTx = TxId.From(lastTx.Value);
+ _currentSnapshot = snapshot;
+ }
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to bootstrap the datom store");
+ throw;
}
+ _txTask = Task.Run(ConsumeTransactions);
}
#region Internals
@@ -553,17 +556,16 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
lock (this)
{
- if (_isStarted) return;
- _isStarted = true;
+ _bootStrapTask ??= Task.Run(Bootstrap, cancellationToken);
}
- await Bootstrap();
- _txTask = Task.Run(ConsumeTransactions);
+ await _bootStrapTask;
}
///
- public Task StopAsync(CancellationToken cancellationToken)
+ public async Task StopAsync(CancellationToken cancellationToken)
{
- return Task.CompletedTask;
+ _txChannel.Writer.TryComplete();
+ await (_txTask ?? Task.CompletedTask);
}
}
diff --git a/src/NexusMods.MnemonicDB/Connection.cs b/src/NexusMods.MnemonicDB/Connection.cs
index 325a7e79..d8d6b2ef 100644
--- a/src/NexusMods.MnemonicDB/Connection.cs
+++ b/src/NexusMods.MnemonicDB/Connection.cs
@@ -24,7 +24,7 @@ public class Connection : IConnection, IHostedService
private IDb? _db;
private readonly IEnumerable _declaredAttributes;
private readonly ILogger _logger;
- private bool _isStarted = false;
+ private Task? _bootstrapTask;
///
/// Main connection class, co-ordinates writes and immutable reads
@@ -157,11 +157,13 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
lock (this)
{
- if (_isStarted)
- return;
- _isStarted = true;
+ _bootstrapTask ??= Task.Run(Bootstrap, cancellationToken);
}
+ await _bootstrapTask;
+ }
+ private async Task Bootstrap()
+ {
// Won't complete until the DatomStore has properly started
await _store.StartAsync(CancellationToken.None);
try
diff --git a/tests/NexusMods.MnemonicDB.TestModel/NexusMods.MnemonicDB.TestModel.csproj b/tests/NexusMods.MnemonicDB.TestModel/NexusMods.MnemonicDB.TestModel.csproj
index c84e3f6b..437d754f 100644
--- a/tests/NexusMods.MnemonicDB.TestModel/NexusMods.MnemonicDB.TestModel.csproj
+++ b/tests/NexusMods.MnemonicDB.TestModel/NexusMods.MnemonicDB.TestModel.csproj
@@ -8,6 +8,7 @@
+