Skip to content

Commit

Permalink
RavenDB-23249 - address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Feb 4, 2025
1 parent 0c1aec5 commit f960ef5
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/Raven.Server/Documents/Indexes/Auto/AutoMapIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Raven.Server.Documents.Indexes.Auto
internal sealed class AutoMapIndex : MapIndexBase<AutoMapIndexDefinition, AutoIndexField>
{
private AutoMapIndex(AutoMapIndexDefinition definition)
: base(IndexType.AutoMap, IndexSourceType.Documents, definition)
: base(IndexType.AutoMap, IndexSourceType.Documents, definition, compiled: null)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public FaultyInMemoryIndex(Exception e, string name, IndexingConfiguration confi
}

private FaultyInMemoryIndex(Exception e, IndexingConfiguration configuration, IndexDefinitionBaseServerSide definition, SearchEngineType searchEngineType)
: base(IndexType.Faulty, IndexSourceType.None, definition)
: base(IndexType.Faulty, IndexSourceType.None, definition, compiled: null)
{
_e = e;
_createdAt = DateTime.UtcNow;
Expand Down
24 changes: 20 additions & 4 deletions src/Raven.Server/Documents/Indexes/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public abstract class Index<TIndexDefinition, TField> : Index
{
public new TIndexDefinition Definition => (TIndexDefinition)base.Definition;

protected Index(IndexType type, IndexSourceType sourceType, TIndexDefinition definition)
: base(type, sourceType, definition)
protected Index(IndexType type, IndexSourceType sourceType, TIndexDefinition definition, AbstractStaticIndexBase compiled)
: base(type, sourceType, definition, compiled)
{
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public bool DeployedOnAllNodes
private string _lastPendingStatus;
public MultipleUseFlag ForceReplace = new MultipleUseFlag();

protected bool HandleAllDocs;
protected readonly bool HandleAllDocs;

protected internal MeterMetric MapsPerSec;
protected internal MeterMetric ReducesPerSec;
Expand Down Expand Up @@ -282,15 +282,28 @@ public bool DeployedOnAllNodes
private bool _newComplexFieldsToReport = false;
public HashSet<IndexField> ComplexFieldsNotIndexedByCorax { get; private set; }

protected Index(IndexType type, IndexSourceType sourceType, IndexDefinitionBaseServerSide definition)
protected Index(IndexType type, IndexSourceType sourceType, IndexDefinitionBaseServerSide definition, AbstractStaticIndexBase compiled)
{
Type = type;
SourceType = sourceType;
Definition = definition;
Collections = new HashSet<string>(Definition.Collections, StringComparer.OrdinalIgnoreCase);

if (Collections.Contains(Constants.Documents.Collections.AllDocumentsCollection))
{
HandleAllDocs = true;
}
else if (compiled != null)
{
foreach (var collection in compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

_queryBuilderFactories = new QueryBuilderFactories
{
Expand Down Expand Up @@ -4444,6 +4457,9 @@ public virtual bool WorksOnAnyCollection(HashSet<string> collections)
if (Collections.Count == 0)
return false;

if (HandleAllDocs)
return true;

return Collections.Overlaps(collections);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Raven.Server/Documents/Indexes/MapIndexBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Raven.Client.Documents.Indexes;
using Raven.Server.Documents.Includes;
using Raven.Server.Documents.Indexes.Persistence;
using Raven.Server.Documents.Indexes.Static;
using Raven.Server.Documents.Indexes.Workers;
using Raven.Server.Documents.Indexes.Workers.Cleanup;
using Raven.Server.Documents.Queries;
Expand All @@ -19,7 +20,7 @@ public abstract class MapIndexBase<T, TField> : Index<T, TField> where T : Index
private IndexingStatsScope _statsInstance;
private readonly MapStats _stats = new MapStats();

protected MapIndexBase(IndexType type, IndexSourceType sourceType, T definition) : base(type, sourceType, definition)
protected MapIndexBase(IndexType type, IndexSourceType sourceType, T definition, AbstractStaticIndexBase compiled) : base(type, sourceType, definition, compiled)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal sealed class AutoMapReduceIndex : MapReduceIndexBase<AutoMapReduceIndex
private readonly MapOutput _output;

private AutoMapReduceIndex(AutoMapReduceIndexDefinition definition)
: base(IndexType.AutoMapReduce, IndexSourceType.Documents, definition)
: base(IndexType.AutoMapReduce, IndexSourceType.Documents, definition, compiled: null)
{
_isFanout = definition.GroupByFields.Any(x => x.Value.GroupByArrayBehavior == GroupByArrayBehavior.ByIndividualValues);
_output = new MapOutput(_isFanout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class MapReduceIndexBase<T, TField> : Index<T, TField> where T :
private IndexingStatsScope _statsInstance;
private readonly MapPhaseStats _stats = new MapPhaseStats();

protected MapReduceIndexBase(IndexType type, IndexSourceType sourceType, T definition) : base(type, sourceType, definition)
protected MapReduceIndexBase(IndexType type, IndexSourceType sourceType, T definition, AbstractStaticIndexBase compiled) : base(type, sourceType, definition, compiled)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MapReduceIndex : MapReduceIndexBase<MapReduceIndexDefinition, Index
public IPropertyAccessor OutputReduceToCollectionPropertyAccessor;

protected MapReduceIndex(MapReduceIndexDefinition definition, AbstractStaticIndexBase compiled)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition, compiled)
{
_compiled = compiled;

Expand All @@ -56,12 +56,7 @@ protected MapReduceIndex(MapReduceIndexDefinition definition, AbstractStaticInde
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down Expand Up @@ -517,9 +512,6 @@ public override bool WorksOnAnyCollection(HashSet<string> collections)
if (_referencedCollections == null)
return false;

if (HandleAllDocs)
return true;

return _referencedCollections.Overlaps(collections);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class MapCountersIndex : MapIndexBase<MapIndexDefinition, IndexFie
private HandleCompareExchangeCountersReferences _handleCompareExchangeReferences;

private MapCountersIndex(MapIndexDefinition definition, AbstractStaticIndexBase compiled)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition, compiled)
{
_compiled = compiled;

Expand All @@ -42,12 +42,7 @@ private MapCountersIndex(MapIndexDefinition definition, AbstractStaticIndexBase
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down Expand Up @@ -161,9 +156,6 @@ public override bool WorksOnAnyCollection(HashSet<string> collections)
if (_referencedCollections == null)
return false;

if (HandleAllDocs)
return true;

return _referencedCollections.Overlaps(collections);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public MapReduceCountersIndex(MapReduceIndexDefinition definition, AbstractStati
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/Raven.Server/Documents/Indexes/Static/MapIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class MapIndex : MapIndexBase<MapIndexDefinition, IndexField>
private HandleCompareExchangeReferences _handleCompareExchangeReferences;

private MapIndex(MapIndexDefinition definition, AbstractStaticIndexBase compiled)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition, compiled)
{
_compiled = compiled;

Expand All @@ -47,12 +47,7 @@ private MapIndex(MapIndexDefinition definition, AbstractStaticIndexBase compiled
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down Expand Up @@ -177,9 +172,6 @@ public override bool WorksOnAnyCollection(HashSet<string> collections)
if (_referencedCollections == null)
return false;

if (HandleAllDocs)
return true;

return _referencedCollections.Overlaps(collections);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public MapReduceTimeSeriesIndex(MapReduceIndexDefinition definition, AbstractSta
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class MapTimeSeriesIndex : MapIndexBase<MapIndexDefinition, IndexF
private HandleCompareExchangeTimeSeriesReferences _handleCompareExchangeReferences;

private MapTimeSeriesIndex(MapIndexDefinition definition, AbstractStaticIndexBase compiled)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition)
: base(definition.IndexDefinition.Type, definition.IndexDefinition.SourceType, definition, compiled)
{
_compiled = compiled;

Expand All @@ -44,12 +44,7 @@ private MapTimeSeriesIndex(MapIndexDefinition definition, AbstractStaticIndexBas
foreach (var collection in _compiled.ReferencedCollections)
{
foreach (var referencedCollection in collection.Value)
{
_referencedCollections.Add(referencedCollection.Name);

if (referencedCollection.Name == Constants.Documents.Collections.AllDocumentsCollection)
HandleAllDocs = true;
}
}
}

Expand Down Expand Up @@ -165,9 +160,6 @@ public override bool WorksOnAnyCollection(HashSet<string> collections)
if (_referencedCollections == null)
return false;

if (HandleAllDocs)
return true;

return _referencedCollections.Overlaps(collections);
}

Expand Down
2 changes: 1 addition & 1 deletion test/FastTests/Server/Documents/Indexing/BasicAnalyzers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public override TokenStream TokenStream(string fieldName, TextReader reader)

internal class TestIndex : Index
{
public TestIndex(DocumentDatabase database, IndexingConfiguration configuration) : base(IndexType.None, IndexSourceType.None, new TestIndexDefinitions())
public TestIndex(DocumentDatabase database, IndexingConfiguration configuration) : base(IndexType.None, IndexSourceType.None, new TestIndexDefinitions(), compiled: null)
{
DocumentDatabase = database;
Configuration = configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public override void Dispose()
public class FakeIndex : Index
{
public FakeIndex()
: base(IndexType.Map, IndexSourceType.Documents, new AutoMapIndexDefinition("Orders", new AutoIndexField[0]))
: base(IndexType.Map, IndexSourceType.Documents, new AutoMapIndexDefinition("Orders", new AutoIndexField[0]), compiled: null)
{
}

Expand Down

0 comments on commit f960ef5

Please sign in to comment.