Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
TalZaccai committed Mar 8, 2025
1 parent 84f397e commit cb29622
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions libs/server/GarnetDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ public void Dispose()

if (ObjectStoreSizeTracker != null)
{
while (!ObjectStoreSizeTracker.Stopped)
Thread.Yield();
// If tracker has previously started, wait for it to stop
if (!ObjectStoreSizeTracker.TryPreventStart())
{
while (!ObjectStoreSizeTracker.Stopped)
Thread.Yield();
}
}

disposed = true;
Expand Down
12 changes: 11 additions & 1 deletion libs/server/Storage/SizeTracker/CacheSizeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CacheSizeTracker

int isStarted = 0;
private const int deltaFraction = 10; // 10% of target size
private TsavoriteKV<byte[], IGarnetObject, ObjectStoreFunctions, ObjectStoreAllocator> store;
TsavoriteKV<byte[], IGarnetObject, ObjectStoreFunctions, ObjectStoreAllocator> store;

internal bool Stopped => (mainLogTracker == null || mainLogTracker.Stopped) && (readCacheTracker == null || readCacheTracker.Stopped);

Expand Down Expand Up @@ -118,5 +118,15 @@ public void AddReadCacheTrackedSize(long size)
// just for the main log
this.readCacheTracker?.IncrementSize(size);
}

/// <summary>
/// If tracker has not started, prevent it from starting
/// </summary>
/// <returns>True if tracker hasn't previously started</returns>
public bool TryPreventStart()
{
var prevStarted = Interlocked.CompareExchange(ref isStarted, 1, 0);
return prevStarted == 0;
}
}
}

0 comments on commit cb29622

Please sign in to comment.