You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/08/02 02:13:13 UTC

[GitHub] [pulsar] mattisonchao opened a new pull request, #16910: Avoid using `ArrayList` in the concurrent environment.

mattisonchao opened a new pull request, #16910:
URL: https://github.com/apache/pulsar/pull/16910

   ### Motivation
   
   Relate issue: #16909 
   
   https://github.com/apache/pulsar/blob/3f109d6cb7f128a5f8331e33477fd69c3c26d531/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L1375-L1442
   
   We have to avoid using `ArrayList` in the concurrent environment.
   
   ### Modifications
   
   - Use `synchronizedList` to instead of `ArrayList`
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   ### Documentation
   
   - [x] `doc-not-needed` 
   (Please explain why)
     


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on pull request #16910: [fix][broker] Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#issuecomment-1201973755

   Sorry, I missed the `synchronized` in the callback.


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] shibd commented on a diff in pull request #16910: Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
shibd commented on code in PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#discussion_r935070634


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   Why local variables need care about concurrency?



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #16910: Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#discussion_r935071389


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   We will invoke the `entries.add` method at callback in the different threads. ( If we need to read entries from the different ledger.)



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #16910: Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#discussion_r935071389


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   We will invoke the `entries.add` method at callback in the different thread.



##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   We will invoke the `entries.add` method at callback in the different threads.



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on pull request #16910: [fix][broker] Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
tisonkun commented on PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#issuecomment-1201970152

   I think the issue here can be that the caller calls `readEntryComplete` with `null` parameter.
   
   IIRC bookkeeper handles callbacks one by one so it may not in a concurrent context.


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao closed pull request #16910: [fix][broker] Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
mattisonchao closed pull request #16910: [fix][broker] Avoid using `ArrayList` in the concurrent environment.
URL: https://github.com/apache/pulsar/pull/16910


-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] mattisonchao commented on a diff in pull request #16910: Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
mattisonchao commented on code in PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#discussion_r935071389


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   We will invoke `entries.add` method at callback in different thread.



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] shibd commented on a diff in pull request #16910: Avoid using `ArrayList` in the concurrent environment.

Posted by GitBox <gi...@apache.org>.
shibd commented on code in PR #16910:
URL: https://github.com/apache/pulsar/pull/16910#discussion_r935070634


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1347,7 +1347,7 @@ public Set<? extends Position> asyncReplayEntries(final Set<? extends Position>
     @Override
     public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positions,
             ReadEntriesCallback callback, Object ctx, boolean sortEntries) {
-        List<Entry> entries = Lists.newArrayListWithExpectedSize(positions.size());
+        List<Entry> entries = Collections.synchronizedList(new ArrayList<>(positions.size()));

Review Comment:
   Why should local variables care about concurrency?



-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org