You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "GWphua (via GitHub)" <gi...@apache.org> on 2025/09/03 03:28:02 UTC
[PR] Concurrent linked queue for writes (druid)
GWphua opened a new pull request, #18470:
URL: https://github.com/apache/druid/pull/18470
### Description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
#### Optimized data structure for heavy writes.
The ConcurrentLinkedQueue features a O(1) write time, as opposed to the O(N) write time for CopyOnWriteArrayList.
Not an impactful performance increase, given the `failedSegments` array should be as small as possible, but caught this while trying to optimize other stuff in `SegmentBootstrapper`.
#### Release note
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
Optimize concurrent writing to failedSegments array when loading segment on startup.
<hr>
##### Key changed/added classes in this PR
* `SegmentBootstrapper`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [x] been self-reviewed.
- [x] a release note entry in the PR description.
- [] been tested in a test Druid cluster. (Pending)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "GWphua (via GitHub)" <gi...@apache.org>.
GWphua commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2319514696
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
> By the way, why would it get converted to an array list in this line?
Ah my bad, oversight on my part. 😂
It simply puts the `failedSegments` into a `LinkedHashMap`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "GWphua (via GitHub)" <gi...@apache.org>.
GWphua commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2317703085
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
> Given that only ever add to this list,
`failSegments` will also get converted to a ArrayList subsequently in here.
```
log.makeAlert("[%,d] errors seen while loading segments on startup", failedSegments.size())
.addData("failedSegments", failedSegments)
.emit();
```
Honestly, not an issue too. I'm ambivalent about both options.
Would we prefer working with a HashSet here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "GWphua (via GitHub)" <gi...@apache.org>.
GWphua commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2319514696
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
Ah my bad, oversight on my part. 😂
It simply puts the `failedSegments` into a `LinkedHashMap`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2318707256
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
Yeah, I am okay either way too. Just wanted to understand if it is really required to be thread safe.
By the way, why would it get converted to an array list in this line?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2317676230
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
Given that only ever add to this list, I wonder if it couldn't just be a `HashSet`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #18470:
URL: https://github.com/apache/druid/pull/18470#discussion_r2318707256
##########
server/src/main/java/org/apache/druid/server/coordination/SegmentBootstrapper.java:
##########
@@ -195,7 +195,7 @@ private void loadSegmentsOnStartup() throws IOException
final int numSegments = segmentsOnStartup.size();
final CountDownLatch latch = new CountDownLatch(numSegments);
final AtomicInteger counter = new AtomicInteger(0);
- final CopyOnWriteArrayList<DataSegment> failedSegments = new CopyOnWriteArrayList<>();
+ final ConcurrentLinkedQueue<DataSegment> failedSegments = new ConcurrentLinkedQueue<>();
Review Comment:
Yeah, I am okay either way. Just wanted to understand if it is really required to be thread safe.
By the way, why would it get converted to an array list in this line?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Concurrent linked queue for writes (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #18470:
URL: https://github.com/apache/druid/pull/18470
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org