Skip to content

Commit bae5cd8

Browse files
committed
Scan update function, and tick based timestamps
1 parent 4c79ead commit bae5cd8

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
### 0.9.100 - 27/1/2025
4+
* Switch timestamps over to storing time as `DateTimeOffset.Ticks` so that we have the most accurate times possible
5+
* Provide a new `ScanUpdate` feature that can be used for data migration and conversions. Allows datoms to be deleted or
6+
updated based on a simple function interface
7+
38
### 0.9.99 - 21/1/2025
49
* Provide a way to open a RocksDB backend in read-only mode
510
* Default to zstd compression for RocksDB vs the previous snappy compression

src/NexusMods.MnemonicDB.Abstractions/Attributes/TimestampAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace NexusMods.MnemonicDB.Abstractions.Attributes;
1111
public sealed class TimestampAttribute(string ns, string name) : ScalarAttribute<DateTimeOffset, long, Int64Serializer>(ns, name)
1212
{
1313
/// <inheritdoc />
14-
protected override long ToLowLevel(DateTimeOffset value) => value.ToUnixTimeMilliseconds();
14+
protected override long ToLowLevel(DateTimeOffset value) => value.UtcTicks;
1515

1616
/// <inheritdoc />
17-
protected override DateTimeOffset FromLowLevel(long value, AttributeResolver resolver) => DateTimeOffset.FromUnixTimeMilliseconds(value);
17+
protected override DateTimeOffset FromLowLevel(long value, AttributeResolver resolver) => new(value, TimeSpan.Zero);
1818
}

src/NexusMods.MnemonicDB/Connection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public async Task<ICommitResult> FlushAndCompact()
264264
/// <inheritdoc />
265265
public Task UpdateSchema(params IAttribute[] attribute)
266266
{
267-
return Transact(new SchemaMigration(attribute));
267+
return Transact(new ScanUpdate(attribute));
268268
}
269269

270270
public IObservable<IChangeSet<Datom, DatomKey>> ObserveDatoms(SliceDescriptor descriptor)
@@ -327,7 +327,7 @@ private void Bootstrap()
327327
AttributeCache.Reset(initialDb);
328328

329329
var declaredAttributes = AttributeResolver.DefinedAttributes.OrderBy(a => a.Id.Id).ToArray();
330-
_store.Transact(new SchemaMigration(declaredAttributes));
330+
_store.Transact(new ScanUpdate(declaredAttributes));
331331

332332
_dbStreamDisposable = ProcessUpdates(_store.TxLog)
333333
.Subscribe();

src/NexusMods.MnemonicDB/InternalTxFunctions/SchemaMigration.cs renamed to src/NexusMods.MnemonicDB/InternalTxFunctions/ScanUpdate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace NexusMods.MnemonicDB.InternalTxFunctions;
1313

14-
internal class SchemaMigration : AInternalFn
14+
internal class ScanUpdate : AInternalFn
1515
{
1616
private readonly IAttribute[] _declaredAttributes;
1717
private ulong _tempId = PartitionId.Temp.MakeEntityId(1).Value;
1818

19-
public SchemaMigration(IAttribute[] attributes)
19+
public ScanUpdate(IAttribute[] attributes)
2020
{
2121
_declaredAttributes = attributes;
2222
}

src/NexusMods.MnemonicDB/Storage/DatomStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ internal void LogDatoms<TSource>(IWriteBatch batch, TSource datoms, bool advanc
386386
/// <exception cref="NotImplementedException"></exception>
387387
private void LogTx(IWriteBatch batch)
388388
{
389-
MemoryMarshal.Write(_txScratchSpace.Span, _timeProvider.GetUtcNow().ToUnixTimeMilliseconds());
389+
MemoryMarshal.Write(_txScratchSpace.Span, _timeProvider.GetUtcNow().UtcTicks);
390390
var id = EntityId.From(_thisTx.Value);
391391
var keyPrefix = new KeyPrefix(id, AttributeCache.GetAttributeId(MnemonicDB.Abstractions.BuiltInEntities.Transaction.Timestamp.Id), _thisTx, false, ValueTag.Int64);
392392
var datom = new Datom(keyPrefix, _txScratchSpace[..sizeof(long)]);

0 commit comments

Comments
 (0)