Query on a soft deleted stream with new events returns nothing ?

I have a query that actually works fine with some brand new streams with events :

fromStreams('mystream1', 'mystream2')
    .partitionBy(function(e){
        if(e.body == null || e.body.ProductId == null) return null;
        return e.body.ProductId;
    })
    .when({
        $init: function() {
            return { create:0, delete:0 };
        },
        $created: function(s,e){ s.ProductId = e.body.ProductId; },
        "ProductCreated": function(s, e) {
            s.create++;
            return s;
        },            
        "ProductDeleted": function(s, e) {
            s.delete++;
            return s;
        }
    })

``

I get all expected results, and the projection status is "Completed/Stopped/Writing results"

  • Then I soft delete the stream.

  • Then I append some new events.

  • Then I run again the query …

I get nothing and the projection status is "Running"

Is there someone who knows wwwhy ?

Well, nobody ?

what is the output from curl -i http://yourinstance/streams/mystream1
and curl -i http://yourinstance/streams/mystream2

also do you get the same behavior with fromStream on each or only on the join?

In attachement are curl responses from the 2 streams :

  • before deletion

  • when deleted

  • after added some events

Produced by this test :

[TestMethod]
public async Task TheSoftDeleteThenProjectionProblem()
{
var stream1 = “mystream1” + Guid.NewGuid().ToString().ToLower();
var stream2 = “mystream2” + Guid.NewGuid().ToString().ToLower();

using (var factory = new EventStoreEventStreamFactory())
{
    var repos = factory.GetRepository();
    IEventStoreConnection connection = factory._connection;

    await repos.AppendEvents(stream1,
        new ProductCreatedEvent { ProductId = "p1" },
        new ProductCreatedEvent { ProductId = "p2" },
        new ProductCreatedEvent { ProductId = "p3" },
        new ProductCreatedEvent { ProductId = "p4" },
        new ProductDeletedEvent { ProductId = "p4" }
        );

    await repos.AppendEvents(stream2,
        new ProductChangedEvent { ProductId = "p1" },
        new ProductDeletedEvent { ProductId = "p2" },
        new ProductCreatedEvent { ProductId = "p3" }
        );

    WriteHttp("http://127.0.0.1:2114/streams/" + stream1);
    WriteHttp("http://127.0.0.1:2114/streams/" + stream2);

    await connection.DeleteStreamAsync(stream1, ExpectedVersion.Any);
    await connection.DeleteStreamAsync(stream2, ExpectedVersion.Any);

    WriteHttp("http://127.0.0.1:2114/streams/" + stream1);
    WriteHttp("http://127.0.0.1:2114/streams/" + stream2);

    await repos.AppendEvents(stream1,
        new ProductCreatedEvent { ProductId = "p1" },
        new ProductCreatedEvent { ProductId = "p2" },
        new ProductCreatedEvent { ProductId = "p3" },
        new ProductCreatedEvent { ProductId = "p4" },
        new ProductDeletedEvent { ProductId = "p4" }
    );

    await repos.AppendEvents(stream2,
        new ProductChangedEvent { ProductId = "p1" },
        new ProductDeletedEvent { ProductId = "p2" },
        new ProductCreatedEvent { ProductId = "p3" }
        );

    WriteHttp("http://127.0.0.1:2114/streams/" + stream1);
    WriteHttp("http://127.0.0.1:2114/streams/" + stream2);
}

}

void WriteHttp(string address)
{
System.Console.WriteLine("\n\n--------------------------------------- :: " + address);
var startInfo = new ProcessStartInfo(“curl”, "-i " + address);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;

var curl = System.Diagnostics.Process.Start(startInfo);
curl.WaitForExit();
System.Console.Out.Write(curl.StandardOutput.ReadToEnd());

}

``

I post the answer of your second question in a few moments.

curl responses.txt (15.1 KB)

The behavior is a little different when only one stream is queried :

My test is the same :

  • add some events to two streams

  • execute the query

  • soft delete the stream

  • add the same events

  • execute the same query

Results :

  • when fromstreams(s1, s2) is used : the second query stay “running” forever

  • when fromstream(s1) is used : the second query returns nothing

  • when fromstream(s1); fromstream(s2) : same “running forever” as fromstreams(s1, s2)

Regards,

Jérôme

UP

"- add the same events"

Just curious what you get in the stream browser. If they are the "same
events" its highly likely you are getting an idempotent write.

Well, in the stream browser, I got the same results than in curl.

  • The first events take the number 1,2,3,4 … => I can see in them in the browser

  • Then I soft delete the stream => the stream is empty in the browser

  • The the new same events take event number 5,6,7,8 …=> I can see them in the browser

Are the ids of the events the same if not they are not the same events
(they are new events that may happen to have the same payload).

- The the new same events take event number 5,6,7,8 ...=> I can see
them in the browser

And fromStream('foo') after gives you no results? I just tried this
and was unable to reproduce the behaviour.

Are the ids of the events the same if not they are not the same events

(they are new events that may happen to have the same payload).

True, sorry, so they are new events with the same payload than the “soft deleted” ones.

And fromStream(‘foo’) after gives you no results? I just tried this

and was unable to reproduce the behaviour.

I shortened the conditions for my previous test :

  • insert 1 event to a stream (let’s call it foo)

  • execute the query : fromStream(‘foo’) => a result

  • soft delete stream foo

  • insert 1 event (same payload, new id)

  • execute the query : fromStream(‘foo’) => no result

Up ?

Will try to reproduce.