Skip to content

Commit

Permalink
RavenDB-23100 - use the correct item ID casing to align with the stor…
Browse files Browse the repository at this point in the history
…age state
  • Loading branch information
grisha-kotler authored and arekpalinski committed Dec 9, 2024
1 parent 644489c commit 5e4f23a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return new CounterIndexItem(counter.LuceneKey, counter.DocumentId, counter.Etag, counter.CounterName, counter.Size, counter);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.LowerSourceDocumentId;
}

public override void HandleDelete(Tombstone tombstone, string collection, Lazy<IndexWriteOperationBase> writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
{
using (DocumentIdWorker.GetSliceFromId(indexContext, tombstone.LowerId, out Slice documentIdPrefixWithCounterKeySeparator, SpecialChars.RecordSeparator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return new CounterIndexItem(counter.LuceneKey, counter.DocumentId, counter.Etag, counter.CounterName, counter.Size, counter);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.LowerSourceDocumentId;
}

public override void HandleDelete(Tombstone tombstone, string collection, Lazy<IndexWriteOperationBase> writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
{
using (DocumentIdWorker.GetSliceFromId(indexContext, tombstone.LowerId, out Slice documentIdPrefixWithTsKeySeparator, SpecialChars.RecordSeparator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return HandleNotNormalizedDocumentReferences.GetNonNormalizedDocumentItem(databaseContext, key);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.Id;
}

protected override void DeleteReferences(string collection, IndexingStatsScope stats, DocumentsOperationContext databaseContext, TransactionOperationContext indexContext)
{
HandleNotNormalizedDocumentReferences.DeleteReferences(collection, stats, _referencesStorage, databaseContext, indexContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return GetNonNormalizedDocumentItem(databaseContext, key);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.Id;
}

public static unsafe IndexItem GetNonNormalizedDocumentItem(DocumentsOperationContext databaseContext, Slice key)
{
using (DocumentIdWorker.GetLower(databaseContext.Allocator, key.Content.Ptr, key.Size, out var loweredKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return GetDocumentItem(databaseContext, key);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.LowerId;
}

public static IndexItem GetDocumentItem(DocumentsOperationContext databaseContext, Slice key)
{
// when there is conflict, we need to apply same behavior as if the document would not exist
Expand Down Expand Up @@ -247,7 +252,7 @@ protected HandleReferencesBase(Index index, DocumentsStorage documentsStorage, I
if (CanContinueReferenceBatch() == false)
{
// updating the last reference state in order to continue from the place we left off
referenceState = new ReferencesState.ReferenceState(referencedItem.Key, referencedItem.Etag, current.LowerSourceDocumentId ?? current.Id, lastIndexedParentEtag);
referenceState = new ReferencesState.ReferenceState(referencedItem.Key, referencedItem.Etag, GetNextItemId(current), lastIndexedParentEtag);

if (batchContinuationResult != Index.CanContinueBatchResult.RenewTransaction)
{
Expand Down Expand Up @@ -504,6 +509,8 @@ public InMemoryReferencesInfo GetReferencesInfo(string collection)

protected abstract IndexItem GetItem(DocumentsOperationContext databaseContext, Slice key);

protected abstract string GetNextItemId(IndexItem indexItem);

protected virtual void DeleteReferences(string collection, IndexingStatsScope stats, DocumentsOperationContext databaseContext, TransactionOperationContext indexContext)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return new TimeSeriesIndexItem(timeSeries.LuceneKey, timeSeries.DocId, timeSeries.Etag, default, timeSeries.Name, timeSeries.SegmentSize, timeSeries);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.LowerSourceDocumentId;
}

public override void HandleDelete(Tombstone tombstone, string collection, Lazy<IndexWriteOperationBase> writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
{
using (DocumentIdWorker.GetSliceFromId(indexContext, tombstone.LowerId, out Slice documentIdPrefixWithTsKeySeparator, SpecialChars.RecordSeparator))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ protected override IndexItem GetItem(DocumentsOperationContext databaseContext,
return new TimeSeriesIndexItem(timeSeries.LuceneKey, timeSeries.DocId, timeSeries.Etag, default, timeSeries.Name, timeSeries.SegmentSize, timeSeries);
}

protected override string GetNextItemId(IndexItem indexItem)
{
return indexItem.LowerSourceDocumentId;
}

public override void HandleDelete(Tombstone tombstone, string collection, Lazy<IndexWriteOperationBase> writer, TransactionOperationContext indexContext, IndexingStatsScope stats)
{
using (DocumentIdWorker.GetSliceFromId(indexContext, tombstone.LowerId, out Slice documentIdPrefixWithTsKeySeparator, SpecialChars.RecordSeparator))
Expand Down
12 changes: 10 additions & 2 deletions test/SlowTests/Issues/RavenDB-15754.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ public async Task CanIndexReferencedDocumentChange()

using (var bulk = store.BulkInsert())
{
var baseDate = new DateTime(2024, 9, 1);
for (var i = 0; i < _employeesCount; i++)
{
var date = baseDate.AddDays(i);
var dateString = date.ToString("yyyy-MM-dd");
await bulk.StoreAsync(new Employee
{
CompanyId = company.Id
CompanyId = company.Id,
Id = $"Employees/Accounts/937-A/{dateString}"
});
}
}
Expand Down Expand Up @@ -447,11 +451,15 @@ public async Task CanIndexReferencedCompareExchangeWithQuery()

using (var bulk = store.BulkInsert())
{
var baseDate = new DateTime(2024, 9, 1);
for (var i = 0; i < _employeesCount; i++)
{
var date = baseDate.AddDays(i);
var dateString = date.ToString("yyyy-MM-dd");
await bulk.StoreAsync(new Employee
{
CompanyId = _commonName
CompanyId = _commonName,
Id = $"Employees/Accounts/937-A/{dateString}"
});
}
}
Expand Down

0 comments on commit 5e4f23a

Please sign in to comment.