Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

mpsc_queue: allow interrupting try_consume_batch#1104

Merged
lukaszstolarczuk merged 1 commit intopmem:masterfrom
igchor:mpsc_queue_consume_interrupt
Jul 2, 2021
Merged

mpsc_queue: allow interrupting try_consume_batch#1104
lukaszstolarczuk merged 1 commit intopmem:masterfrom
igchor:mpsc_queue_consume_interrupt

Conversation

@igchor
Copy link
Copy Markdown
Contributor

@igchor igchor commented Jun 28, 2021

If interrupt (exception) happens, next try_consume_batch will
resume from the previous position.


This change is Reviewable

@igchor igchor requested a review from karczex June 28, 2021 12:11
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 28, 2021

Codecov Report

Merging #1104 (de6c200) into master (fd6e426) will increase coverage by 0.09%.
The diff coverage is 100.00%.

❗ Current head de6c200 differs from pull request most recent head 1f4030c. Consider uploading reports for the commit 1f4030c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1104      +/-   ##
==========================================
+ Coverage   94.14%   94.24%   +0.09%     
==========================================
  Files          51       51              
  Lines        5227     5247      +20     
==========================================
+ Hits         4921     4945      +24     
+ Misses        306      302       -4     
Flag Coverage Δ
tests_clang_debug_cpp17 93.81% <100.00%> (+0.10%) ⬆️
tests_gcc_debug 90.69% <88.23%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
include/libpmemobj++/experimental/mpsc_queue.hpp 94.47% <100.00%> (+0.65%) ⬆️
include/libpmemobj++/experimental/radix_tree.hpp 98.51% <0.00%> (+0.14%) ⬆️
...ude/libpmemobj++/container/concurrent_hash_map.hpp 94.20% <0.00%> (+0.15%) ⬆️
include/libpmemobj++/container/vector.hpp 92.95% <0.00%> (+0.33%) ⬆️
include/libpmemobj++/transaction.hpp 80.64% <0.00%> (+0.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd6e426...1f4030c. Read the comment docs.

Copy link
Copy Markdown
Member

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 5 files at r1.
Reviewable status: 3 of 5 files reviewed, 4 unresolved discussions (waiting on @igchor and @karczex)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 83 at r1 (raw file):

	pmem_log_type *pmem;

	static constexpr size_t consume_invalid =

what exactly these vars are storing...?


tests/CMakeLists.txt, line 973 at r1 (raw file):

	build_test(mpsc_queue_consume_interrupt mpsc_queue/consume_interrupt.cpp)
	add_test_generic(NAME mpsc_queue_consume_interrupt SCRIPT mpsc_queue/mpsc_queue_consume_interrupt_0.cmake TRACERS none memcheck pmemcheck)

_0 in script's name is redundant, I believe


tests/mpsc_queue/consume_interrupt.cpp, line 5 at r1 (raw file):

/*
 * basic.pp -- Single threaded tests for

wrong name and description 😉


tests/mpsc_queue/consume_interrupt.cpp, line 17 at r1 (raw file):

#include <libpmemobj++/make_persistent.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/string_view.hpp>

it seems redundant

@igchor igchor force-pushed the mpsc_queue_consume_interrupt branch from b424d97 to a615b52 Compare June 30, 2021 13:50
Copy link
Copy Markdown
Contributor Author

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 5 files reviewed, 4 unresolved discussions (waiting on @karczex and @lukaszstolarczuk)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 83 at r1 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

what exactly these vars are storing...?

Done.


tests/CMakeLists.txt, line 973 at r1 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

_0 in script's name is redundant, I believe

Done.


tests/mpsc_queue/consume_interrupt.cpp, line 5 at r1 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

wrong name and description 😉

Done.


tests/mpsc_queue/consume_interrupt.cpp, line 17 at r1 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

it seems redundant

Done.

@igchor igchor force-pushed the mpsc_queue_consume_interrupt branch from a615b52 to 7cb14ca Compare July 1, 2021 09:16
Copy link
Copy Markdown
Member

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @igchor and @karczex)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 87 at r2 (raw file):

	/* Stores offset and length of next message to be consumed. If
	 * The values are set to `consume_invalid` next message must be

the values (lowercase)

and what exactly did you mean by "if the values are set"?


include/libpmemobj++/experimental/mpsc_queue.hpp, line 88 at r2 (raw file):

	/* Stores offset and length of next message to be consumed. If
	 * The values are set to `consume_invalid` next message must be
	 * obtained from ringbug_consume. */

this ringbuf is bugged 😉 (ringbug)


tests/mpsc_queue/consume_interrupt.cpp, line 49 at r2 (raw file):

		UT_ASSERT(!ret);

		/* XXX: this is to make sure that try_consume_batch later in the

why is this an XXX ?

Copy link
Copy Markdown
Contributor Author

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @karczex and @lukaszstolarczuk)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 87 at r2 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

the values (lowercase)

and what exactly did you mean by "if the values are set"?

I mean if someone sets them to consume_invalid ;d I'm not sure how to reprehase it


include/libpmemobj++/experimental/mpsc_queue.hpp, line 88 at r2 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

this ringbuf is bugged 😉 (ringbug)

Done.


tests/mpsc_queue/consume_interrupt.cpp, line 49 at r2 (raw file):

Previously, lukaszstolarczuk (Łukasz Stolarczuk) wrote…

why is this an XXX ?

Because we want to eventually hide the wraparound behind the iterators. So try_consume_batch will call the callback only once.

@igchor igchor force-pushed the mpsc_queue_consume_interrupt branch from 7cb14ca to de6c200 Compare July 1, 2021 14:29
Copy link
Copy Markdown

@karczex karczex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 of 5 files reviewed, 4 unresolved discussions (waiting on @igchor and @lukaszstolarczuk)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 286 at r3 (raw file):

		 * try_consume_batch failed. In that case, call f() with the
		 * same offset/len as before. */
		if (consume_offset == consume_invalid) {

Wouldn't be better to add to ringbuff_t varialble which track state of the consume (as may be only one consumer, the change would be trivial)

bool consume_pending;

which you set at the beginning of ringbuf_consume and reset at the end of ringbuf_release.
And early return 0 from ringbuf_consume if previous one is pending.

So instead of this comparison to consume_invalid, you may check

if(ring_buffer->consume_pending) 

@igchor igchor force-pushed the mpsc_queue_consume_interrupt branch from de6c200 to 68aedfc Compare July 2, 2021 10:28
Copy link
Copy Markdown
Contributor Author

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 3 of 6 files reviewed, 4 unresolved discussions (waiting on @karczex and @lukaszstolarczuk)


include/libpmemobj++/experimental/mpsc_queue.hpp, line 286 at r3 (raw file):

Previously, karczex (Paweł Karczewski) wrote…

Wouldn't be better to add to ringbuff_t varialble which track state of the consume (as may be only one consumer, the change would be trivial)

bool consume_pending;

which you set at the beginning of ringbuf_consume and reset at the end of ringbuf_release.
And early return 0 from ringbuf_consume if previous one is pending.

So instead of this comparison to consume_invalid, you may check

if(ring_buffer->consume_pending) 

Done.

Copy link
Copy Markdown

@karczex karczex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 3 of 6 files reviewed, 3 unresolved discussions (waiting on @lukaszstolarczuk)

Copy link
Copy Markdown
Member

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 3 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @igchor)

If interrupt (exception) happens, next try_consume_batch will
resume from the previous position.
@igchor igchor force-pushed the mpsc_queue_consume_interrupt branch from 68aedfc to 1f4030c Compare July 2, 2021 11:40
Copy link
Copy Markdown
Member

@lukaszstolarczuk lukaszstolarczuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @igchor)

@lukaszstolarczuk lukaszstolarczuk merged commit 2a8e855 into pmem:master Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants