use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.
the class ZkController method getLeaderInitiatedRecoveryStateObject.
public Map<String, Object> getLeaderInitiatedRecoveryStateObject(String collection, String shardId, String coreNodeName) {
if (collection == null || shardId == null || coreNodeName == null)
// if we don't have complete data about a core in cloud mode, return null
return null;
String znodePath = getLeaderInitiatedRecoveryZnodePath(collection, shardId, coreNodeName);
byte[] stateData = null;
try {
stateData = zkClient.getData(znodePath, null, new Stat(), false);
} catch (NoNodeException ignoreMe) {
// safe to ignore as this znode will only exist if the leader initiated recovery
} catch (ConnectionLossException | SessionExpiredException cle) {
// sort of safe to ignore ??? Usually these are seen when the core is going down
// or there are bigger issues to deal with than reading this znode
log.warn("Unable to read " + znodePath + " due to: " + cle);
} catch (Exception exc) {
log.error("Failed to read data from znode " + znodePath + " due to: " + exc);
if (exc instanceof SolrException) {
throw (SolrException) exc;
} else {
throw new SolrException(ErrorCode.SERVER_ERROR, "Failed to read data from znodePath: " + znodePath, exc);
}
}
Map<String, Object> stateObj = null;
if (stateData != null && stateData.length > 0) {
// TODO: Remove later ... this is for upgrading from 4.8.x to 4.10.3 (see: SOLR-6732)
if (stateData[0] == (byte) '{') {
Object parsedJson = Utils.fromJSON(stateData);
if (parsedJson instanceof Map) {
stateObj = (Map<String, Object>) parsedJson;
} else {
throw new SolrException(ErrorCode.SERVER_ERROR, "Leader-initiated recovery state data is invalid! " + parsedJson);
}
} else {
// old format still in ZK
stateObj = Utils.makeMap("state", new String(stateData, StandardCharsets.UTF_8));
}
}
return stateObj;
}
use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.
the class ZkController method getLeaderProps.
/**
* Get leader props directly from zk nodes.
*
* @return leader props
*/
public ZkCoreNodeProps getLeaderProps(final String collection, final String slice, int timeoutms, boolean failImmediatelyOnExpiration) throws InterruptedException {
int iterCount = timeoutms / 1000;
Exception exp = null;
while (iterCount-- > 0) {
try {
byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
return leaderProps;
} catch (InterruptedException e) {
throw e;
} catch (SessionExpiredException e) {
if (failImmediatelyOnExpiration) {
throw new RuntimeException("Session has expired - could not get leader props", exp);
}
exp = e;
Thread.sleep(1000);
} catch (Exception e) {
exp = e;
Thread.sleep(1000);
}
if (cc.isShutDown()) {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "CoreContainer is closed");
}
}
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Could not get leader props", exp);
}
use of org.apache.zookeeper.KeeperException.SessionExpiredException in project accumulo by apache.
the class ZooReaderWriterTest method testMutateNodeCreationFails.
@Test(expected = SessionExpiredException.class)
public void testMutateNodeCreationFails() throws Exception {
final String path = "/foo";
final byte[] value = new byte[] { 0 };
final List<ACL> acls = Collections.emptyList();
Mutator mutator = new Mutator() {
@Override
public byte[] mutate(byte[] currentValue) throws Exception {
return new byte[] { 1 };
}
};
zk.create(path, value, acls, CreateMode.PERSISTENT);
EasyMock.expectLastCall().andThrow(new SessionExpiredException()).once();
EasyMock.expect(retry.canRetry()).andReturn(false);
EasyMock.expect(retry.retriesCompleted()).andReturn(1l).once();
EasyMock.replay(zk, zrw, retryFactory, retry);
zrw.mutate(path, value, acls, mutator);
}
use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.
the class TestManagedSchemaThreadSafety method createZkController.
private ZkController createZkController(SolrZkClient client) throws KeeperException, InterruptedException {
CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
// Allow retry on session expiry
when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(Boolean.FALSE);
MockZkController zkController = mock(MockZkController.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
when(zkController.getZkClient()).thenReturn(client);
Mockito.doAnswer(new Answer<Boolean>() {
volatile boolean sessionExpired = false;
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
String path = (String) invocation.getArguments()[0];
perhapsExpired();
Boolean exists = client.exists(path, true);
perhapsExpired();
return exists;
}
private void perhapsExpired() throws SessionExpiredException {
if (!sessionExpired && rarely()) {
sessionExpired = true;
throw new KeeperException.SessionExpiredException();
}
}
}).when(zkController).pathExists(Mockito.anyString());
return zkController;
}
use of org.apache.zookeeper.KeeperException.SessionExpiredException in project lucene-solr by apache.
the class LeaderElectionTest method getLeaderUrl.
private String getLeaderUrl(final String collection, final String slice) throws KeeperException, InterruptedException {
int iterCount = 60;
while (iterCount-- > 0) {
try {
byte[] data = zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null, true);
ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data));
return leaderProps.getCoreUrl();
} catch (NoNodeException | SessionExpiredException e) {
Thread.sleep(500);
}
}
zkClient.printLayoutToStdOut();
throw new RuntimeException("Could not get leader props");
}
Aggregations