Skip to content

Commit

Permalink
Merge branch 'v6.0' of github.com:ravendb/ravendb into v6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arekpalinski committed Jul 2, 2024
2 parents 976fdf6 + 0ae4355 commit 1762ba9
Show file tree
Hide file tree
Showing 47 changed files with 1,334 additions and 179 deletions.
6 changes: 5 additions & 1 deletion src/Raven.Client/Documents/BulkInsert/BulkInsertOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ private static bool CheckServerVersion(string serverVersion)
if (serverVersion != null && Version.TryParse(serverVersion, out var ver))
{
// Version 6 only from 6.0.2
if (ver.Major == 6 && ver.Build < 2)
if (ver.Major == 6 && ver.Minor > 0)
return true;

if (ver.Major == 6 && ver.Minor == 0 && ver.Build < 2)
return false;

// 5.4.108 or higher
if (ver.Major > 5 || (ver.Major == 5 && ver.Minor >= 4 && ver.Build >= 110))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void Fill(IOperationProgress progress, int shardNumber, string nodeTag)
Counters = bp.Counters;
TimeSeries = bp.TimeSeries;
CompareExchangeTombstones = bp.CompareExchangeTombstones;
TimeSeriesDeletedRanges = bp.TimeSeriesDeletedRanges;
}

public override DynamicJsonValue ToJson()
Expand Down
5 changes: 2 additions & 3 deletions src/Raven.Client/Documents/Smuggler/DatabaseItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ public enum DatabaseItemType
LegacyAttachmentDeletions = 1 << 10,
DatabaseRecord = 1 << 11,
Unknown = 1 << 12,

Attachments = 1 << 14,
CounterGroups = 1 << 15,
Subscriptions = 1 << 16,
CompareExchangeTombstones = 1 << 17,
TimeSeries = 1 << 18,

ReplicationHubCertificates = 1 << 19
ReplicationHubCertificates = 1 << 19,
TimeSeriesDeletedRanges = 1 << 20
}

[Flags]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class DatabaseSmugglerOptions : IDatabaseSmugglerOptions
DatabaseItemType.Attachments |
DatabaseItemType.CounterGroups |
DatabaseItemType.Subscriptions |
DatabaseItemType.TimeSeries;
DatabaseItemType.TimeSeries |
DatabaseItemType.TimeSeriesDeletedRanges;

public const DatabaseRecordItemType DefaultOperateOnDatabaseRecordTypes = DatabaseRecordItemType.Client |
DatabaseRecordItemType.ConflictSolverConfig |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void Fill(IOperationProgress progress, int shardNumber, string nodeTag)
Counters = sp.Counters;
TimeSeries = sp.TimeSeries;
CompareExchangeTombstones = sp.CompareExchangeTombstones;
TimeSeriesDeletedRanges = sp.TimeSeriesDeletedRanges;
}

public override DynamicJsonValue ToJson()
Expand Down
3 changes: 3 additions & 0 deletions src/Raven.Client/Documents/Smuggler/SmugglerProgressBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public abstract class SmugglerProgressBase : IOperationProgress

public Counts CompareExchangeTombstones { get; set; }

public CountsWithSkippedCountAndLastEtag TimeSeriesDeletedRanges { get; set; }

public virtual DynamicJsonValue ToJson()
{
return new DynamicJsonValue(GetType())
Expand All @@ -51,6 +53,7 @@ public virtual DynamicJsonValue ToJson()
[nameof(CompareExchangeTombstones)] = CompareExchangeTombstones.ToJson(),
[nameof(TimeSeries)] = TimeSeries.ToJson(),
[nameof(ReplicationHubCertificates)] = ReplicationHubCertificates.ToJson(),
[nameof(TimeSeriesDeletedRanges)] = TimeSeriesDeletedRanges.ToJson()
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/Raven.Client/Documents/Smuggler/SmugglerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public SmugglerResult()
Subscriptions = new Counts();
ReplicationHubCertificates = new Counts();
TimeSeries = new CountsWithSkippedCountAndLastEtag();
TimeSeriesDeletedRanges = new CountsWithSkippedCountAndLastEtag();
_progress = new SmugglerProgress(this);
}

Expand Down Expand Up @@ -86,6 +87,11 @@ void IOperationResult.MergeWith(IOperationResult result)

smugglerResult.TimeSeries.LastEtag = Math.Max(smugglerResult.TimeSeries.LastEtag, TimeSeries.LastEtag);

smugglerResult.TimeSeriesDeletedRanges.ReadCount += TimeSeriesDeletedRanges.ReadCount;
smugglerResult.TimeSeriesDeletedRanges.ErroredCount += TimeSeriesDeletedRanges.ErroredCount;
smugglerResult.TimeSeriesDeletedRanges.SizeInBytes += TimeSeriesDeletedRanges.SizeInBytes;
smugglerResult.TimeSeriesDeletedRanges.LastEtag = Math.Max(smugglerResult.TimeSeriesDeletedRanges.LastEtag, TimeSeriesDeletedRanges.LastEtag);

smugglerResult.Identities.ReadCount += Identities.ReadCount;
smugglerResult.Identities.ErroredCount += Identities.ErroredCount;

Expand Down Expand Up @@ -230,6 +236,7 @@ public SmugglerProgress(SmugglerResult result)
Subscriptions = _result?.Subscriptions;
TimeSeries = _result?.TimeSeries;
ReplicationHubCertificates = _result?.ReplicationHubCertificates;
TimeSeriesDeletedRanges = _result?.TimeSeriesDeletedRanges;
}

internal string Message { get; set; }
Expand Down Expand Up @@ -261,6 +268,9 @@ public long GetLastEtag()
if (TimeSeries.LastEtag > lastEtag)
lastEtag = TimeSeries.LastEtag;

if (TimeSeriesDeletedRanges.LastEtag > lastEtag)
lastEtag = TimeSeriesDeletedRanges.LastEtag;

return lastEtag;
}

Expand Down
21 changes: 20 additions & 1 deletion src/Raven.Server/Documents/BlittableMetadataModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Raven.Server.Documents
{
public sealed class BlittableMetadataModifier : IDisposable, IBlittableDocumentModifier
{
private bool _disposed;

private bool _readingMetadataObject;
private int _depth;
private State _state = State.None;
Expand Down Expand Up @@ -131,6 +133,8 @@ private enum State
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartObject()
{
AssertNotDisposed();

if (_readingMetadataObject == false)
return;

Expand All @@ -140,6 +144,8 @@ public void StartObject()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void EndObject()
{
AssertNotDisposed();

if (_readingMetadataObject == false)
return;

Expand All @@ -153,6 +159,8 @@ public void EndObject()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool AboutToReadPropertyName(IJsonParser reader, JsonParserState state)
{
AssertNotDisposed();

if (reader is UnmanagedJsonParser unmanagedParser)
return AboutToReadPropertyNameInternal(unmanagedParser, state);
if (reader is ObjectJsonParser objectParser)
Expand Down Expand Up @@ -592,7 +600,7 @@ private unsafe bool AboutToReadPropertyNameInMetadataUnlikely(IJsonParser reader
aboutToReadPropertyName = true;
return true;
}

if ("Raven-Replication-Version"u8.IsEqualConstant(state.StringBuffer) == false ||
"Raven-Replication-History"u8.IsEqualConstant(state.StringBuffer) == false)
{
Expand Down Expand Up @@ -847,10 +855,14 @@ public void Dispose()
_ctx.ReturnMemory(_allocations[i]);
}
_allocations.Clear();

_disposed = true;
}

public void Reset(JsonOperationContext ctx)
{
AssertNotDisposed();

if (_ctx == null) // should never happen
{
_ctx = ctx;
Expand All @@ -872,5 +884,12 @@ public void Reset(JsonOperationContext ctx)
_metadataCollections = _ctx.GetLazyStringForFieldWithCaching(CollectionName.MetadataCollectionSegment);
_metadataExpires = _ctx.GetLazyStringForFieldWithCaching(Constants.Documents.Metadata.Expires);
}

[Conditional("DEBUG")]
private void AssertNotDisposed()
{
if (_disposed)
throw new ObjectDisposedException(nameof(BlittableMetadataModifier));
}
}
}
21 changes: 21 additions & 0 deletions src/Raven.Server/Documents/Handlers/CountersHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public sealed class SmugglerCounterBatchCommand : MergedTransactionCommand<Docum

public long ErrorCount;

private BlittableJsonDocumentBuilder _builder;
private BlittableMetadataModifier _metadataModifier;

public SmugglerCounterBatchCommand(DocumentDatabase database, SmugglerResult result)
{
_database = database;
Expand Down Expand Up @@ -358,6 +361,21 @@ public void RegisterForDisposal(IDisposable data)
_toDispose.Add(data);
}

public BlittableJsonDocumentBuilder GetOrCreateBuilder(UnmanagedJsonParser parser, JsonParserState state, string debugTag, BlittableMetadataModifier modifier = null)
{
return _builder ??= new BlittableJsonDocumentBuilder(_context, BlittableJsonDocumentBuilder.UsageMode.ToDisk, debugTag, parser, state, modifier: modifier);
}

public BlittableMetadataModifier GetOrCreateMetadataModifier(string firstEtagOfLegacyRevision = null, long legacyRevisionsCount = 0, bool legacyImport = false,
bool readLegacyEtag = false, DatabaseItemType operateOnTypes = DatabaseItemType.None)
{
_metadataModifier ??= new BlittableMetadataModifier(_context, legacyImport, readLegacyEtag, operateOnTypes);
_metadataModifier.FirstEtagOfLegacyRevision = firstEtagOfLegacyRevision;
_metadataModifier.LegacyRevisionsCount = legacyRevisionsCount;

return _metadataModifier;
}

protected override long ExecuteCmd(DocumentsOperationContext context)
{
if (_legacyDictionary != null)
Expand Down Expand Up @@ -587,6 +605,9 @@ public void Dispose()

_legacyDictionary?.Clear();

_builder?.Dispose();
_metadataModifier?.Dispose();

_resetContext?.Dispose();
_resetContext = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ internal void ApplyBackwardCompatibility(DatabaseSmugglerOptionsServerSide optio
if (RequestRouter.TryGetClientVersion(HttpContext, out var version) == false)
return;

if (version.Major == 5 && (version.Minor < 4 || version.Minor == 4 && version.Build < 200) &&
options.OperateOnTypes.HasFlag(DatabaseItemType.TimeSeries))
{
// version is older than 5.4.200
options.OperateOnTypes |= DatabaseItemType.TimeSeriesDeletedRanges;
}

if (version.Major != RavenVersionAttribute.Instance.MajorVersion)
return;

Expand Down
66 changes: 64 additions & 2 deletions src/Raven.Server/Documents/Handlers/TimeSeriesHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Raven.Server.Smuggler.Documents;
using Sparrow.Json;
using System.Diagnostics.CodeAnalysis;
using Raven.Client.Documents.Smuggler;
using Sparrow.Json.Parsing;

namespace Raven.Server.Documents.Handlers
{
Expand All @@ -26,7 +28,7 @@ public async Task Stats()
await processor.ExecuteAsync();
}
}

[RavenAction("/databases/*/timeseries/ranges", "GET", AuthorizationStatus.ValidUser, EndpointType.Read)]
public async Task ReadRanges()
{
Expand Down Expand Up @@ -275,6 +277,8 @@ public sealed class SmugglerTimeSeriesBatchCommand : MergedTransactionCommand<Do

private readonly Dictionary<string, List<TimeSeriesItem>> _dictionary;

private readonly Dictionary<string, List<TimeSeriesDeletedRangeItemForSmuggler>> _deletedRanges;

private readonly DocumentsOperationContext _context;

public DocumentsOperationContext Context => _context;
Expand All @@ -289,10 +293,14 @@ public sealed class SmugglerTimeSeriesBatchCommand : MergedTransactionCommand<Do

public string LastChangeVector;

private BlittableJsonDocumentBuilder _builder;
private BlittableMetadataModifier _metadataModifier;

public SmugglerTimeSeriesBatchCommand(DocumentDatabase database)
{
_database = database;
_dictionary = new Dictionary<string, List<TimeSeriesItem>>();
_dictionary = new Dictionary<string, List<TimeSeriesItem>>(StringComparer.OrdinalIgnoreCase);
_deletedRanges = new Dictionary<string, List<TimeSeriesDeletedRangeItemForSmuggler>>(StringComparer.OrdinalIgnoreCase);
_toDispose = new();
_toReturn = new();
_releaseContext = _database.DocumentsStorage.ContextPool.AllocateOperationContext(out _context);
Expand All @@ -304,6 +312,27 @@ protected override long ExecuteCmd(DocumentsOperationContext context)

var changes = 0L;

foreach (var (docId, items) in _deletedRanges)
{
foreach (var item in items)
{
using (item)
{
var deletionRangeRequest = new TimeSeriesStorage.DeletionRangeRequest
{
DocumentId = docId,
Collection = item.Collection,
Name = item.Name,
From = item.From,
To = item.To
};
tss.DeleteTimestampRange(context, deletionRangeRequest, remoteChangeVector: null, updateMetadata: false);
}
}

changes += items.Count;
}

foreach (var (docId, items) in _dictionary)
{
var collectionName = _database.DocumentsStorage.ExtractCollectionName(context, items[0].Collection);
Expand Down Expand Up @@ -346,6 +375,21 @@ public bool AddToDictionary(TimeSeriesItem item)
return newItem;
}

public bool AddToDeletedRanges(TimeSeriesDeletedRangeItemForSmuggler item)
{
bool newItem = false;

if (_deletedRanges.TryGetValue(item.DocId, out var deletedRangesList) == false)
{
_deletedRanges[item.DocId] = deletedRangesList = [];
newItem = true;
}

deletedRangesList.Add(item);
return newItem;
}


public void AddToDisposal(IDisposable disposable)
{
_toDispose.Add(disposable);
Expand All @@ -356,6 +400,21 @@ public void AddToReturn(AllocatedMemoryData allocatedMemoryData)
_toReturn.Add(allocatedMemoryData);
}

public BlittableJsonDocumentBuilder GetOrCreateBuilder(UnmanagedJsonParser parser, JsonParserState state, string debugTag, BlittableMetadataModifier modifier = null)
{
return _builder ??= new BlittableJsonDocumentBuilder(_context, BlittableJsonDocumentBuilder.UsageMode.ToDisk, debugTag, parser, state, modifier: modifier);
}

public BlittableMetadataModifier GetOrCreateMetadataModifier(string firstEtagOfLegacyRevision = null, long legacyRevisionsCount = 0, bool legacyImport = false,
bool readLegacyEtag = false, DatabaseItemType operateOnTypes = DatabaseItemType.None)
{
_metadataModifier ??= new BlittableMetadataModifier(_context, legacyImport, readLegacyEtag, operateOnTypes);
_metadataModifier.FirstEtagOfLegacyRevision = firstEtagOfLegacyRevision;
_metadataModifier.LegacyRevisionsCount = legacyRevisionsCount;

return _metadataModifier;
}

public void Dispose()
{
if (_isDisposed)
Expand All @@ -373,6 +432,9 @@ public void Dispose()
_context.ReturnMemory(returnable);
_toReturn.Clear();

_builder?.Dispose();
_metadataModifier?.Dispose();

_releaseContext?.Dispose();
_releaseContext = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void Fill(IOperationProgress progress, int shardNumber, string nodeTag)
Counters = rp.Counters;
TimeSeries = rp.TimeSeries;
CompareExchangeTombstones = rp.CompareExchangeTombstones;
TimeSeriesDeletedRanges = rp.TimeSeriesDeletedRanges;
}

public override DynamicJsonValue ToJson()
Expand Down
Loading

0 comments on commit 1762ba9

Please sign in to comment.