void IHandle <StorageMessage.WriteDelete> .Handle(StorageMessage.WriteDelete message) { Interlocked.Decrement(ref FlushMessagesInQueue); try { if (message.LiveUntil < DateTime.UtcNow) { return; } var record = LogRecord.DeleteTombstone(Writer.Checkpoint.ReadNonFlushed(), message.CorrelationId, message.EventStreamId, message.ExpectedVersion); WritePrepareWithRetry(record); } catch (Exception exc) { Log.ErrorException(exc, "Exception in writer."); throw; } finally { Flush(); } }
void IHandle <StorageMessage.WriteDelete> .Handle(StorageMessage.WriteDelete message) { Interlocked.Decrement(ref FlushMessagesInQueue); try { if (message.LiveUntil < DateTime.UtcNow) { return; } var eventId = Guid.NewGuid(); var commitCheck = _indexWriter.CheckCommit(message.EventStreamId, message.ExpectedVersion, new[] { eventId }); if (commitCheck.Decision != CommitDecision.Ok) { ActOnCommitCheckFailure(message.Envelope, message.CorrelationId, commitCheck); return; } if (message.HardDelete) { // HARD DELETE const long expectedVersion = EventNumber.DeletedStream - 1; var record = LogRecord.DeleteTombstone(Writer.Checkpoint.ReadNonFlushed(), message.CorrelationId, eventId, message.EventStreamId, expectedVersion, PrepareFlags.IsCommitted); var res = WritePrepareWithRetry(record); _indexWriter.PreCommit(new[] { res.Prepare }); } else { // SOFT DELETE var metastreamId = SystemStreams.MetastreamOf(message.EventStreamId); var expectedVersion = _indexWriter.GetStreamLastEventNumber(metastreamId); var logPosition = Writer.Checkpoint.ReadNonFlushed(); const PrepareFlags flags = PrepareFlags.SingleWrite | PrepareFlags.IsCommitted | PrepareFlags.IsJson; var data = new StreamMetadata(truncateBefore: EventNumber.DeletedStream).ToJsonBytes(); var res = WritePrepareWithRetry( LogRecord.Prepare(logPosition, message.CorrelationId, eventId, logPosition, 0, metastreamId, expectedVersion, flags, SystemEventTypes.StreamMetadata, data, null)); _indexWriter.PreCommit(new[] { res.Prepare }); } } catch (Exception exc) { Log.ErrorException(exc, "Exception in writer."); throw; } finally { Flush(); } }
void IHandle <StorageMessage.WriteDelete> .Handle(StorageMessage.WriteDelete message) { Interlocked.Decrement(ref FlushMessagesInQueue); try { if (message.LiveUntil < DateTime.UtcNow) { return; } if (ShouldCreateStreamFor(message)) { var transactionPos = Writer.Checkpoint.ReadNonFlushed(); var res = WritePrepareWithRetry(LogRecord.StreamCreated(transactionPos, message.CorrelationId, transactionPos, message.EventStreamId, LogRecord.NoData)); transactionPos = res.WrittenPos; WritePrepareWithRetry(LogRecord.Prepare(res.NewPos, message.CorrelationId, Guid.NewGuid(), transactionPos, 0, message.EventStreamId, message.ExpectedVersion, PrepareFlags.StreamDelete | PrepareFlags.TransactionEnd, SystemEventTypes.StreamDeleted, LogRecord.NoData, LogRecord.NoData)); } else { var record = LogRecord.DeleteTombstone(Writer.Checkpoint.ReadNonFlushed(), message.CorrelationId, message.EventStreamId, message.ExpectedVersion); WritePrepareWithRetry(record); } } finally { Flush(); } }