-
Notifications
You must be signed in to change notification settings - Fork 39
Move metadata internal API to use List instead of Set as replicas store #446
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
Move metadata internal API to use List instead of Set as replicas store #446
Conversation
d9b71c9 to
e88f84e
Compare
e88f84e to
f284924
Compare
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.
Added few comments to consider. I did not thoroughly check not highlighted parts of the code. One thing to look out for would be any calls to methods like contains. Since they are basically the same for sets and lists they are not highlighted as change. With lists they will be linear now, which may introduce unwanted overhead.
I get a feeling that we're moving instantiations deeper into the code instead of making a List copy later, which probably does not bring much benefit
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
35b1528 to
50c1b05
Compare
f4f5e1c to
5070eba
Compare
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.
I think TokenAwarePolicy has a typo introducing a bug, added a comment.
Metadata#getReplicas(String keyspace, TokenRange range) now creates a new HashSet copy rather than return directly.
Metadata#getReplicas(String keyspace, Token token) now returns a copy too
TokenAwarePolicy#newQueryPlan(final String loggedKeyspace, final Statement) Looks like for token map does a copy and for tablet map does not. Previously it would make a copy for both cases so this is partial improvement.
Overall net -1 collection creations for tablet map but +1 for token map (plus O(1) instanceof check for both) when we call newQueryPlan. For other policies it should be net 0 or +1 in that case.
If we don't care as much about token map performance then this is maybe an ok sacrifice to make.
edit: newQueryPlan does not call those getReplicas so this calculation was wrong. New instantiations affect only users of those specific APIs.
It would also be good to update the javadocs to mention where methods return a shallow copy and where not. Previously they would return underlying token maps collections.
driver-core/src/main/java/com/datastax/driver/core/TabletMap.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
e6673a9 to
eeaaac3
Compare
I don't think that it makes sense, it is only confuse API user, let's just state that you are not suppose to write to it, which we alredy do. getReplicas - marked as depricated in favor of getReplicasList it is not used in the driver internals, only tests. |
eeaaac3 to
ccf8d18
Compare
You're right, this is actually not on the path to newQueryPlan, so this does not impact it. It uses |
|
@Bouncheck , please check on it. |
Bouncheck
left a comment
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.
See comments
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java
Outdated
Show resolved
Hide resolved
6204b05 to
43e5291
Compare
All adressed |
Bouncheck
left a comment
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.
Generally LGTM, although this does not avoid converting into ArrayList in the end, which i thought was the purpose.
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
driver-core/src/main/java/com/datastax/driver/core/Metadata.java
Outdated
Show resolved
Hide resolved
In almost all use cases replicas are getting converted into a List. To make performance better make these API provide List instead.
43e5291 to
54f9276
Compare
Thanks, it will be addressed in another PR after we introduce bench tests |
In almost all use cases replicas are getting converted into a List.
To make performance better make these API provide List instead.