forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RavenDB-23100 - remove the need to lower the key for indexes with the…
… new version
- Loading branch information
1 parent
0a0820e
commit 7ac4c09
Showing
11 changed files
with
282 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Raven.Server/Documents/Indexes/Workers/HandleNotNormalizedCompareExchangeReferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using Raven.Server.Config.Categories; | ||
using Raven.Server.ServerWide.Context; | ||
using Voron; | ||
|
||
namespace Raven.Server.Documents.Indexes.Workers; | ||
|
||
public class HandleNotNormalizedCompareExchangeReferences : HandleCompareExchangeReferences | ||
{ | ||
public HandleNotNormalizedCompareExchangeReferences(Index index, HashSet<string> collectionsWithCompareExchangeReferences, DocumentsStorage documentsStorage, IndexStorage indexStorage, IndexingConfiguration configuration) : base(index, collectionsWithCompareExchangeReferences, documentsStorage, indexStorage, configuration) | ||
{ | ||
} | ||
|
||
protected override IndexItem GetItem(DocumentsOperationContext databaseContext, Slice key) | ||
{ | ||
return HandleNotNormalizedDocumentReferences.GetNonNormalizedDocumentItem(databaseContext, key); | ||
} | ||
|
||
protected override void AfterGetItemsFromCollectionThatReference(string collection, IndexingStatsScope stats, DocumentsOperationContext databaseContext, TransactionOperationContext indexContext) | ||
{ | ||
HandleNotNormalizedDocumentReferences.AfterGetItemsFromCollectionThatReference(collection, stats, _referencesStorage, databaseContext, indexContext); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/Raven.Server/Documents/Indexes/Workers/HandleNotNormalizedDocumentReferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections.Generic; | ||
using Raven.Client.Documents.Indexes; | ||
using Raven.Server.Config.Categories; | ||
using Raven.Server.Documents.Indexes.Static; | ||
using Raven.Server.ServerWide.Context; | ||
using Voron; | ||
|
||
namespace Raven.Server.Documents.Indexes.Workers; | ||
|
||
public class HandleNotNormalizedDocumentReferences : HandleDocumentReferences | ||
{ | ||
public HandleNotNormalizedDocumentReferences(Index index, Dictionary<string, HashSet<CollectionName>> referencedCollections, DocumentsStorage documentsStorage, IndexStorage indexStorage, IndexingConfiguration configuration) : base(index, referencedCollections, documentsStorage, indexStorage, configuration) | ||
{ | ||
} | ||
|
||
protected HandleNotNormalizedDocumentReferences(Index index, Dictionary<string, HashSet<CollectionName>> referencedCollections, DocumentsStorage documentsStorage, IndexStorage indexStorage, IndexStorage.ReferencesBase referencesStorage, IndexingConfiguration configuration) : base(index, referencedCollections, documentsStorage, indexStorage, referencesStorage, configuration) | ||
{ | ||
} | ||
|
||
protected override IndexItem GetItem(DocumentsOperationContext databaseContext, Slice key) | ||
{ | ||
return GetNonNormalizedDocumentItem(databaseContext, key); | ||
} | ||
|
||
public static unsafe IndexItem GetNonNormalizedDocumentItem(DocumentsOperationContext databaseContext, Slice key) | ||
{ | ||
using (DocumentIdWorker.GetLower(databaseContext.Allocator, key.Content.Ptr, key.Size, out var loweredKey)) | ||
{ | ||
var documentItem = GetDocumentItem(databaseContext, loweredKey); | ||
if (documentItem == null) | ||
{ | ||
// this isn't required for new indexes as CleanupDocuments will handle it. | ||
// however, for older indexes, we need to clean up any leftovers. | ||
CurrentIndexingScope.Current.ReferencesToDelete ??= new HashSet<Slice>(); | ||
CurrentIndexingScope.Current.ReferencesToDelete.Add(key.Clone(databaseContext.Allocator)); | ||
} | ||
|
||
return documentItem; | ||
} | ||
} | ||
|
||
protected override void AfterGetItemsFromCollectionThatReference(string collection, IndexingStatsScope stats, DocumentsOperationContext databaseContext, TransactionOperationContext indexContext) | ||
{ | ||
AfterGetItemsFromCollectionThatReference(collection, stats, _referencesStorage, databaseContext, indexContext); | ||
} | ||
|
||
public static void AfterGetItemsFromCollectionThatReference(string collection, IndexingStatsScope stats, IndexStorage.ReferencesBase referencesStorage, DocumentsOperationContext databaseContext, TransactionOperationContext indexContext) | ||
{ | ||
if (CurrentIndexingScope.Current.ReferencesToDelete == null) | ||
return; | ||
|
||
using (stats.For(IndexingOperation.Map.DocumentRead, start: false).For(IndexingOperation.Storage.UpdateReferences)) | ||
{ | ||
foreach (var keyToRemove in CurrentIndexingScope.Current.ReferencesToDelete) | ||
{ | ||
referencesStorage.RemoveReferences(keyToRemove, collection, null, indexContext.Transaction); | ||
keyToRemove.Release(databaseContext.Allocator); | ||
} | ||
} | ||
|
||
CurrentIndexingScope.Current.ReferencesToDelete.Clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-114 KB
test/SlowTests/Data/RavenDB_23100/2024-11-17-09-31-49-8220303.ravendb-snapshot
Binary file not shown.
Binary file added
BIN
+115 KB
test/SlowTests/Data/RavenDB_23100/2024-11-18-17-16-52-7843589.ravendb-snapshot
Binary file not shown.
Binary file added
BIN
+101 KB
test/SlowTests/Data/RavenDB_23100/2024-11-18-18-07-42-3204449.ravendb-snapshot
Binary file not shown.
Oops, something went wrong.