SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen.

This commit is contained in:
Andrzej Bialecki 2018-08-02 18:47:58 +02:00
parent 5de10c7966
commit d1173b8adc
5 changed files with 24 additions and 13 deletions

View File

@ -198,6 +198,8 @@ Bug Fixes
* SOLR-12344: SolrSlf4jReporter doesn't set MDC context. (ab)
* SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen. (ab)
Optimizations
----------------------

View File

@ -62,6 +62,7 @@ import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.cloud.autoscaling.ReplicaInfo;
import org.apache.solr.client.solrj.cloud.autoscaling.VersionedData;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.cloud.LeaderElector;
import org.apache.solr.cloud.Overseer;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ClusterState;
@ -332,12 +333,14 @@ public class MetricsHistoryHandler extends RequestHandlerBase implements Permiss
if (oid == null) {
return null;
}
String[] ids = oid.split("-");
if (ids.length != 3) { // unknown format
log.warn("Unknown format of leader id, skipping: " + oid);
String nodeName = null;
try {
nodeName = LeaderElector.getNodeName(oid);
} catch (Exception e) {
log.warn("Unknown format of leader id, skipping: " + oid, e);
return null;
}
return ids[1];
return nodeName;
}
private boolean amIOverseerLeader() {

View File

@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.http.client.HttpClient;
import org.apache.solr.cloud.LeaderElector;
import org.apache.solr.cloud.Overseer;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.cloud.SolrZkClient;
@ -270,13 +271,15 @@ public class SolrClusterReporter extends SolrCoreContainerReporter {
if (oid == null) {
return lastKnownUrl;
}
String[] ids = oid.split("-");
if (ids.length != 3) { // unknown format
log.warn("Unknown format of leader id, skipping: " + oid);
String nodeName = null;
try {
nodeName = LeaderElector.getNodeName(oid);
} catch (Exception e) {
log.warn("Unknown format of leader id, skipping: " + oid, e);
return lastKnownUrl;
}
// convert nodeName back to URL
String url = zk.getZkStateReader().getBaseUrlForNodeName(ids[1]);
String url = zk.getZkStateReader().getBaseUrlForNodeName(nodeName);
// check that it's parseable
try {
new java.net.URL(url);

View File

@ -206,7 +206,8 @@ public class SolrRrdBackendFactory extends RrdBackendFactory implements SolrClos
return null;
}
if (o instanceof byte[]) {
Long time = (Long)doc.getFieldValue("timestamp_l");
Object timeObj = doc.getFieldValue("timestamp_l");
Long time = timeObj instanceof Number ? ((Number)timeObj).longValue() : Long.parseLong(String.valueOf(timeObj));
return new SolrRrdBackend.SyncData((byte[])o, time);
} else {
throw new SolrServerException("Unexpected value of '" + DATA_FIELD + "' field: " + o.getClass().getName() + ": " + o);
@ -248,7 +249,11 @@ public class SolrRrdBackendFactory extends RrdBackendFactory implements SolrClos
SolrDocumentList docs = rsp.getResults();
if (docs != null) {
docs.forEach(d -> {
Long time = (Long)d.getFieldValue("timestamp_l");
Object o = d.getFieldValue("timestamp_l");
if (o == null) {
return;
}
Long time = o instanceof Number ? ((Number)o).longValue() : Long.parseLong(String.valueOf(o));
Pair<String, Long> p = new Pair<>(((String)d.getFieldValue("id")).substring(idPrefixLength), time);
byName.put(p.first(), p);
});

View File

@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.cloud.autoscaling.AutoScalingConfig;
@ -45,7 +44,6 @@ import org.rrd4j.core.RrdDb;
*
*/
@LogLevel("org.apache.solr.cloud=DEBUG")
@LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Jul-2018
public class MetricsHistoryHandlerTest extends SolrCloudTestCase {
private static SolrCloudManager cloudManager;
@ -60,7 +58,7 @@ public class MetricsHistoryHandlerTest extends SolrCloudTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
simulated = random().nextBoolean() || true;
simulated = random().nextBoolean();
Map<String, Object> args = new HashMap<>();
args.put(MetricsHistoryHandler.SYNC_PERIOD_PROP, 1);
args.put(MetricsHistoryHandler.COLLECT_PERIOD_PROP, 1);