LantaoJin opened a new pull request, #5348:
URL: https://github.com/apache/calcite/pull/5348

   ## Jira Link
   
   [CALCITE-7872](https://issues.apache.org/jira/browse/CALCITE-7872)
   
   ## Changes Proposed
   <!--
   Please clarify what changes you are proposing. The purpose of this section 
is to outline the changes and how this PR fixes the issue.
   If possible, please consider writing useful notes for better and faster 
reviews in your PR.
   -->
   
   The static initializer of `RelCollations` creates `RelCollationImpl` 
instances. The static initializer of `RelCollationImpl` reads 
`RelCollations.EMPTY` and `RelCollations.PRESERVE` for its deprecated aliases. 
So two threads that initialize the two classes at the same time can deadlock. 
This made a full `:core:test` run hang when `CollationConversionTest` and 
`TraitPropagationTest` were initialized at the same time. Also, if 
`RelCollations` is initialized first, which is the usual order, the two 
constants are copied while they are still null. So `RelCollationImpl.EMPTY` and 
`RelCollationImpl.PRESERVE` are `null`.
   
   Changes:
   
   - `RelCollationImpl` creates its own `EMPTY` and `PRESERVE`, canonized 
through `RelCollationTraitDef`, so `RelCollations.EMPTY` is the same object. 
Its constructor checks that fields are distinct without calling 
`RelCollations.ordinals`. After this change, initializing `RelCollationImpl` 
never needs `RelCollations`.
   - `RelCollations.PRESERVE` (deprecated) now refers to 
`RelCollationImpl.PRESERVE`, and still prints `PRESERVE`. No public API is 
added or removed.
   - `RelCollationTest` has two new tests. Each test loads its own copy of the 
Calcite classes through a child-first class loader, so both classes start 
uninitialized. One test initializes the classes in both orders and checks that 
the constants are non-null and identical. The other test initializes the two 
classes from two threads at the same time. Before the fix, the first test fails 
with `was null` and the second fails with `TimeoutException`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to