Skip to content

Commit

Permalink
RavenDB-22369: Introducing the SupportedFeatures.All option and makin…
Browse files Browse the repository at this point in the history
…g SupportedFeatures mandatory to pass into IndexWriter.
  • Loading branch information
maciejaszyk authored and arekpalinski committed May 17, 2024
1 parent 558ba9e commit dbfad58
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 102 deletions.
2 changes: 1 addition & 1 deletion bench/Voron.Benchmark/Corax/AndOrBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void GenerateData(StorageEnvironment env)
using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
IndexFieldsMapping fields = CreateFieldsMapping(bsc);

using (var writer = new IndexWriter(env, fields))
using (var writer = new IndexWriter(env, fields, SupportedFeatures.All))
{
{
using var builder = writer.Index("Arava");
Expand Down
2 changes: 1 addition & 1 deletion bench/Voron.Benchmark/Corax/InBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static void GenerateData(StorageEnvironment env)
using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
IndexFieldsMapping fields = CreateFieldsMapping(bsc);

using (var writer = new IndexWriter(env, fields))
using (var writer = new IndexWriter(env, fields, SupportedFeatures.All))
{
{
using var builder = writer.Index("Arava");
Expand Down
2 changes: 1 addition & 1 deletion bench/Voron.Benchmark/Corax/OrderByBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static void GenerateData(StorageEnvironment env)
using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
IndexFieldsMapping fields = CreateFieldsMapping(bsc);

using (var writer = new IndexWriter(env, fields))
using (var writer = new IndexWriter(env, fields, SupportedFeatures.All))
{
{
using var builder = writer.Index("items/1"u8);
Expand Down
2 changes: 1 addition & 1 deletion bench/Voron.Benchmark/Corax/StartWithBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void GenerateData(StorageEnvironment env)
{
using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
IndexFieldsMapping fields = CreateFieldsMapping(bsc);
using (var writer = new IndexWriter(env, fields))
using (var writer = new IndexWriter(env, fields, SupportedFeatures.All))
{
{
using var entryWriter = writer.Index("Arava");
Expand Down
6 changes: 3 additions & 3 deletions src/Corax/Indexing/IndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private IndexWriter(IndexFieldsMapping fieldsMapping, SupportedFeatures supporte
_indexDebugDumper = new IndexOperationsDumper(fieldsMapping);
_builder = new IndexEntryBuilder(this);
_fieldsMapping = fieldsMapping;
_supportedFeatures = supportedFeatures ?? new(); // if not explicitly set - all features are available
_supportedFeatures = supportedFeatures; // if not explicitly set - all features are available
_encodingBufferHandler = Analyzer.BufferPool.Rent(fieldsMapping.MaximumOutputSize);
_tokensBufferHandler = Analyzer.TokensPool.Rent(fieldsMapping.MaximumTokenSize);
_utf8ConverterBufferHandler = Analyzer.BufferPool.Rent(fieldsMapping.MaximumOutputSize * 10);
Expand All @@ -104,7 +104,7 @@ private IndexWriter(IndexFieldsMapping fieldsMapping, SupportedFeatures supporte
_removalsForTerm = new List<long>();
}

public IndexWriter([NotNull] StorageEnvironment environment, IndexFieldsMapping fieldsMapping, in SupportedFeatures supportedFeatures = default) : this(fieldsMapping, supportedFeatures)
public IndexWriter([NotNull] StorageEnvironment environment, IndexFieldsMapping fieldsMapping, SupportedFeatures supportedFeatures) : this(fieldsMapping, supportedFeatures)
{
TransactionPersistentContext transactionPersistentContext = new(true);
_transaction = environment.WriteTransaction(transactionPersistentContext);
Expand All @@ -113,7 +113,7 @@ public IndexWriter([NotNull] StorageEnvironment environment, IndexFieldsMapping
Init();
}

public IndexWriter([NotNull] Transaction tx, IndexFieldsMapping fieldsMapping, in SupportedFeatures supportedFeatures = default) : this(fieldsMapping, supportedFeatures)
public IndexWriter([NotNull] Transaction tx, IndexFieldsMapping fieldsMapping, SupportedFeatures supportedFeatures) : this(fieldsMapping, supportedFeatures)
{
_transaction = tx;

Expand Down
17 changes: 4 additions & 13 deletions src/Corax/SupportedFeatures.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
namespace Corax;

public class SupportedFeatures
public class SupportedFeatures(bool isPhraseQuerySupported, bool isStoreOnlySupported)
{
public readonly bool PhraseQuery = true;
public readonly bool StoreOnly = true;

public SupportedFeatures(bool isPhraseQuerySupported, bool isStoreOnlySupported)
{
PhraseQuery = isPhraseQuerySupported;
StoreOnly = isStoreOnlySupported;
}
public static readonly SupportedFeatures All = new (true, true);

public SupportedFeatures()
{
// all is supported
}
public readonly bool PhraseQuery = isPhraseQuerySupported;
public readonly bool StoreOnly = isStoreOnlySupported;
}
4 changes: 2 additions & 2 deletions test/FastTests/Corax/BoostingQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public unsafe void CanAddAndRemoveDocumentBoost()

using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
using var knownFields = CreateKnownFields(bsc);
using (var indexWriter = new IndexWriter(Env, knownFields))
using (var indexWriter = new IndexWriter(Env, knownFields, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/1");
indexWriter.Commit();
Expand Down Expand Up @@ -387,7 +387,7 @@ private void IndexEntries()
using var bsc = new ByteStringContext(SharedMultipleUseFlag.None);
using var knownFields = CreateKnownFields(bsc);

using var indexWriter = new IndexWriter(Env, knownFields);
using var indexWriter = new IndexWriter(Env, knownFields, SupportedFeatures.All);

foreach (var entry in longList)
{
Expand Down
10 changes: 5 additions & 5 deletions test/FastTests/Corax/Bugs/FacetIndexingRepro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void CanHandleRecompressionOfEntryTerms()
var fieldsTree = wtx.CreateTree(Constants.IndexWriter.FieldsSlice);
CompactTree idTree = fieldsTree.CompactTreeFor(id);

using var iw = new IndexWriter(wtx, fields);
using var iw = new IndexWriter(wtx, fields, SupportedFeatures.All);
string entryKey = "users/00000001";
long entryId;
using (var builder = iw.Index("entryKey"))
Expand Down Expand Up @@ -125,7 +125,7 @@ public unsafe void ShouldNotCorrupt()
var wtx = Env.WriteTransaction();
try
{
var iw = new IndexWriter(wtx, fields);
var iw = new IndexWriter(wtx, fields, SupportedFeatures.All);
while (true)
{
string id;
Expand Down Expand Up @@ -178,7 +178,7 @@ void FlushIndexAndRenewWriteTransaction()
txns++;
items = 0;
wtx = Env.WriteTransaction();
iw = new IndexWriter(wtx, fields);
iw = new IndexWriter(wtx, fields, SupportedFeatures.All);
}
}
finally
Expand Down Expand Up @@ -228,7 +228,7 @@ public unsafe void CanSuccessfullyIndexData()
IndexFieldsMapping indexFieldsMapping = builder.Build();
using (var wtx = Env.WriteTransaction())
{
var iw = new IndexWriter(wtx, indexFieldsMapping);
var iw = new IndexWriter(wtx, indexFieldsMapping, SupportedFeatures.All);
while (true)
{
string id;
Expand All @@ -248,7 +248,7 @@ public unsafe void CanSuccessfullyIndexData()
{
iw.Commit();
iw.Dispose();
iw = new IndexWriter(wtx, indexFieldsMapping);
iw = new IndexWriter(wtx, indexFieldsMapping, SupportedFeatures.All);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion test/FastTests/Corax/Bugs/IndexEntryReaderBigDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public unsafe void CanCreateAndReadBigDocument()


long entryId;
using (var indexWriter = new IndexWriter(Env, knownFields))
using (var indexWriter = new IndexWriter(Env, knownFields, SupportedFeatures.All))
{
var options = new[] { "one", "two", "three" };
using (var writer = indexWriter.Index("users/1"))
Expand Down
4 changes: 2 additions & 2 deletions test/FastTests/Corax/Bugs/OptimizedUpdatesOnIndexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void CanUpdateAndNotDelete()
{
using var fields = CreateKnownFields(Allocator);
long oldId;
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var entry = indexWriter.Update("cars/1"u8))
{
Expand All @@ -45,7 +45,7 @@ public void CanUpdateAndNotDelete()
}

long newId;
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var entry = indexWriter.Update("cars/1"u8))
{
Expand Down
2 changes: 1 addition & 1 deletion test/FastTests/Corax/Bugs/RavenDB-19283.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public unsafe void CanReadAndWriteLargeEntries()
using var knownFields = builder.Build();

long entryId;
using (var indexWriter = new IndexWriter(Env, knownFields))
using (var indexWriter = new IndexWriter(Env, knownFields, SupportedFeatures.All))
{
var options = new[] { "one", "two", "three" };
using (var writer = indexWriter.Index("users/1"))
Expand Down
3 changes: 2 additions & 1 deletion test/FastTests/Corax/Bugs/RavenDB-22285.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Corax;
using Corax.Analyzers;
using Corax.Indexing;
using Corax.Mappings;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void MultiTermMatchReturnsGoodResults()
using var mapping = CreateKnownFields(allocator);
var descendingSortedTerm = Enumerable.Range(0, 26).Select(i => new[] { (byte)('z' - i) }).ToList();
var database = new List<Dto>();
using (var indexWriter = new IndexWriter(Env, mapping))
using (var indexWriter = new IndexWriter(Env, mapping, SupportedFeatures.All))
{
for (var idX = 0; idX < 2096; ++idX)
{
Expand Down
12 changes: 6 additions & 6 deletions test/FastTests/Corax/CoraxCrud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void CanIndexUsingBuilder()
{
var fields = CreateKnownFields(Allocator);
Span<long> ids = stackalloc long[1024];
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Index("users/1"u8))
{
Expand All @@ -51,7 +51,7 @@ public void CanDetectWhenFieldHasMultipleTerms()
{
var fields = CreateKnownFields(Allocator);
Span<long> ids = stackalloc long[1024];
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Index("users/1"u8))
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public void CanUpdateWithDifferentFrequency()
{
var fields = CreateKnownFields(Allocator);
Span<long> ids = stackalloc long[1024];
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Index("users/1"u8))
{
Expand All @@ -90,7 +90,7 @@ public void CanUpdateWithDifferentFrequency()
indexWriter.Commit();
}

using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Update("users/1"u8))
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public void CanUpdateUsingBuilder()
{
var fields = CreateKnownFields(Allocator);
Span<long> ids = stackalloc long[1024];
using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Index("users/1"u8))
{
Expand All @@ -135,7 +135,7 @@ public void CanUpdateUsingBuilder()
indexWriter.Commit();
}

using (var indexWriter = new IndexWriter(Env, fields))
using (var indexWriter = new IndexWriter(Env, fields, SupportedFeatures.All))
{
using (var builder = indexWriter.Update("users/1"u8))
{
Expand Down
3 changes: 2 additions & 1 deletion test/FastTests/Corax/CoraxQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using Corax;
using Corax.Mappings;
using Corax.Querying.Matches;
using Corax.Querying.Matches.Meta;
Expand Down Expand Up @@ -334,7 +335,7 @@ private void IndexEntries()
_knownFields.TryGetByFieldId(TextualValueId, out binding);
_textualItemFieldMetadata = binding.Metadata;

using var indexWriter = new IndexWriter(Env, _knownFields);
using var indexWriter = new IndexWriter(Env, _knownFields, SupportedFeatures.All);

foreach (var entry in _entries)
{
Expand Down
12 changes: 6 additions & 6 deletions test/FastTests/Corax/DeleteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CanDelete()
Assert.Equal(_longList.Count, match.Fill(ids));
}

using (var indexWriter = new IndexWriter(Env, _analyzers))
using (var indexWriter = new IndexWriter(Env, _analyzers, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/0");
indexWriter.Commit();
Expand Down Expand Up @@ -81,7 +81,7 @@ public void CanDeleteNumericalData()
Assert.Equal(_longList.Count, match.Fill(ids));
}

using (var indexWriter = new IndexWriter(Env, _analyzers))
using (var indexWriter = new IndexWriter(Env, _analyzers, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/0");
indexWriter.Commit();
Expand Down Expand Up @@ -116,7 +116,7 @@ public void CanDeleteSingleItemInList(int batchSize)
Assert.Equal(batchSize, indexSearcher.NumberOfEntries);
}

using (var indexWriter = new IndexWriter(Env, _analyzers))
using (var indexWriter = new IndexWriter(Env, _analyzers, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/0");
indexWriter.Commit();
Expand Down Expand Up @@ -144,7 +144,7 @@ public void CanDeleteOneElement()
Assert.Equal(count, match.Fill(ids));
}

using (var indexWriter = new IndexWriter(Env, _analyzers))
using (var indexWriter = new IndexWriter(Env, _analyzers, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/9");
indexWriter.Commit();
Expand Down Expand Up @@ -180,7 +180,7 @@ public void CanDeleteAndPushUnderSameId()
var match = indexSearcher.TermQuery("Content", "0");
Assert.Equal(1, match.Fill(ids));
}
using (var indexWriter = new IndexWriter(Env, _analyzers))
using (var indexWriter = new IndexWriter(Env, _analyzers, SupportedFeatures.All))
{
indexWriter.TryDeleteEntry("list/0");
indexWriter.Commit();
Expand Down Expand Up @@ -229,7 +229,7 @@ private enum DataType

private void IndexEntries(IndexFieldsMapping knownFields)
{
using var indexWriter = new IndexWriter(Env, knownFields);
using var indexWriter = new IndexWriter(Env, knownFields, SupportedFeatures.All);

foreach (var entry in _longList)
{
Expand Down

0 comments on commit dbfad58

Please sign in to comment.