-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove subsegments lock #278
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.amazonaws.xray.entities.Segment; | ||
import com.amazonaws.xray.entities.Subsegment; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DefaultStreamingStrategy implements StreamingStrategy { | ||
|
||
|
@@ -82,30 +83,18 @@ public boolean requiresStreaming(Segment segment) { | |
*/ | ||
@Override | ||
public void streamSome(Entity entity, Emitter emitter) { | ||
if (entity.getSubsegmentsLock().tryLock()) { | ||
try { | ||
stream(entity, emitter); | ||
} finally { | ||
entity.getSubsegmentsLock().unlock(); | ||
} | ||
} | ||
stream(entity, emitter); | ||
} | ||
|
||
private boolean stream(Entity entity, Emitter emitter) { | ||
ArrayList<Subsegment> children = new ArrayList<>(entity.getSubsegments()); | ||
ArrayList<Subsegment> streamable = new ArrayList<>(); | ||
List<Subsegment> children = entity.getSubsegmentsCopy(); | ||
List<Subsegment> streamable = new ArrayList<>(); | ||
|
||
//Gather children and in the condition they are ready to stream, add them to the streamable list. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think/fear a different race condition just moved 2 lines up now by removing the subsegmentLock. And you will hit #181 again. As the copy of Possible solutions I see:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for noticing this @steven-aerts - I've updated to return a copy |
||
if (children.size() > 0) { | ||
for (Subsegment child : children) { | ||
if (child.getSubsegmentsLock().tryLock()) { | ||
try { | ||
if (stream(child, emitter)) { | ||
streamable.add(child); | ||
} | ||
} finally { | ||
child.getSubsegmentsLock().unlock(); | ||
} | ||
if (stream(child, emitter)) { | ||
streamable.add(child); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return an
UnmodifiableCollection
of the subsegments list here? Or do we intentionally want to return a snapshot of the current subsegments at copying time that is not updated with new subsegments?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think it is more clear, but won't mind if the proposed behavior is kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wrapping the subsegments won't solve the thread safety possibility, it needs to be a copy. I could also wrap the copy with Unmodifiable but I don't think we really need to for copies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok fair enough, yeah I guess doing an
UnmodifiableCollection
would still allow the user to mutate the individual subsegments.