public void DeleteRevision(DocumentsOperationContext context, Slice key, string collection, string changeVector, long lastModifiedTicks) { var collectionName = new CollectionName(collection); var table = EnsureRevisionTableCreated(context.Transaction.InnerTransaction, collectionName); long revisionEtag; if (table.ReadByKey(key, out TableValueReader tvr)) { using (TableValueToSlice(context, (int)RevisionsTable.LowerId, ref tvr, out Slice lowerId)) using (GetKeyPrefix(context, lowerId, out Slice prefixSlice)) { IncrementCountOfRevisions(context, prefixSlice, -1); } revisionEtag = TableValueToEtag((int)RevisionsTable.Etag, ref tvr); table.Delete(tvr.Id); } else { var tombstoneTable = context.Transaction.InnerTransaction.OpenTable(TombstonesSchema, RevisionsTombstonesSlice); if (tombstoneTable.ReadByKey(key, out var existingTombstone)) { revisionEtag = TableValueToEtag((int)TombstoneTable.Etag, ref existingTombstone); tombstoneTable.Delete(existingTombstone.Id); } else { // we need to generate a unique etag if we got a tombstone revisions from replication, // but we don't want to mess up the order of events so the delete revision etag we use is negative revisionEtag = _documentsStorage.GenerateNextEtagForReplicatedTombstoneMissingDocument(context); } } CreateTombstone(context, key, revisionEtag, collectionName, changeVector, lastModifiedTicks); }