SOLR-14463: Solr Admin ZkStatus page now works with ZK 3.6 (#1499)

This commit is contained in:
Jan Høydahl 2020-05-12 10:57:33 +02:00 committed by GitHub
parent a0e158c3d0
commit 6971244134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -161,6 +161,8 @@ Bug Fixes
* SOLR-14431: SegmentsInfoRequestHandler does not release IndexWriter (Tiziano Degaetano, ab) * SOLR-14431: SegmentsInfoRequestHandler does not release IndexWriter (Tiziano Degaetano, ab)
* SOLR-14463: Solr Admin ZkStatus page now works with ZK 3.6, without 'For input string: "null"' error (janhoy, Bernd Wahlen)
Other Changes Other Changes
--------------------- ---------------------
* SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid * SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid

View File

@ -147,7 +147,10 @@ public class ZookeeperStatusHandler extends RequestHandlerBase {
followers++; followers++;
} else if ("leader".equals(state)) { } else if ("leader".equals(state)) {
leaders++; leaders++;
reportedFollowers = Integer.parseInt(String.valueOf(stat.get("zk_followers"))); reportedFollowers = Math.max(
Integer.parseInt((String) stat.getOrDefault("zk_followers", "0")),
Integer.parseInt((String) stat.getOrDefault("zk_synced_followers", "0"))
);
} else if ("standalone".equals(state)) { } else if ("standalone".equals(state)) {
standalone++; standalone++;
} }

View File

@ -165,4 +165,39 @@ public class ZookeeperStatusHandlerTest extends SolrCloudTestCase {
public void validateEmptyResponse() { public void validateEmptyResponse() {
new ZookeeperStatusHandler(null).validateZkRawResponse(Collections.emptyList(), "zoo1:2181", "mntr"); new ZookeeperStatusHandler(null).validateZkRawResponse(Collections.emptyList(), "zoo1:2181", "mntr");
} }
@Test
public void testMntrBugZk36Solr14463() {
assumeWorkingMockito();
ZookeeperStatusHandler zkStatusHandler = mock(ZookeeperStatusHandler.class);
when(zkStatusHandler.getZkRawResponse("zoo1:2181", "ruok")).thenReturn(Arrays.asList("imok"));
when(zkStatusHandler.getZkRawResponse("zoo1:2181", "mntr")).thenReturn(
Arrays.asList("zk_version\t3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT",
"zk_avg_latency\t1",
"zk_server_state\tleader",
"zk_synced_followers\t2"));
when(zkStatusHandler.getZkRawResponse("zoo1:2181", "conf")).thenReturn(
Arrays.asList("clientPort=2181"));
when(zkStatusHandler.getZkStatus(anyString(), any())).thenCallRealMethod();
when(zkStatusHandler.monitorZookeeper(anyString())).thenCallRealMethod();
when(zkStatusHandler.validateZkRawResponse(ArgumentMatchers.any(), any(), any())).thenAnswer(Answers.CALLS_REAL_METHODS);
Map<String, Object> mockStatus = zkStatusHandler.getZkStatus("zoo1:2181", ZkDynamicConfig.fromZkConnectString("zoo1:2181"));
String expected = "{\n" +
" \"mode\":\"ensemble\",\n" +
" \"dynamicReconfig\":true,\n" +
" \"ensembleSize\":1,\n" +
" \"details\":[{\n" +
" \"zk_synced_followers\":\"2\",\n" +
" \"zk_version\":\"3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT\",\n" +
" \"zk_avg_latency\":\"1\",\n" +
" \"host\":\"zoo1:2181\",\n" +
" \"clientPort\":\"2181\",\n" +
" \"ok\":true,\n" +
" \"zk_server_state\":\"leader\"}],\n" +
" \"zkHost\":\"zoo1:2181\",\n" +
" \"errors\":[\"Leader reports 2 followers, but we only found 0. Please check zkHost configuration\"],\n" +
" \"status\":\"red\"}";
assertEquals(expected, JSONUtil.toJSON(mockStatus));
}
} }