Skip to content

Commit

Permalink
Don't pass the registry into IndexStore, it's not needed and that was…
Browse files Browse the repository at this point in the history
… blowing out the registry cache
  • Loading branch information
halgari committed May 6, 2024
1 parent 943d5e1 commit b40fad2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/NexusMods.MnemonicDB.Storage/RocksDbBackend/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public IWriteBatch CreateBatch()
public void DeclareIndex<TComparator>(IndexType name)
where TComparator : IDatomComparator
{
var indexStore = new IndexStore<TComparator>(name.ToString(), name, registry);
var indexStore = new IndexStore<TComparator>(name.ToString(), name);
_stores.Add(name, indexStore);

var index = new Index<TComparator>(indexStore);
Expand Down
33 changes: 10 additions & 23 deletions src/NexusMods.MnemonicDB.Storage/RocksDbBackend/IndexStore.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using DynamicData;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.DatomComparators;
using NexusMods.MnemonicDB.Abstractions.DatomIterators;
using NexusMods.MnemonicDB.Storage.Abstractions;
using RocksDbSharp;

namespace NexusMods.MnemonicDB.Storage.RocksDbBackend;

public class IndexStore<TComparator> : IRocksDBIndexStore
where TComparator : IDatomComparator
public class IndexStore<TComparator>(string handleName, IndexType type) : IRocksDBIndexStore
where TComparator : IDatomComparator
{
private readonly string _handleName;
private readonly AttributeRegistry _registry;
private IntPtr _comparator;
private CompareDelegate _comparatorDelegate = null!;
private RocksDb _db = null!;
private DestructorDelegate _destructorDelegate = null!;
private NameDelegate _nameDelegate = null!;
private IntPtr _namePtr;
Expand All @@ -30,27 +25,20 @@ public class IndexStore<TComparator> : IRocksDBIndexStore
/// things will never amount to more than a few dozen objects.
/// </summary>
/// <returns></returns>
private static List<object> _roots = new ();

public IndexStore(string handleName, IndexType type, AttributeRegistry registry)
{
Type = type;
_registry = registry;
_handleName = handleName;
}
private static readonly List<object> Roots = new ();

public ColumnFamilyHandle Handle { get; private set; } = null!;

public IndexType Type { get; }
public IndexType Type { get; } = type;

public void SetupColumnFamily(IIndex index, ColumnFamilies columnFamilies)
{
_options = new ColumnFamilyOptions();
_namePtr = Marshal.StringToHGlobalAnsi(_handleName);
_namePtr = Marshal.StringToHGlobalAnsi(handleName);

_nameDelegate = _ => _namePtr;
_destructorDelegate = _ => { };
_comparatorDelegate = (_, a, alen, b, blen) =>
_destructorDelegate = static _ => { };
_comparatorDelegate = static (_, a, alen, b, blen) =>
{
unsafe
{
Expand All @@ -59,19 +47,18 @@ public void SetupColumnFamily(IIndex index, ColumnFamilies columnFamilies)
};

// Save these as roots so they never get GC'd
_roots.Add((_nameDelegate, _destructorDelegate, _comparatorDelegate));
Roots.Add((_nameDelegate, _destructorDelegate, _comparatorDelegate));

_comparator =
Native.Instance.rocksdb_comparator_create(IntPtr.Zero, _destructorDelegate, _comparatorDelegate,
_nameDelegate);
_options.SetComparator(_comparator);

columnFamilies.Add(_handleName, _options);
columnFamilies.Add(handleName, _options);
}

public void PostOpenSetup(RocksDb db)
{
_db = db;
Handle = db.GetColumnFamily(_handleName);
Handle = db.GetColumnFamily(handleName);
}
}

0 comments on commit b40fad2

Please sign in to comment.