Skip to content
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

Lock all accesses to entities. #250

Merged
merged 2 commits into from
Feb 4, 2021
Merged

Conversation

anuraaga
Copy link
Contributor

Issue #, if available: #108

Description of changes:
Almost none of the entity accesses are currently safe since there are many mutations of non-volatile fields. While making fields volatile is one way to help, modern CPUs have fast enough performance for non-contended locks (just atomic CAS) that it's common to just use locks (Golang makes it very hard to use volatile for this reason). This is the implementation OTel uses

https://github.com/open-telemetry/opentelemetry-java/blob/master/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/RecordEventsReadableSpan.java

OTel doesn't have setters for every single thing so doesn't need as much locking, but as we don't expect much contention here it should be fine.

I haven't quite reasoned through whether this fixes the subsegment issues, but it's an important change regardless.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

} finally {
getSubsegmentsLock().unlock();
synchronized (lock) {
getSubsegmentsLock().lock();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to lock the subsegments list when we're locking on the entire parent entity?

Copy link
Contributor

@willarmiros willarmiros left a comment

Choose a reason for hiding this comment

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

LGTM, we'll need to keep an eye on benchmarks before next release but shouldn't be a big deal. My guess is this should resolve #108 since the issue there was that during serialization, a subsegment could be removed from the entity being serialized. Since the serialize method and the methods to add/remove subsegments are controlled by the same lock now, it should be ok now. But can't be sure without reliable repro case/test.

@anuraaga anuraaga merged commit f0a3b3a into aws:master Feb 4, 2021
willarmiros pushed a commit to willarmiros/aws-xray-sdk-java that referenced this pull request Aug 13, 2022
wangzlei pushed a commit that referenced this pull request Aug 22, 2022
* Revert "Don't lock segment from subsegment (#306)"

This reverts commit d5ccae2.

* Revert "Keep track of emitted in emitter. (#279)"

This reverts commit d66d69a.

* Revert "Remove subsegments lock (#278)"

This reverts commit adfb395.

* Revert "Lock all accesses to entities. (#250)"

This reverts commit f0a3b3a.

* add back errorprone annotations

* fixed shouldPropagate

* added back getSubsegmentsCopy

* added back compareAndSetEmitted

* whitespace fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants