public class ZkController extends Object implements Closeable
notes: loads everything on init, creates what's not there - further updates are prompted with Watches.
TODO: exceptions during close on attempts to update cloud state
Modifier and Type | Class and Description |
---|---|
static class |
ZkController.NotInClusterStateException
Thrown during pre register process if the replica is not present in clusterstate
|
static class |
ZkController.ResourceModifiedInZkException |
Modifier and Type | Field and Description |
---|---|
static String |
COLLECTION_PARAM_PREFIX |
static String |
CONFIGNAME_PROP |
protected Overseer |
overseer |
ZkStateReader |
zkStateReader |
Constructor and Description |
---|
ZkController(CoreContainer cc,
String zkServerAddress,
int zkClientConnectTimeout,
CloudConfig cloudConfig,
CurrentCoreDescriptorProvider registerOnReconnect) |
Modifier and Type | Method and Description |
---|---|
void |
addOnReconnectListener(OnReconnect listener)
Add a listener to be notified once there is a new session created after a ZooKeeper session expiration occurs;
in most cases, listeners will be components that have watchers that need to be re-created.
|
static void |
bootstrapConf(SolrZkClient zkClient,
CoreContainer cc,
String solrHome)
If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
|
static boolean |
checkChrootPath(String zkHost,
boolean create)
Validates if the chroot exists in zk (or if it is successfully created).
|
boolean |
checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore) |
void |
checkOverseerDesignate() |
boolean |
claimAsyncId(String asyncId)
When an operation needs to be performed in an asynchronous mode, the asyncId needs
to be claimed by calling this method to make sure it's not duplicate (hasn't been
claimed by other request).
|
boolean |
clearAsyncId(String asyncId)
Clears an asyncId previously claimed by calling
claimAsyncId(String) |
void |
clearZkCollectionTerms() |
void |
close()
Closes the underlying ZooKeeper client.
|
boolean |
configFileExists(String collection,
String fileName)
Returns true if config file exists
|
static void |
createClusterZkNodes(SolrZkClient zkClient)
Create the zknodes necessary for a cluster to operate
|
void |
createCollection(String collection) |
String |
getBaseUrl() |
int |
getClientTimeout() |
ClusterState |
getClusterState() |
OnReconnect |
getConfigDirListener() |
byte[] |
getConfigFileData(String zkConfigName,
String fileName)
Returns config file data (in bytes)
|
CoreContainer |
getCoreContainer() |
String |
getCoreNodeName(CoreDescriptor descriptor) |
static String |
getDefaultConfigDirPath()
Gets the absolute filesystem path of the _default configset to bootstrap from.
|
String |
getHostName() |
int |
getHostPort() |
int |
getLeaderConflictResolveWait() |
ZkCoreNodeProps |
getLeaderProps(String collection,
String slice,
int timeoutms)
Get leader props directly from zk nodes.
|
ZkCoreNodeProps |
getLeaderProps(String collection,
String slice,
int timeoutms,
boolean failImmediatelyOnExpiration)
Get leader props directly from zk nodes.
|
int |
getLeaderVoteWait() |
String |
getNodeName() |
Overseer |
getOverseer() |
OverseerTaskQueue |
getOverseerCollectionQueue() |
DistributedMap |
getOverseerCompletedMap() |
OverseerTaskQueue |
getOverseerConfigSetQueue() |
LeaderElector |
getOverseerElector() |
DistributedMap |
getOverseerFailureMap() |
ZkDistributedQueue |
getOverseerJobQueue() |
DistributedMap |
getOverseerRunningMap() |
ZkShardTerms |
getShardTerms(String collection,
String shardId) |
SolrCloudManager |
getSolrCloudManager() |
NodesSysPropsCacher |
getSysPropsCacher() |
SolrZkClient |
getZkClient() |
String |
getZkServerAddress() |
ZkStateReader |
getZkStateReader() |
void |
giveupLeadership(CoreDescriptor cd,
Throwable tragicException)
Best effort to give up the leadership of a shard in a core after hitting a tragic exception
|
boolean |
isConnected() |
static void |
linkConfSet(SolrZkClient zkClient,
String collection,
String confSetName) |
boolean |
pathExists(String path)
Returns true if the path exists
|
static int |
persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader,
int znodeVersion,
String resourceName,
byte[] content,
boolean createIfNotExists)
Persists a config file to ZooKeeper using optimistic concurrency.
|
void |
preClose() |
void |
preRegister(CoreDescriptor cd,
boolean publishState) |
void |
publish(CoreDescriptor cd,
Replica.State state) |
void |
publish(CoreDescriptor cd,
Replica.State state,
boolean updateLastState,
boolean forcePublish)
Publish core state to overseer.
|
void |
publishAndWaitForDownStates() |
void |
publishAndWaitForDownStates(int timeoutSeconds) |
void |
publishNodeAsDown(String nodeName)
Best effort to set DOWN state for all replicas on node.
|
String |
register(String coreName,
CoreDescriptor desc,
boolean skipRecovery)
Register shard with ZooKeeper.
|
String |
register(String coreName,
CoreDescriptor desc,
boolean recoverReloadedCores,
boolean afterExpiration,
boolean skipRecovery)
Register shard with ZooKeeper.
|
void |
registerConfListenerForCore(String confDir,
SolrCore core,
Runnable listener)
This will give a callback to the listener whenever a child is modified in the
conf directory.
|
void |
rejoinOverseerElection(String electionNode,
boolean joinAtHead) |
void |
rejoinShardLeaderElection(SolrParams params) |
void |
removeEphemeralLiveNode() |
void |
removeOnReconnectListener(OnReconnect listener)
Removed a previously registered OnReconnect listener, such as when a core is removed or reloaded.
|
void |
startReplicationFromLeader(String coreName,
boolean switchTransactionLog) |
void |
stopReplicationFromLeader(String coreName) |
void |
throwErrorIfReplicaReplaced(CoreDescriptor desc) |
static void |
touchConfDir(ZkSolrResourceLoader zkLoader) |
static String |
trimLeadingAndTrailingSlashes(String in)
Utility method for trimming and leading and/or trailing slashes from
its input.
|
void |
unregister(String coreName,
CoreDescriptor cd) |
void |
unregister(String coreName,
CoreDescriptor cd,
boolean removeCoreFromZk) |
public static final String COLLECTION_PARAM_PREFIX
public static final String CONFIGNAME_PROP
public final ZkStateReader zkStateReader
protected volatile Overseer overseer
public ZkController(CoreContainer cc, String zkServerAddress, int zkClientConnectTimeout, CloudConfig cloudConfig, CurrentCoreDescriptorProvider registerOnReconnect) throws InterruptedException, TimeoutException, IOException
public int getLeaderVoteWait()
public int getLeaderConflictResolveWait()
public NodesSysPropsCacher getSysPropsCacher()
public void preClose()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void giveupLeadership(CoreDescriptor cd, Throwable tragicException)
cd
- The current core descriptortragicException
- The tragic exception from the IndexWriter
public boolean configFileExists(String collection, String fileName) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public ClusterState getClusterState()
public SolrCloudManager getSolrCloudManager()
public byte[] getConfigFileData(String zkConfigName, String fileName) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public String getHostName()
public int getHostPort()
public SolrZkClient getZkClient()
public String getZkServerAddress()
public static void createClusterZkNodes(SolrZkClient zkClient) throws org.apache.zookeeper.KeeperException, InterruptedException, IOException
zkClient
- a SolrZkClientorg.apache.zookeeper.KeeperException
- if there is a Zookeeper errorInterruptedException
- on interruptIOException
public static String getDefaultConfigDirPath()
SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE
public void publishAndWaitForDownStates() throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public void publishAndWaitForDownStates(int timeoutSeconds) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public static boolean checkChrootPath(String zkHost, boolean create) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public boolean isConnected()
public void removeEphemeralLiveNode() throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public String getNodeName()
public boolean pathExists(String path) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public String register(String coreName, CoreDescriptor desc, boolean skipRecovery) throws Exception
Exception
public String register(String coreName, CoreDescriptor desc, boolean recoverReloadedCores, boolean afterExpiration, boolean skipRecovery) throws Exception
Exception
public void startReplicationFromLeader(String coreName, boolean switchTransactionLog) throws InterruptedException
InterruptedException
public void stopReplicationFromLeader(String coreName)
public ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms) throws InterruptedException, org.apache.zookeeper.KeeperException.SessionExpiredException
org.apache.zookeeper.KeeperException.SessionExpiredException
- on zk session expiration.InterruptedException
public ZkCoreNodeProps getLeaderProps(String collection, String slice, int timeoutms, boolean failImmediatelyOnExpiration) throws InterruptedException, org.apache.zookeeper.KeeperException.SessionExpiredException
org.apache.zookeeper.KeeperException.SessionExpiredException
- on zk session expiration.InterruptedException
public String getBaseUrl()
public void publish(CoreDescriptor cd, Replica.State state) throws Exception
Exception
public void publish(CoreDescriptor cd, Replica.State state, boolean updateLastState, boolean forcePublish) throws Exception
Exception
public ZkShardTerms getShardTerms(String collection, String shardId)
public void clearZkCollectionTerms()
public void unregister(String coreName, CoreDescriptor cd) throws Exception
Exception
public void unregister(String coreName, CoreDescriptor cd, boolean removeCoreFromZk) throws Exception
Exception
public ZkStateReader getZkStateReader()
public String getCoreNodeName(CoreDescriptor descriptor)
public void preRegister(CoreDescriptor cd, boolean publishState)
public static void linkConfSet(SolrZkClient zkClient, String collection, String confSetName) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome) throws IOException
IOException
public ZkDistributedQueue getOverseerJobQueue()
public OverseerTaskQueue getOverseerCollectionQueue()
public OverseerTaskQueue getOverseerConfigSetQueue()
public DistributedMap getOverseerRunningMap()
public DistributedMap getOverseerCompletedMap()
public DistributedMap getOverseerFailureMap()
public boolean claimAsyncId(String asyncId) throws org.apache.zookeeper.KeeperException
clearAsyncId(String)
.
If this method returns false, no reservation has been made, and this asyncId can't
be used, since it's being used by another operation (currently or in the past)asyncId
- A string representing the asyncId of an operation. Can't be null.org.apache.zookeeper.KeeperException
public boolean clearAsyncId(String asyncId) throws org.apache.zookeeper.KeeperException
claimAsyncId(String)
asyncId
- A string representing the asyncId of an operation. Can't be null.org.apache.zookeeper.KeeperException
public int getClientTimeout()
public Overseer getOverseer()
public LeaderElector getOverseerElector()
public static String trimLeadingAndTrailingSlashes(String in)
public void rejoinOverseerElection(String electionNode, boolean joinAtHead)
public void rejoinShardLeaderElection(SolrParams params)
public void checkOverseerDesignate()
public CoreContainer getCoreContainer()
public void throwErrorIfReplicaReplaced(CoreDescriptor desc)
public void addOnReconnectListener(OnReconnect listener)
public void removeOnReconnectListener(OnReconnect listener)
public static int persistConfigResourceToZooKeeper(ZkSolrResourceLoader zkLoader, int znodeVersion, String resourceName, byte[] content, boolean createIfNotExists)
public static void touchConfDir(ZkSolrResourceLoader zkLoader)
public void registerConfListenerForCore(String confDir, SolrCore core, Runnable listener)
public OnReconnect getConfigDirListener()
public boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore)
public void publishNodeAsDown(String nodeName)
nodeName
- to operate onCopyright © 2000-2020 Apache Software Foundation. All Rights Reserved.