Skip to content

Commit

Permalink
RavenDB-22835 rename + fix tests + add a dew more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aviv committed Nov 25, 2024
1 parent 34d92ec commit f9569de
Show file tree
Hide file tree
Showing 6 changed files with 450 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

namespace Raven.Server.Documents;

public class FixCorruptedCountersTask
public class CountersRepairTask
{
private readonly DocumentDatabase _database;

private readonly Logger _logger;

public static string Completed = string.Empty;

public FixCorruptedCountersTask(DocumentDatabase database)
public CountersRepairTask(DocumentDatabase database)
{
_database = database;
_logger = LoggingSource.Instance.GetLogger<FixCorruptedCountersTask>(_database.Name);
_logger = LoggingSource.Instance.GetLogger<CountersRepairTask>(_database.Name);
}

public async Task Start(string lastProcessedKey)
Expand Down Expand Up @@ -128,7 +128,7 @@ private void MarkAsCompleted()
using (_database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext writeCtx))
using (var tx = writeCtx.OpenWriteTransaction())
{
_database.DocumentsStorage.SetFixCountersLastKey(writeCtx, Completed);
_database.DocumentsStorage.SetLastFixedCounterKey(writeCtx, Completed);
tx.Commit();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Raven.Server/Documents/CountersStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,8 @@ public int FixCountersForDocuments(DocumentsOperationContext context, List<strin
numOfCounterGroupsFixed += FixCountersForDocument(context, docId);
}

var lastProcessedKey = hasMore ? docIds[^1] : FixCorruptedCountersTask.Completed;
_documentsStorage.SetFixCountersLastKey(context, lastProcessedKey);
var lastProcessedKey = hasMore ? docIds[^1] : CountersRepairTask.Completed;
_documentsStorage.SetLastFixedCounterKey(context, lastProcessedKey);

return numOfCounterGroupsFixed;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Raven.Server/Documents/DocumentDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public DocumentDatabase(string name, RavenConfiguration configuration, ServerSto
});
_hasClusterTransaction = new ManualResetEventSlim(false);
IdentityPartsSeparator = '/';
FixCorruptedCountersTask = new FixCorruptedCountersTask(this);
CountersRepairTask = new CountersRepairTask(this);
}
catch (Exception)
{
Expand Down Expand Up @@ -287,7 +287,7 @@ public DocumentDatabase(string name, RavenConfiguration configuration, ServerSto

public StudioConfiguration StudioConfiguration { get; private set; }

public FixCorruptedCountersTask FixCorruptedCountersTask { get; private set; }
public CountersRepairTask CountersRepairTask { get; private set; }

public bool Is32Bits { get; }

Expand Down Expand Up @@ -393,9 +393,9 @@ record = _serverStore.Cluster.ReadDatabase(context, Name, out index);
var lastCompletedClusterTransactionIndex = DocumentsStorage.ReadLastCompletedClusterTransactionIndex(ctx.Transaction.InnerTransaction);
ClusterWideTransactionIndexWaiter.SetAndNotifyListenersIfHigher(lastCompletedClusterTransactionIndex);

var fixCountersLastKey = DocumentsStorage.ReadFixCountersLastKey(ctx.Transaction.InnerTransaction);
if (fixCountersLastKey != FixCorruptedCountersTask.Completed)
_ = Task.Run(() => FixCorruptedCountersTask.Start(fixCountersLastKey), DatabaseShutdown);
var lastCounterFixed = DocumentsStorage.ReadLastFixedCounterKey(ctx.Transaction.InnerTransaction);
if (lastCounterFixed != CountersRepairTask.Completed)
_ = Task.Run(() => CountersRepairTask.Start(lastCounterFixed), DatabaseShutdown);
}

_ = Task.Run(async () =>
Expand Down
4 changes: 2 additions & 2 deletions src/Raven.Server/Documents/DocumentsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public void SetLastCompletedClusterTransactionIndex(DocumentsOperationContext co
tree.Add(LastCompletedClusterTransactionIndexSlice, indexSlice);
}

public static string ReadFixCountersLastKey(Transaction tx)
public static string ReadLastFixedCounterKey(Transaction tx)
{
if (tx == null)
throw new InvalidOperationException("No active transaction found in the context, and at least read transaction is needed");
Expand All @@ -768,7 +768,7 @@ public static string ReadFixCountersLastKey(Transaction tx)
return Encodings.Utf8.GetString(val.Reader.Base, val.Reader.Length);
}

public void SetFixCountersLastKey(DocumentsOperationContext context, string lastKey)
public void SetLastFixedCounterKey(DocumentsOperationContext context, string lastKey)
{
var tree = context.Transaction.InnerTransaction.ReadTree(GlobalTreeSlice);
using (Slice.From(context.Allocator, lastKey, out var slice))
Expand Down
14 changes: 2 additions & 12 deletions src/Raven.Server/Documents/Handlers/CountersHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,10 @@ protected override long ExecuteCmd(DocumentsOperationContext context)

foreach (var cgd in _counterGroups)
{
try
{

using (cgd.Values)
{
PutCounters(context, cgd);
}
}
catch (Exception e)
using (cgd.Values)
{
Console.WriteLine(e);
throw;
PutCounters(context, cgd);
}

}

UpdateDocumentsMetadata(context);
Expand Down
Loading

0 comments on commit f9569de

Please sign in to comment.