Save and restore error in ctf_fs_iterator_next, muxer_msg_iter_do_next
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 7 Nov 2019 22:27:27 +0000 (17:27 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 15 Nov 2019 18:07:38 +0000 (13:07 -0500)
commitcbca1c06c79966c7fb9fe5b08ccd9c95fa3620cc
treeb7d6998e8ff3f3dccd15c0a588da0542592984ff
parent7fb13d3fb818c75c3cc67f37ce846492dc628a69
Save and restore error in ctf_fs_iterator_next, muxer_msg_iter_do_next

ctf_fs_iterator_next and muxer_msg_iter_do_next are written in such a
way that if they successfully accumulate some messages, then hit an
error, they will return OK to make sure that those messages propagate
downstream in the graph, before the error stops the execution.  This
assumes that the subsequent call to _next will fail again.

This poses a problem: when it returns OK in this case, it also leaves
the current thread error set.  This is a postcondition breach.

One solution would be to simply clear the error in that case.  This
would still rely on some error (perhaps the same, perhaps not) to be hit
again  on the next _next call.   What I don't like with that solution is
that the behaviour of the iterator, if we call _next again after a
failure, is hard to predict.  We could hit the same error if we are
lucky, we could hit another error, we could hit an assertion because we
are in an unexpected state, etc.

Instead, this patch implements the following solution: return OK, but
take the error from the current thread and save it in the iterator.  The
next time _next is called, that error is moved back to the current
thread and the error status is returned.  This ensures that the error
the user will see is the one that originally caused the problem.

A test is added with a trace containing two valid events followed by an
invalid one.  We expect to see the two events printed by the details
sink, as well as the error about the invalid event class id.

Change-Id: I725f1de0e6fa0b430aa34bfc524811c5dcd80fa3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2353
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/fs.h
src/plugins/utils/muxer/muxer.c
tests/data/ctf-traces/fail/valid-events-then-invalid-events/README [new file with mode: 0644]
tests/data/ctf-traces/fail/valid-events-then-invalid-events/trace/dummystream [new file with mode: 0644]
tests/data/ctf-traces/fail/valid-events-then-invalid-events/trace/metadata [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/fail/valid-events-then-invalid-events.expect [new file with mode: 0644]
tests/plugins/src.ctf.fs/fail/test_fail
This page took 0.026056 seconds and 4 git commands to generate.