Skip to content

Commit

Permalink
RavenDB-22116 add debug method to delete document by etag
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 authored and arekpalinski committed Mar 6, 2024
1 parent 83c5b18 commit be2539a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/Raven.Server/Documents/DocumentsStorage.Debug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Raven.Server.ServerWide.Context;
using Voron.Data.Tables;

namespace Raven.Server.Documents
{
public partial class DocumentsStorage
{
public Debugging ForDebug => new Debugging(this);

public class Debugging
{
private readonly DocumentsStorage _storage;

public Debugging(DocumentsStorage storage)
{
_storage = storage;
}
// Used to delete corrupted document from the JS admin console
public void DeleteDocumentByEtag(long etag)
{
using (_storage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
using (var tx = context.OpenWriteTransaction())
{
var table = new Table(DocsSchema, context.Transaction.InnerTransaction);
var index = DocsSchema.FixedSizeIndexes[AllDocsEtagsSlice];

if (table.FindByIndex(index, etag, out var reader))
{
var doc = _storage.TableValueToDocument(context, ref reader, DocumentFields.Id);
_storage.Delete(context, doc.Id, DocumentFlags.None);
tx.Commit();
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Raven.Server/Documents/DocumentsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Raven.Server.Documents
{
public unsafe class DocumentsStorage : IDisposable
public unsafe partial class DocumentsStorage : IDisposable
{
private static readonly Slice DocsSlice;
public static readonly Slice CollectionEtagsSlice;
Expand Down
1 change: 0 additions & 1 deletion src/Voron/Data/Tables/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,6 @@ public long DeleteBackwardFrom(TableSchema.FixedSizeSchemaIndexDef index, long v

public bool FindByIndex(TableSchema.FixedSizeSchemaIndexDef index, long value, out TableValueReader reader)
{
AssertWritableTable();
reader = default;
var fst = GetFixedSizeTree(index);

Expand Down

0 comments on commit be2539a

Please sign in to comment.