Refactor to use setOnce #7
Conversation
080a501 to
f01a4ff
Compare
| * Subscribes for the first cluster state update where nodeId and clusterId is set. | ||
| */ | ||
| public static void subscribeTo(ClusterStateObserver observer) { | ||
| observer.waitForNextChange(new NodeAndClusterIdStateListener(), NodeAndClusterIdStateListener::nodeIdAndClusterIdSet); |
There was a problem hiding this comment.
should this have a timeout?
There was a problem hiding this comment.
I think it's ok not to specify a timeout here.
| observer.waitForNextChange(new NodeAndClusterIdStateListener(), NodeAndClusterIdStateListener::nodeIdAndClusterIdSet); | ||
| } | ||
|
|
||
| private static boolean nodeIdAndClusterIdSet(ClusterState clusterState) { |
There was a problem hiding this comment.
"set" here threw me off at first (sounds like a setter). Maybe have this be more a boolean name, like "isNodeAndClusterIdReady"?
There was a problem hiding this comment.
maybe isNodeAndClusterIdPresent ?
| */ | ||
| public static boolean setOnce(String nodeId, String clusterUUID) { | ||
| return nodeAndClusterId.compareAndSet(null, formatIds(clusterUUID, nodeId)); | ||
| public static void setOnce(String nodeId, String clusterUUID) { |
There was a problem hiding this comment.
I still dont' like this being "setOnce", I think it should be parallel to the node name listener?
There was a problem hiding this comment.
as this is almost the same as NodeNameConverter I think you are right this method should be name in similar manner. Will rename to setNodeIdAndClusterId
| throw new ElasticsearchTimeoutException("Interrupted while waiting for initial discovery state"); | ||
| } | ||
|
|
||
| NodeAndClusterIdStateListener.subscribeTo(observer); |
There was a problem hiding this comment.
The name subscribeTo looks odd here, since this is a one time use. Perhaps the name should reflect that, like "getAndSetClusterIds"?
There was a problem hiding this comment.
Also, note that this is inside a block which will not run if the join has already happened. I think this needs to be moved outside this block.
danielmitterdorfer
left a comment
There was a problem hiding this comment.
Makes sense in general. I left a few minor comments
| logger.debug("Received first cluster state update. Setting nodeId=[{}] and clusterUuid=[{}]", nodeId, clusterUUID); | ||
| } | ||
| NodeAndClusterIdConverter.setOnce(nodeId, clusterUUID); | ||
| logger.debug("Received first cluster state update. Setting nodeId=[{}] and clusterUuid=[{}]", nodeId, clusterUUID); |
There was a problem hiding this comment.
I'd prefer to move this up before we set it because this statement is never executed if there is a second attempt and we're failing. If it is one line up it would provide at least some ability to see what's going on.
There was a problem hiding this comment.
good pint. will remove the first word too
| /** | ||
| * Updates only once the clusterID and nodeId | ||
| * Updates only once the clusterID and nodeId. | ||
| * Note: Should only be called once. Subsequent executions will throw {@link org.apache.lucene.util.SetOnce.AlreadySetException}. |
There was a problem hiding this comment.
Nit: Scratch "Note: Should only be called once."?
There was a problem hiding this comment.
right, the previous line should make it clear that it should only be called once
| * Subscribes for the first cluster state update where nodeId and clusterId is set. | ||
| */ | ||
| public static void subscribeTo(ClusterStateObserver observer) { | ||
| observer.waitForNextChange(new NodeAndClusterIdStateListener(), NodeAndClusterIdStateListener::nodeIdAndClusterIdSet); |
There was a problem hiding this comment.
I think it's ok not to specify a timeout here.
…astic#69765) Previously we did not resolve the attributes recursively which meant that if a field or expression was re-aliased multiple times (through multiple levels of subqueries), the aliases were only resolved one level down. This led to failed query translation because `ReferenceAttribute`s were pointing to non-existing attributes during query translation. For example the query ```sql SELECT i AS j FROM ( SELECT int AS i FROM test) ORDER BY j ``` failed during translation because the `OrderBy` resolved the `j` ReferenceAttribute to another `i` ReferenceAttribute that was later removed by an Optimization: ``` OrderBy[[Order[j{r}#4,ASC,LAST]]] ! OrderBy[[Order[i{r}#2,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` By resolving the `Attributes` recursively both `j{r}` and `i{r}` will resolve to `test.int{f}` above: ``` OrderBy[[Order[test.int{f}#22,ASC,LAST]]] = OrderBy[[Order[test.int{f}#22,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` The scope of recursive resolution depends on how the `AttributeMap` is constructed and populated. Fixes elastic#67237
…astic#69765) (elastic#70322) Previously we did not resolve the attributes recursively which meant that if a field or expression was re-aliased multiple times (through multiple levels of subqueries), the aliases were only resolved one level down. This led to failed query translation because `ReferenceAttribute`s were pointing to non-existing attributes during query translation. For example the query ```sql SELECT i AS j FROM ( SELECT int AS i FROM test) ORDER BY j ``` failed during translation because the `OrderBy` resolved the `j` ReferenceAttribute to another `i` ReferenceAttribute that was later removed by an Optimization: ``` OrderBy[[Order[j{r}#4,ASC,LAST]]] ! OrderBy[[Order[i{r}#2,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` By resolving the `Attributes` recursively both `j{r}` and `i{r}` will resolve to `test.int{f}` above: ``` OrderBy[[Order[test.int{f}#22,ASC,LAST]]] = OrderBy[[Order[test.int{f}#22,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` The scope of recursive resolution depends on how the `AttributeMap` is constructed and populated. Fixes elastic#67237
…astic#69765) (elastic#70325) Previously we did not resolve the attributes recursively which meant that if a field or expression was re-aliased multiple times (through multiple levels of subqueries), the aliases were only resolved one level down. This led to failed query translation because `ReferenceAttribute`s were pointing to non-existing attributes during query translation. For example the query ```sql SELECT i AS j FROM ( SELECT int AS i FROM test) ORDER BY j ``` failed during translation because the `OrderBy` resolved the `j` ReferenceAttribute to another `i` ReferenceAttribute that was later removed by an Optimization: ``` OrderBy[[Order[j{r}#4,ASC,LAST]]] ! OrderBy[[Order[i{r}#2,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` By resolving the `Attributes` recursively both `j{r}` and `i{r}` will resolve to `test.int{f}` above: ``` OrderBy[[Order[test.int{f}#22,ASC,LAST]]] = OrderBy[[Order[test.int{f}#22,ASC,LAST]]] \_Project[[j]] = \_Project[[j]] \_Project[[i]] ! \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] \_EsRelation[test][date{f}#6, some{f}#7, some.string{f}#8, some.string..] ! ``` The scope of recursive resolution depends on how the `AttributeMap` is constructed and populated. Fixes elastic#67237
…pare_more Spacetime transactions prepare more
gradle check?