Commit ddec811
authored
KAFKA-19937: Introduced Shared ReaperThread for Persister / NetworkPartitionMetadataClient (#21842)
### Description
This pull request addresses the redundant thread usage detailed in
[KAFKA-19937](https://issues.apache.org/jira/browse/KAFKA-19937)
affecting the `PersisterStateManager` and
`NetworkPartitionMetadataClient` classes specifically. Presently each
creates/manages its own separate `SystemTimerReaper` instances, but rely
on identical timers with independent tasks. The changes proposed address
this by introducing a new, sharable instance of the thread to reduce
overhead.
### Key Changes
- Updated `BrokerServer` to create a single shared `SystemTimerReaper`
instance used by both `PersisterStateManager` and
`NetworkPartitionMetadataClient`, with cleanup in the shutdown path
after both components have been stopped.
- Moved timer ownership to the caller for the affected classes to the
caller (e.g., `PersisterStateManager.stop()` and
`NetworkPartitionMetadataClient.close()` no longer close their injected
timer, as lifecycle is managed by `BrokerServer`).
- This specific timer ownership behavior is documented via JavaDocs
for both `PersisterStateManager` and `NetworkPartitionMetadataClient`
- Added null validation to the `SystemTimerReaper` constructor
arguments.
### Tests and Verification
Verified that all existing test suites still pass as expected and added
the following to verify new behavior and usage related to the above
changes:
- Extended `SystemTimerReaperTest.java` to verify null validity and
timer-sharing behavior (e.g., two consumers sharing a timer can both
schedule and expire tasks independently).
- Updated `PersisterStateManagerTest.java` to verify that `stop()` does
not close the timer, consistent with the new caller-ownership contract.
### Reviewer(s)
Tagging @AndrewJSchofield (initial reporter)
Reviewers: Sushant Mahajan <smahajan@confluent.io>, Andrew Schofield
<aschofield@confluent.io>1 parent eef6cab commit ddec811
6 files changed
Lines changed: 61 additions & 13 deletions
File tree
- core/src/main/scala/kafka/server
- server-common/src
- main/java/org/apache/kafka/server
- util/timer
- test/java/org/apache/kafka/server
- util/timer
- server/src/main/java/org/apache/kafka/server/util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
| |||
381 | 383 | | |
382 | 384 | | |
383 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
384 | 389 | | |
385 | 390 | | |
386 | 391 | | |
| |||
655 | 660 | | |
656 | 661 | | |
657 | 662 | | |
658 | | - | |
| 663 | + | |
659 | 664 | | |
660 | 665 | | |
661 | 666 | | |
| |||
734 | 739 | | |
735 | 740 | | |
736 | 741 | | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
| 742 | + | |
741 | 743 | | |
742 | 744 | | |
743 | 745 | | |
| |||
887 | 889 | | |
888 | 890 | | |
889 | 891 | | |
| 892 | + | |
| 893 | + | |
890 | 894 | | |
891 | 895 | | |
892 | 896 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| |||
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
| |||
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
169 | | - | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
48 | | - | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
server-common/src/test/java/org/apache/kafka/server/share/persister/PersisterStateManagerTest.java
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4827 | 4827 | | |
4828 | 4828 | | |
4829 | 4829 | | |
4830 | | - | |
| 4830 | + | |
| 4831 | + | |
4831 | 4832 | | |
4832 | 4833 | | |
4833 | 4834 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
70 | 101 | | |
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
152 | | - | |
153 | 158 | | |
154 | 159 | | |
155 | 160 | | |
| |||
0 commit comments