Skip to content

Commit

Permalink
Add compaction methods to the RecordTable.
Browse files Browse the repository at this point in the history
  • Loading branch information
koculu committed Sep 1, 2024
1 parent 50ae54e commit fc971b6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/ZoneTree.FullTextSearch.Playground/SearchEngineApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ record = Interlocked.Increment(ref nextRecord);

sw.Restart();
SearchEngine.Index.EvictToDisk();
RecordTable.EvictToDisk();
Console.WriteLine("Waiting for background threads...");
SearchEngine.Index.WaitForBackgroundThreads();
RecordTable.WaitForBackgroundThreads();
Console.WriteLine("Merging completed in: " + sw.ElapsedMilliseconds + " ms");
if (cancellationTokenSource.IsCancellationRequested && isInteractive)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ZoneTree.FullTextSearch/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<Authors>Ahmed Yasin Koculu</Authors>
<PackageId>ZoneTree.FullTextSearch</PackageId>
<Title>ZoneTree.FullTextSearch</Title>
<ProductVersion>1.0.2.0</ProductVersion>
<Version>1.0.2.0</Version>
<ProductVersion>1.0.3.0</ProductVersion>
<Version>1.0.3.0</Version>
<Authors>Ahmed Yasin Koculu</Authors>
<AssemblyTitle>ZoneTree.FullTextSearch</AssemblyTitle>
<Description>ZoneTree.FullTextSearch is an open-source library that extends ZoneTree to provide efficient full-text search capabilities. It offers a fast, embedded search engine suitable for applications that require high performance and do not rely on external databases.</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void ThrowIfIndexIsDropped()
public bool IsIndexDropped { get => isDropped; }

/// <summary>
/// Evicts inactive data from memory to disk in both primary and secondary zone trees.
/// Evicts data from memory to disk in both primary and secondary zone trees.
/// </summary>
public void EvictToDisk()
{
Expand Down
41 changes: 40 additions & 1 deletion src/ZoneTree.FullTextSearch/Storage/RecordTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class RecordTable<TRecord, TValue> : IDisposable where TRecord : u
/// </summary>
public bool IsDropped { get => isDropped; }

bool isDropped = false;
bool isDropped;

/// <summary>
/// Initializes a new instance of the RecordTable class, setting up the two ZoneTrees and their maintainers.
Expand Down Expand Up @@ -105,6 +105,15 @@ public bool TryGetValue(TRecord record, out TValue value)
return ZoneTree1.TryGet(record, out value);
}

/// <summary>
/// Throws an exception if the index has been dropped, preventing further operations on a dropped index.
/// </summary>
void ThrowIfIndexIsDropped()
{
if (isDropped)
throw new Exception($"{nameof(RecordTable<TRecord, TValue>)} is dropped.");
}

/// <summary>
/// Tries to retrieve a record associated with a given value.
/// </summary>
Expand All @@ -116,6 +125,36 @@ public bool TryGetRecord(TValue value, out TRecord record)
return ZoneTree2.TryGet(value, out record);
}

/// <summary>
/// Evicts data from memory to disk in both primary and secondary zone trees.
/// </summary>
public void EvictToDisk()
{
ThrowIfIndexIsDropped();
Maintainer1.EvictToDisk();
Maintainer2.EvictToDisk();
}

/// <summary>
/// Attempts to cancel any background threads associated with maintenance tasks for both zone trees.
/// </summary>
public void TryCancelBackgroundThreads()
{
ThrowIfIndexIsDropped();
Maintainer1.TryCancelBackgroundThreads();
Maintainer2.TryCancelBackgroundThreads();
}

/// <summary>
/// Waits for all background threads associated with maintenance tasks to complete for both zone trees.
/// </summary>
public void WaitForBackgroundThreads()
{
ThrowIfIndexIsDropped();
Maintainer1.WaitForBackgroundThreads();
Maintainer2.WaitForBackgroundThreads();
}

/// <summary>
/// Drops the record table.
/// </summary>
Expand Down

0 comments on commit fc971b6

Please sign in to comment.