-
Notifications
You must be signed in to change notification settings - Fork 907
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
Enable ZooKeeper client to establish connection in read-only mode #4244
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
massakam
force-pushed
the
allow-zk-ro-mode
branch
from
March 25, 2024 18:50
55dee7e
to
7ecf92b
Compare
hezhangjian
approved these changes
May 12, 2024
hezhangjian
requested review from
merlimat,
hangc0276,
jiazhai,
dlg99,
eolivelli,
zymap,
wenbingshen and
StevenLuMT
May 12, 2024 09:08
dlg99
approved these changes
May 30, 2024
hangc0276
approved these changes
Jul 8, 2024
massakam
force-pushed
the
allow-zk-ro-mode
branch
from
July 10, 2024 05:16
7ecf92b
to
26b8c9e
Compare
Ran |
@shoothzj @dlg99 @hangc0276 |
Ghatage
pushed a commit
to sijie/bookkeeper
that referenced
this pull request
Jul 12, 2024
…ache#4244) ### Motivation If the system property `readonlymode.enabled` is set to true on a ZooKeeper server, read-only mode is enabled. Data can be read from the server in read-only mode even if that server is split from the quorum. https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#Experimental+Options%2FFeatures To connect to the server in read-only mode, the client must also allow read-only mode. The `ZooKeeperClient` class in the bookkeeper repository also has an option called `allowReadOnlyMode`. https://github.com/apache/bookkeeper/blob/15171e1904f7196d8e9f4116ab2aecdf582e0032/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java#L219-L222 However, even if this option is set to true, the connection to the server in read-only mode will actually fail. The cause is in the `ZooKeeperWatcherBase` class. When the `ZooKeeperWatcherBase` class receives the `SyncConnected` event, it releases `clientConnectLatch` and assumes that the connection is complete. https://github.com/apache/bookkeeper/blob/15171e1904f7196d8e9f4116ab2aecdf582e0032/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperWatcherBase.java#L128-L144 However, if the server is in read-only mode, it will receive `ConnectedReadOnly` instead of `SyncConnected`. This causes the connection to time out without being completed. ### Changes Modified the switch statement in the `ZooKeeperWatcherBase` class to release `clientConnectLatch` when `ConnectedReadOnly` is received if the `allowReadOnlyMode` option is true. By the way, `allowReadOnlyMode` is never set to true in BookKeeper. So this change would be useless for BookKeeper. However, it is useful for Pulsar. Because Pulsar also uses `ZooKeeperWatcherBase` and needs to be able to connect to ZooKeeper in read-only mode. https://github.com/apache/pulsar/blob/cba1600d0f6a82f1ea194f3214a80f283fe8dc27/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/PulsarZooKeeperClient.java#L242-L244
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
If the system property
readonlymode.enabled
is set to true on a ZooKeeper server, read-only mode is enabled. Data can be read from the server in read-only mode even if that server is split from the quorum.https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#Experimental+Options%2FFeatures
To connect to the server in read-only mode, the client must also allow read-only mode. The
ZooKeeperClient
class in the bookkeeper repository also has an option calledallowReadOnlyMode
.bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
Lines 219 to 222 in 15171e1
However, even if this option is set to true, the connection to the server in read-only mode will actually fail. The cause is in the
ZooKeeperWatcherBase
class. When theZooKeeperWatcherBase
class receives theSyncConnected
event, it releasesclientConnectLatch
and assumes that the connection is complete.bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperWatcherBase.java
Lines 128 to 144 in 15171e1
However, if the server is in read-only mode, it will receive
ConnectedReadOnly
instead ofSyncConnected
. This causes the connection to time out without being completed.Changes
Modified the switch statement in the
ZooKeeperWatcherBase
class to releaseclientConnectLatch
whenConnectedReadOnly
is received if theallowReadOnlyMode
option is true.By the way,
allowReadOnlyMode
is never set to true in BookKeeper. So this change would be useless for BookKeeper. However, it is useful for Pulsar. Because Pulsar also usesZooKeeperWatcherBase
and needs to be able to connect to ZooKeeper in read-only mode.https://github.com/apache/pulsar/blob/cba1600d0f6a82f1ea194f3214a80f283fe8dc27/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/PulsarZooKeeperClient.java#L242-L244