To clearify: This question is about Greg Young's Event Store.
I tried to soft delete a stream which contained 2 events:
var slice = con.ReadStreamEventsBackwardAsync(streamName, 0, 1, resolveLinkTos: true).Result;
es.DeleteStreamAsync(streamName, slice.LastEventNumber, hardDelete: false).Wait();
This call was successful and investigating the store revealed a new metadata event. This event was of type $metadata
and contained:
{
"$tb": 9223372036854775807
}
$tb
stands for "truncate before" and is described in Deleting streams and events. The documentation says:
When you delete a stream, its TruncateBefore or $tb is set to the streams current last event number.
Which (as you can see in the json above) is not the case. Truncate before is set to long.MaxVaue
. Although this seems to be bad behaviour it is not the actual problem. The issue is that I cannot write to the stream anymore. Invoking the following snipped completes successfully but does not append any event to the stream:
await es.AppendToStreamAsync(persistenceId, expectedVersion < 0 ? ExpectedVersion.NoStream : expectedVersion, events);
In the snipped above, expectedVersion
is set to -1
. The metadata of the soft deleted stream says:
Stream is deleted: False
Meta Stream version: 0
Truncate before: 9223372036854775807
Max count:
Max age:
And reading the slice from the last event of the stream reveales:
Last Event number: 1
Next Event number: -1
Status: StreamNotFound
Has anybody encountered the same issue and might have found a solution which allows continuing appending events to deleted streams?
答案 0 :(得分:1)
我通过请求请求收到了一些有价值的信息。 首先,即使事件存储在当前时间点上的行为与文档中所描述的都不一样,但其行为仍正确。
我们从持久性ID和序列号生成了确定性Guid
。除非您根据流中的事件数确定序列号,否则不会有问题。软删除的流没有返回任何导致新事件的序列号为0的事件,因此我们生成了与流中第一个(但已删除)事件相同的事件ID。然后事件存储继续进行,并忽略了新事件,因为(基于生成的事件ID)已存储并删除了该新事件。
解决方案是从StreamEventSlice.LastEventNumber
而不是从事件存储返回的事件数中获取当前序列号。