Package org.apache.flink.runtime.util
Class ZooKeeperUtils
java.lang.Object
org.apache.flink.runtime.util.ZooKeeperUtils
Class containing helper functions to interact with ZooKeeper.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSecureACLProviderimplementation.static enumZooKeeper client ACL mode enum. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ZooKeeperCheckpointIDCountercreateCheckpointIDCounter(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aZooKeeperCheckpointIDCounterinstance.static CompletedCheckpointStorecreateCompletedCheckpoints(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, org.apache.flink.configuration.Configuration configuration, int maxNumberOfCheckpointsToRetain, SharedStateRegistryFactory sharedStateRegistryFactory, Executor ioExecutor, Executor executor, org.apache.flink.core.execution.RecoveryClaimMode recoveryClaimMode) Creates aDefaultCompletedCheckpointStoreinstance withZooKeeperStateHandleStore.static ExecutionPlanStorecreateExecutionPlans(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, org.apache.flink.configuration.Configuration configuration) Creates aDefaultExecutionPlanStoreinstance withZooKeeperStateHandleStore,ZooKeeperExecutionPlanStoreWatcherandZooKeeperExecutionPlanStoreUtil.static <T extends Serializable>
FileSystemStateStorageHelper<T>createFileSystemStateStorage(org.apache.flink.configuration.Configuration configuration, String prefix) Creates aFileSystemStateStorageHelperinstance.createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, org.apache.flink.configuration.Configuration configuration) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.createLeaderRetrievalService(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aDefaultLeaderRetrievalServiceinstance withZooKeeperLeaderRetrievalDriver.createLeaderRetrievalService(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, org.apache.flink.configuration.Configuration configuration) Creates aDefaultLeaderRetrievalServiceinstance withZooKeeperLeaderRetrievalDriver.static org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCachecreateTreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String pathToNode, org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheSelector selector) static org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCachecreateTreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String pathToNode, org.apache.flink.util.function.RunnableWithException nodeChangeCallback) Creates aTreeCachethat only observes a specific node.static <T extends Serializable>
ZooKeeperStateHandleStore<T>createZooKeeperStateHandleStore(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, RetrievableStateStorageHelper<T> stateStorage) Creates an instance ofZooKeeperStateHandleStore.static voiddeleteZNode(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework curatorFramework, String path) static Stringstatic Stringstatic StringgenerateZookeeperPath(String... paths) Creates a ZooKeeper path of the form "/a/b/...static Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic StringgetLeaderPath(String suffix) static StringgetLeaderPathForJob(org.apache.flink.api.common.JobID jobId) static StringgetPathForJob(org.apache.flink.api.common.JobID jobId) Returns the JobID as a String (with leading slash).static Stringstatic Stringstatic StringgetZooKeeperEnsemble(org.apache.flink.configuration.Configuration flinkConf) Returns the configured ZooKeeper quorum (and removes whitespace, because ZooKeeper does not tolerate it).static booleanisConnectionInfoPath(String path) static booleanisZooKeeperRecoveryMode(org.apache.flink.configuration.Configuration flinkConf) Returns whetherHighAvailabilityMode.ZOOKEEPERis configured.static LeaderInformationreadLeaderInformation(byte[] data) static String[]splitZooKeeperPath(String path) Splits the given ZooKeeper path into its parts.startCuratorFramework(org.apache.flink.configuration.Configuration configuration, org.apache.flink.runtime.rpc.FatalErrorHandler fatalErrorHandler) Starts aCuratorFrameworkinstance and connects it to the given ZooKeeper quorum.startCuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory.Builder builder, org.apache.flink.runtime.rpc.FatalErrorHandler fatalErrorHandler) Starts aCuratorFrameworkinstance and connects it to the given ZooKeeper quorum from a builder.static StringtrimStartingSlash(String path) static org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkuseNamespaceAndEnsurePath(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path) Returns a facade of the client that uses the specified namespace, and ensures that all nodes in the path exist.static voidwriteLeaderInformationToZooKeeper(LeaderInformation leaderInformation, org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework curatorFramework, BooleanSupplier hasLeadershipCheck, String connectionInformationPath)
-
Field Details
-
HA_STORAGE_SUBMITTED_EXECUTION_PLAN_PREFIX
The prefix of the submitted job graph file.- See Also:
-
HA_STORAGE_COMPLETED_CHECKPOINT
The prefix of the completed checkpoint file.- See Also:
-
RESOURCE_MANAGER_NODE
The prefix of the resource manager node.- See Also:
-
-
Method Details
-
getLeaderPathForJob
-
getJobsPath
-
getCheckpointIdCounterPath
-
getLeaderPath
-
getDispatcherNode
-
getResourceManagerNode
-
getRestServerNode
-
getLeaderLatchPath
-
getLeaderPath
-
generateConnectionInformationPath
-
isConnectionInfoPath
-
generateLeaderLatchPath
-
startCuratorFramework
public static CuratorFrameworkWithUnhandledErrorListener startCuratorFramework(org.apache.flink.configuration.Configuration configuration, org.apache.flink.runtime.rpc.FatalErrorHandler fatalErrorHandler) Starts aCuratorFrameworkinstance and connects it to the given ZooKeeper quorum.- Parameters:
configuration-Configurationobject containing the configuration valuesfatalErrorHandler-FatalErrorHandlerfatalErrorHandler to handle unexpected errors ofCuratorFramework- Returns:
CuratorFrameworkWithUnhandledErrorListenerinstance
-
startCuratorFramework
@VisibleForTesting public static CuratorFrameworkWithUnhandledErrorListener startCuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory.Builder builder, org.apache.flink.runtime.rpc.FatalErrorHandler fatalErrorHandler) Starts aCuratorFrameworkinstance and connects it to the given ZooKeeper quorum from a builder.- Parameters:
builder-CuratorFrameworkFactory.BuilderA builder for curatorFramework.fatalErrorHandler-FatalErrorHandlerfatalErrorHandler to handle unexpected errors ofCuratorFramework- Returns:
CuratorFrameworkWithUnhandledErrorListenerinstance
-
isZooKeeperRecoveryMode
public static boolean isZooKeeperRecoveryMode(org.apache.flink.configuration.Configuration flinkConf) Returns whetherHighAvailabilityMode.ZOOKEEPERis configured. -
getZooKeeperEnsemble
public static String getZooKeeperEnsemble(org.apache.flink.configuration.Configuration flinkConf) throws org.apache.flink.configuration.IllegalConfigurationException Returns the configured ZooKeeper quorum (and removes whitespace, because ZooKeeper does not tolerate it).- Throws:
org.apache.flink.configuration.IllegalConfigurationException
-
createLeaderRetrievalService
public static DefaultLeaderRetrievalService createLeaderRetrievalService(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aDefaultLeaderRetrievalServiceinstance withZooKeeperLeaderRetrievalDriver.- Parameters:
client- TheCuratorFrameworkZooKeeper client to use- Returns:
DefaultLeaderRetrievalServiceinstance.
-
createLeaderRetrievalService
public static DefaultLeaderRetrievalService createLeaderRetrievalService(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, org.apache.flink.configuration.Configuration configuration) Creates aDefaultLeaderRetrievalServiceinstance withZooKeeperLeaderRetrievalDriver.- Parameters:
client- TheCuratorFrameworkZooKeeper client to usepath- The path for the leader retrievalconfiguration- configuration for further config options- Returns:
DefaultLeaderRetrievalServiceinstance.
-
createLeaderRetrievalDriverFactory
public static ZooKeeperLeaderRetrievalDriverFactory createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.- Parameters:
client- TheCuratorFrameworkZooKeeper client to use- Returns:
LeaderRetrievalDriverFactoryinstance.
-
createLeaderRetrievalDriverFactory
public static ZooKeeperLeaderRetrievalDriverFactory createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.- Parameters:
client- TheCuratorFrameworkZooKeeper client to usepath- The parent path that shall be used by the client.- Returns:
LeaderRetrievalDriverFactoryinstance.
-
createLeaderRetrievalDriverFactory
public static ZooKeeperLeaderRetrievalDriverFactory createLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, org.apache.flink.configuration.Configuration configuration) Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.- Parameters:
client- TheCuratorFrameworkZooKeeper client to usepath- The path for the leader zNodeconfiguration- configuration for further config options- Returns:
LeaderRetrievalDriverFactoryinstance.
-
writeLeaderInformationToZooKeeper
public static void writeLeaderInformationToZooKeeper(LeaderInformation leaderInformation, org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework curatorFramework, BooleanSupplier hasLeadershipCheck, String connectionInformationPath) throws Exception - Throws:
Exception
-
readLeaderInformation
public static LeaderInformation readLeaderInformation(byte[] data) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
createExecutionPlans
public static ExecutionPlanStore createExecutionPlans(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, org.apache.flink.configuration.Configuration configuration) throws Exception Creates aDefaultExecutionPlanStoreinstance withZooKeeperStateHandleStore,ZooKeeperExecutionPlanStoreWatcherandZooKeeperExecutionPlanStoreUtil.- Parameters:
client- TheCuratorFrameworkZooKeeper client to useconfiguration-Configurationobject- Returns:
DefaultExecutionPlanStoreinstance- Throws:
Exception- if the submitted execution plan store cannot be created
-
getPathForJob
Returns the JobID as a String (with leading slash). -
createZooKeeperStateHandleStore
public static <T extends Serializable> ZooKeeperStateHandleStore<T> createZooKeeperStateHandleStore(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, RetrievableStateStorageHelper<T> stateStorage) throws Exception Creates an instance ofZooKeeperStateHandleStore.- Type Parameters:
T- Type of state- Parameters:
client- ZK clientpath- Path to use for the client namespacestateStorage- RetrievableStateStorageHelper that persist the actual state and whose returned state handle is then written to ZooKeeper- Returns:
ZooKeeperStateHandleStoreinstance- Throws:
Exception- ZK errors
-
createCheckpointIDCounter
public static ZooKeeperCheckpointIDCounter createCheckpointIDCounter(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client) Creates aZooKeeperCheckpointIDCounterinstance.- Parameters:
client- TheCuratorFrameworkZooKeeper client to use- Returns:
ZooKeeperCheckpointIDCounterinstance
-
createFileSystemStateStorage
public static <T extends Serializable> FileSystemStateStorageHelper<T> createFileSystemStateStorage(org.apache.flink.configuration.Configuration configuration, String prefix) throws IOException Creates aFileSystemStateStorageHelperinstance.- Type Parameters:
T- Type of the state objects- Parameters:
configuration-Configurationobjectprefix- Prefix for the created files- Returns:
FileSystemStateStorageHelperinstance- Throws:
IOException- if file system state storage cannot be created
-
generateZookeeperPath
Creates a ZooKeeper path of the form "/a/b/.../z". -
splitZooKeeperPath
Splits the given ZooKeeper path into its parts.- Parameters:
path- path to split- Returns:
- splited path
-
trimStartingSlash
-
useNamespaceAndEnsurePath
public static org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework useNamespaceAndEnsurePath(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path) throws Exception Returns a facade of the client that uses the specified namespace, and ensures that all nodes in the path exist.- Parameters:
client- ZK clientpath- the new namespace- Returns:
- ZK Client that uses the new namespace
- Throws:
Exception- ZK errors
-
createTreeCache
public static org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache createTreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String pathToNode, org.apache.flink.util.function.RunnableWithException nodeChangeCallback) Creates aTreeCachethat only observes a specific node.- Parameters:
client- ZK clientpathToNode- full path of the node to observenodeChangeCallback- callback to run if the node has changed- Returns:
- tree cache
-
createTreeCache
public static org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCache createTreeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String pathToNode, org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheSelector selector) -
deleteZNode
public static void deleteZNode(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework curatorFramework, String path) throws Exception - Throws:
Exception
-