sandynz opened a new issue #15752:
URL: https://github.com/apache/shardingsphere/issues/15752
## Bug Report
### Which version of ShardingSphere did you use?
master branch, commit 54758fe13ef2d9e8255710e015abcbcaf13eb01e and
a69541e29a3f0f7cc8b0c95ab9479ac0bcd46818
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
In unit test.
### Expected behavior
`CuratorZookeeperRepository.get` return correct value, so
`GovernanceRepositoryAPIImplTest.assertRenewJobStatus` could pass.
### Actual behavior
If `GovernanceRepositoryAPIImplTest.assertWatch` is enabled, then
`GovernanceRepositoryAPIImplTest.assertRenewJobStatus` failed. Unit test output:
```
java.lang.AssertionError:
Expected: is <FINISHED>
but: was <RUNNING>
Expected :is <FINISHED>
Actual :<RUNNING>
<Click to see difference>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
at
org.apache.shardingsphere.data.pipeline.api.impl.GovernanceRepositoryAPIImplTest.assertRenewJobStatus(GovernanceRepositoryAPIImplTest.java:139)
```
### Reason analyze (If you can)
`CuratorZookeeperRepository.watch` will enable `CuratorCache`, seems
`CuratorZookeeperRepository.persist` doesn't update curator cache, when
`CuratorZookeeperRepository.get` it get value from curator cache and get old
value.
In commit 54758fe13ef2d9e8255710e015abcbcaf13eb01e
It try to persist status `FINISHED` and no exception thrown:
<img width="1356" alt="WX20220302-123511@2x"
src="https://user-images.githubusercontent.com/42492540/156306042-e17a2291-4968-429d-8c65-e7626e28e91e.png">
But when get value from `CuratorZookeeperRepository`, it get old value from
cache:
<img width="1329" alt="WX20220302-123859@2x"
src="https://user-images.githubusercontent.com/42492540/156306170-000e6f12-dd6e-41d1-a66c-8ecc9e91981e.png">
In commit a69541e29a3f0f7cc8b0c95ab9479ac0bcd46818,
`CuratorZookeeperRepository` has been refactored in
8f012fe4adff996fd796feec038d3837d4a704cc, but `CuratorZookeeperRepository.get`
still return wrong value and `assertRenewJobStatus` couldn't pass.
<img width="1210" alt="WX20220302-142610@2x"
src="https://user-images.githubusercontent.com/42492540/156308437-d671e18b-4d87-4cdd-8960-1449304ddd6d.png">
Seems `CuratorZookeeperRepository.persist` will update cache but with some
delay. I couldn't get the `CuratorZookeeperRepository.get` screenshot anymore,
but I could print log to verify it:
```
CuratorZookeeperRepository - get, key=/scaling/1198244117912739/offset/0,
value=
incremental:
ds_0:
delay:
lastEventTimestamps: 0
latestActiveTimeMillis: 0
position: ''
inventory:
unfinished:
ds_0.t_order#0: ''
sourceDatabaseType: H2
status: RUNNING
java.lang.AssertionError:
Expected: is <FINISHED>
but: was <RUNNING>
Expected :is <FINISHED>
Actual :<RUNNING>
<Click to see difference>
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
Enable `GovernanceRepositoryAPIImplTest.assertWatch` (it's commented for
now), run unit tests of `GovernanceRepositoryAPIImplTest` in IDE. If
`assertRenewJobStatus` run after `assertWatch`, then it could be reproduced.
### Example codes for reproduce this issue (such as a github link).
--
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]