Skip to content

Commit

Permalink
RavenDB-22292 limit time series retention tx to 16MB
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 committed Apr 18, 2024
1 parent 81b1d82 commit d15502e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Raven.Server/Documents/TimeSeries/TimeSeriesRollups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public static void SplitKey(Slice key, out string docId, out string name)
internal class TimeSeriesRetentionCommand : TransactionOperationsMerger.MergedTransactionCommand
{
public const int BatchSize = 1024;
private static readonly Size MaxTransactionSize = new(16, SizeUnit.Megabytes);

private readonly List<Slice> _keys;
private readonly string _collection;
Expand Down Expand Up @@ -274,6 +275,9 @@ protected override long ExecuteCmd(DocumentsOperationContext context)

if (logger.IsInfoEnabled)
logger.Info($"{request} was executed (successfully: {done})");

if (context.Transaction.InnerTransaction.LowLevelTransaction.TransactionSize > MaxTransactionSize)
break;
}

return retained;
Expand Down
8 changes: 4 additions & 4 deletions src/Raven.Server/Documents/TimeSeries/TimeSeriesStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ public static void RemoveTimeSeriesNameFromMetadata(DocumentsOperationContext ct
{
var storage = ctx.DocumentDatabase.DocumentsStorage;

var doc = storage.Get(ctx, docId);
if (doc == null)
return;

var tss = storage.TimeSeriesStorage;
if (tss.Stats.GetStats(ctx, docId, tsName).Count > 0)
return;

var doc = storage.Get(ctx, docId);
if (doc == null)
return;

var data = doc.Data;
var flags = doc.Flags.Strip(DocumentFlags.FromClusterTransaction | DocumentFlags.Resolved);
Expand Down
2 changes: 2 additions & 0 deletions src/Voron/Impl/LowLevelTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void Reset()

public event Action<LowLevelTransaction> LastChanceToReadFromWriteTransactionBeforeCommit;

public Size TransactionSize => new Size(NumberOfModifiedPages * Constants.Storage.PageSize, SizeUnit.Bytes) + AdditionalMemoryUsageSize;

public Size AdditionalMemoryUsageSize
{
get
Expand Down

0 comments on commit d15502e

Please sign in to comment.