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)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Nov 2019 21:10:12 +0000 (16:10 -0500)
commit44381faea7fa26bf9411c67d7efa201523c8c11f
treebd739c3c9ab7c6b0b69cbd484cc2906e5fe14dfe
parentf331468c193c14544df578174185b01af900abcf
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.025049 seconds and 4 git commands to generate.