public bool DeleteDocument(string key, Guid?etag, out RavenJObject metadata, out Guid?deletedETag) { var existingEtag = AssertValidEtag(key, etag, "DELETE", null); deletedETag = existingEtag; metadata = null; var readResult = storage.Documents.Read(new RavenJObject { { "key", key } }); if (readResult == null) { return(false); } metadata = readResult.Data().ToJObject(); storage.Documents.Remove(new RavenJObject { { "key", key } }); documentCacher.RemoveCachedDocument(key, existingEtag ?? Guid.Empty); return(true); }
public bool DeleteDocument(string key, Etag etag, out RavenJObject metadata, out Etag deletedETag) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } var normalizedKey = CreateKey(key); var normalizedKeyAsSlice = (Slice)normalizedKey; if (etag != null) { EnsureDocumentEtagMatch(normalizedKey, etag, "DELETE"); } ushort?existingVersion; if (!tableStorage.Documents.Contains(Snapshot, normalizedKeyAsSlice, writeBatch.Value, out existingVersion)) { if (logger.IsDebugEnabled) { logger.Debug("Document with key '{0}' was not found, and considered deleted", key); } ; metadata = null; deletedETag = null; return(false); } if (!metadataIndex.Contains(Snapshot, normalizedKeyAsSlice, writeBatch.Value)) //data exists, but metadata is not --> precaution, should never be true { var errorString = string.Format("Document with key '{0}' was found, but its metadata wasn't found --> possible data corruption", key); throw new InvalidDataException(errorString); } var existingEtag = EnsureDocumentEtagMatch(normalizedKey, etag, "DELETE"); int _; var documentMetadata = ReadDocumentMetadata(normalizedKey, normalizedKeyAsSlice, out _); metadata = documentMetadata.Metadata; deletedETag = etag != null ? existingEtag : documentMetadata.Etag; tableStorage.Documents.Delete(writeBatch.Value, normalizedKey, existingVersion); metadataIndex.Delete(writeBatch.Value, normalizedKey); tableStorage.Documents.GetIndex(Tables.Documents.Indices.KeyByEtag) .Delete(writeBatch.Value, deletedETag); documentCacher.RemoveCachedDocument(normalizedKey, existingEtag); if (logger.IsDebugEnabled) { logger.Debug("Deleted document with key = '{0}'", key); } return(true); }