Package org.apache.flink.runtime.util
Class ZooKeeperUtils
- java.lang.Object
-
- org.apache.flink.runtime.util.ZooKeeperUtils
-
public class ZooKeeperUtils extends Object
Class containing helper functions to interact with ZooKeeper.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classZooKeeperUtils.SecureAclProviderSecureACLProviderimplementation.static classZooKeeperUtils.ZkClientACLModeZooKeeper client ACL mode enum.
-
Field Summary
Fields Modifier and Type Field Description static StringHA_STORAGE_COMPLETED_CHECKPOINTThe prefix of the completed checkpoint file.static StringHA_STORAGE_SUBMITTED_EXECUTION_PLAN_PREFIXThe prefix of the submitted job graph file.static StringRESOURCE_MANAGER_NODEThe prefix of the resource manager node.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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.static ZooKeeperLeaderRetrievalDriverFactorycreateLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client)Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.static ZooKeeperLeaderRetrievalDriverFactorycreateLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path)Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.static ZooKeeperLeaderRetrievalDriverFactorycreateLeaderRetrievalDriverFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client, String path, org.apache.flink.configuration.Configuration configuration)Creates aLeaderRetrievalDriverFactoryimplemented by ZooKeeper.static DefaultLeaderRetrievalServicecreateLeaderRetrievalService(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework client)Creates aDefaultLeaderRetrievalServiceinstance withZooKeeperLeaderRetrievalDriver.static DefaultLeaderRetrievalServicecreateLeaderRetrievalService(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 StringgenerateConnectionInformationPath(String path)static StringgenerateLeaderLatchPath(String path)static StringgenerateZookeeperPath(String... paths)Creates a ZooKeeper path of the form "/a/b/...static StringgetCheckpointIdCounterPath()static StringgetDispatcherNode()static StringgetJobsPath()static StringgetLeaderLatchPath()static StringgetLeaderPath()static 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 StringgetResourceManagerNode()static StringgetRestServerNode()static 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.static CuratorFrameworkWithUnhandledErrorListenerstartCuratorFramework(org.apache.flink.configuration.Configuration configuration, org.apache.flink.runtime.rpc.FatalErrorHandler fatalErrorHandler)Starts aCuratorFrameworkinstance and connects it to the given ZooKeeper quorum.static CuratorFrameworkWithUnhandledErrorListenerstartCuratorFramework(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 Detail
-
HA_STORAGE_SUBMITTED_EXECUTION_PLAN_PREFIX
public static final String HA_STORAGE_SUBMITTED_EXECUTION_PLAN_PREFIX
The prefix of the submitted job graph file.- See Also:
- Constant Field Values
-
HA_STORAGE_COMPLETED_CHECKPOINT
public static final String HA_STORAGE_COMPLETED_CHECKPOINT
The prefix of the completed checkpoint file.- See Also:
- Constant Field Values
-
RESOURCE_MANAGER_NODE
public static final String RESOURCE_MANAGER_NODE
The prefix of the resource manager node.- See Also:
- Constant Field Values
-
-
Method Detail
-
getLeaderPathForJob
public static String getLeaderPathForJob(org.apache.flink.api.common.JobID jobId)
-
getJobsPath
public static String getJobsPath()
-
getCheckpointIdCounterPath
public static String getCheckpointIdCounterPath()
-
getLeaderPath
public static String getLeaderPath()
-
getDispatcherNode
public static String getDispatcherNode()
-
getResourceManagerNode
public static String getResourceManagerNode()
-
getRestServerNode
public static String getRestServerNode()
-
getLeaderLatchPath
public static String getLeaderLatchPath()
-
generateConnectionInformationPath
public static String generateConnectionInformationPath(String path)
-
isConnectionInfoPath
public static boolean isConnectionInfoPath(String path)
-
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
-
createCompletedCheckpoints
public static CompletedCheckpointStore createCompletedCheckpoints(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) throws Exception
Creates aDefaultCompletedCheckpointStoreinstance withZooKeeperStateHandleStore.- Parameters:
client- TheCuratorFrameworkZooKeeper client to useconfiguration-ConfigurationobjectmaxNumberOfCheckpointsToRetain- The maximum number of checkpoints to retainexecutor- to run ZooKeeper callbacksrecoveryClaimMode- the mode in which the job is being restored- Returns:
DefaultCompletedCheckpointStoreinstance- Throws:
Exception- if the completed checkpoint store cannot be created
-
getPathForJob
public static String getPathForJob(org.apache.flink.api.common.JobID jobId)
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
public static String generateZookeeperPath(String... paths)
Creates a ZooKeeper path of the form "/a/b/.../z".
-
splitZooKeeperPath
public static String[] splitZooKeeperPath(String path)
Splits the given ZooKeeper path into its parts.- Parameters:
path- path to split- Returns:
- splited path
-
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 ExceptionReturns 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)
-
-