Skip to content

Make netty 4.0 attributes definition compatible with Apache Atlas 1.1.0 - #906

Merged
labbati merged 15 commits into
masterfrom
labbati/atlas-1.1.0-compatibility
Aug 2, 2019
Merged

labbati merged 15 commits into
masterfrom
labbati/atlas-1.1.0-compatibility

Conversation

@labbati

@labbati labbati commented Jul 5, 2019

Copy link
Copy Markdown
Member

The issue we are trying to fix here seems to be a result of two concurrent issues.

Cassandra driver's used by atlas 1.1.0 brings in a old version of netty < 4.0.23.

In version 4.0.25 netty raised exception in UniqueName class for duplicate name

if (map.putIfAbsent(name, Boolean.TRUE) != null) {
            throw new IllegalArgumentException(String.format("'%s' is already in use", name));
        }

This changed in 4.0.26 where exception was not thrown, instead the duplicate key was just ignored.

    protected UniqueName(String name) {
        this.name = checkNotNull(name, "name");
        id = nextId.incrementAndGet();
    }

Now this alone would not be enough. The only way I was able to reproduce is if two different class loaders tries to load the
same class AttributeKeys twice.
I tried to look into Atlas source code (which is huge) and I could not find a clear path of how this would be possible.

Further more, looking at some build scripts that a user experiencing this issue provided,
it looks like they are doing everything correctly and there is nothing they should change.

In conclusion, I believe that even if this is not a very clean approach,
we should be resilient to this use case, when a customer using netty <4.0.25 in an
older version of Apache Atlas (or with some sort of class loader behavior).

labbati added 3 commits July 16, 2019 11:02
The issue we are trying to fix here seems to be a result of two concurrent issues.

Cassandra driver's used by atlas 1.1.0 brings in a old version of netty < 4.0.23.

In version 4.0.25 netty raised exception in `UniqueName` class for duplicate name

```
if (map.putIfAbsent(name, Boolean.TRUE) != null) {
            throw new IllegalArgumentException(String.format("'%s' is already in use", name));
        }
```

This changed in 4.0.26 where exception was not thrown, instead the duplicate key was just ignored.

```
    protected UniqueName(String name) {
        this.name = checkNotNull(name, "name");
        id = nextId.incrementAndGet();
    }
```

Now this alone would not be enough. The only way I was able to reproduce is if two different class loaders tries to load the
same class `AttributeKeys` twice.
I tried to look into Atlas source code (which is huge) and I could not find a clear path of how this would be possible.

Further more, looking at some build scripts that a user experiencing this issue provided,
it looks like they are doing everything correctly and there is nothing they should change.

In conclusion, I believe that even if this is not a very clean approach,
we should be resilient to this use case, when a customer using netty <4.0.25 in an
older version of Apache Atlas (or with some sort of class loader behavior).
@labbati
labbati force-pushed the labbati/atlas-1.1.0-compatibility branch from be8bf24 to bfa5712 Compare July 16, 2019 09:40
@labbati
labbati marked this pull request as ready for review July 19, 2019 14:31
@labbati
labbati requested a review from a team as a code owner July 19, 2019 14:31
@labbati
labbati requested review from mar-kolya and tylerbenson July 19, 2019 16:15

@tylerbenson tylerbenson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couple of small things... Consider adding the double-check locking.

@Override
public V getOrCreate(K key, ValueSupplier<V> supplier) {
if (!map.containsKey(key)) {
map.put(key, supplier.get());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider adding "double check locking" here to ensure thread safety.

* prevents an issue with Apache Atlas project were this class loaded by multiple class loaders,
* while the Attribute class is loaded by a third class loader and used internally for the
* cassandra driver.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want/need a similar change in the netty 4.0 instrumentation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think you are referring to 4.1. I think this issue is very specific to the usage that Apache Atlas does of the class loaders + netty. We can do that as a safety net though, as I do not see any disadvantage, so good call.

def "getOrCreate a value"() {
setup:
def supplier = new CounterSupplier()
def sut = new WeakMap.MapAdapter<String, Integer>(new WeakHashMap<>())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These could be moved to class fields instead of having to duplicate for each test. (Unless marked as @Shared, Spock will reinitialize before each test.)

@Override
public synchronized V getOrCreate(K key, ValueSupplier<V> supplier) {
if (!map.containsKey(key)) {
map.put(key, supplier.get());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trade synchronized for double check locking here instead.

@tylerbenson

Copy link
Copy Markdown
Contributor

Looks like there's a conflict with master and the tests are failing. Once those are fixed, good to merge.

@labbati

labbati commented Jul 26, 2019

Copy link
Copy Markdown
Member Author

Merge conflict resolved and added new style definition for new property in AttributeKeys.

@labbati
labbati merged commit 097c818 into master Aug 2, 2019
@tylerbenson
tylerbenson deleted the labbati/atlas-1.1.0-compatibility branch August 8, 2019 16:13
@tylerbenson tylerbenson added this to the 0.32.0 milestone Aug 30, 2019
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.

2 participants