2015-05-17 13:59:09 +02:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Cloudius Systems
|
|
|
|
*
|
|
|
|
* Modified by Cloudius Systems
|
|
|
|
*/
|
|
|
|
package org.apache.cassandra.net;
|
|
|
|
|
2016-08-17 10:36:02 +02:00
|
|
|
import static java.util.Collections.emptyMap;
|
|
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2015-11-11 08:48:49 +01:00
|
|
|
import java.util.Map.Entry;
|
2016-10-11 14:06:33 +02:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
2015-05-17 13:59:09 +02:00
|
|
|
|
2015-11-16 10:56:40 +01:00
|
|
|
import javax.json.JsonArray;
|
|
|
|
import javax.json.JsonObject;
|
2015-12-17 08:26:19 +01:00
|
|
|
|
2015-11-16 10:56:40 +01:00
|
|
|
import org.apache.cassandra.metrics.DroppedMessageMetrics;
|
2015-12-17 08:26:19 +01:00
|
|
|
|
|
|
|
import com.scylladb.jmx.api.APIClient;
|
2016-10-11 14:06:33 +02:00
|
|
|
import com.scylladb.jmx.metrics.MetricsMBean;
|
2015-05-17 13:59:09 +02:00
|
|
|
|
2016-10-11 14:06:33 +02:00
|
|
|
public final class MessagingService extends MetricsMBean implements MessagingServiceMBean {
|
2015-05-17 13:59:09 +02:00
|
|
|
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=MessagingService";
|
2016-10-11 14:06:33 +02:00
|
|
|
private static final Logger logger = Logger.getLogger(MessagingService.class.getName());
|
|
|
|
|
|
|
|
private Map<String, Long> resentTimeouts = new HashMap<String, Long>();
|
2015-11-17 10:57:07 +01:00
|
|
|
private long recentTimeoutCount;
|
|
|
|
|
2015-11-16 10:56:40 +01:00
|
|
|
/* All verb handler identifiers */
|
2016-10-11 14:06:33 +02:00
|
|
|
public enum Verb {
|
|
|
|
MUTATION, @Deprecated BINARY, READ_REPAIR, READ, REQUEST_RESPONSE, // client-initiated
|
|
|
|
// reads
|
|
|
|
// and
|
|
|
|
// writes
|
|
|
|
@Deprecated STREAM_INITIATE, @Deprecated STREAM_INITIATE_DONE, @Deprecated STREAM_REPLY, @Deprecated STREAM_REQUEST, RANGE_SLICE, @Deprecated BOOTSTRAP_TOKEN, @Deprecated TREE_REQUEST, @Deprecated TREE_RESPONSE, @Deprecated JOIN, GOSSIP_DIGEST_SYN, GOSSIP_DIGEST_ACK, GOSSIP_DIGEST_ACK2, @Deprecated DEFINITIONS_ANNOUNCE, DEFINITIONS_UPDATE, TRUNCATE, SCHEMA_CHECK, @Deprecated INDEX_SCAN, REPLICATION_FINISHED, INTERNAL_RESPONSE, // responses
|
|
|
|
// to
|
|
|
|
// internal
|
|
|
|
// calls
|
|
|
|
COUNTER_MUTATION, @Deprecated STREAMING_REPAIR_REQUEST, @Deprecated STREAMING_REPAIR_RESPONSE, SNAPSHOT, // Similar
|
|
|
|
// to
|
|
|
|
// nt
|
|
|
|
// snapshot
|
|
|
|
MIGRATION_REQUEST, GOSSIP_SHUTDOWN, _TRACE, // dummy verb so we can use
|
|
|
|
// MS.droppedMessages
|
|
|
|
ECHO, REPAIR_MESSAGE,
|
|
|
|
// use as padding for backwards compatability where a previous version
|
|
|
|
// needs to validate a verb from the future.
|
|
|
|
PAXOS_PREPARE, PAXOS_PROPOSE, PAXOS_COMMIT, PAGED_RANGE,
|
2015-11-16 10:56:40 +01:00
|
|
|
// remember to add new verbs at the end, since we serialize by ordinal
|
2016-10-11 14:06:33 +02:00
|
|
|
UNUSED_1, UNUSED_2, UNUSED_3,;
|
2015-11-16 10:56:40 +01:00
|
|
|
}
|
2015-05-17 13:59:09 +02:00
|
|
|
|
|
|
|
public void log(String str) {
|
2015-12-30 07:47:32 +01:00
|
|
|
logger.finest(str);
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:06:33 +02:00
|
|
|
public MessagingService(APIClient client) {
|
|
|
|
super(MBEAN_NAME, client,
|
|
|
|
Stream.of(Verb.values()).map(v -> new DroppedMessageMetrics(v)).collect(Collectors.toList()));
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pending tasks for Command(Mutations, Read etc) TCP Connections
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Integer> getCommandPendingTasks() {
|
|
|
|
log(" getCommandPendingTasks()");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getMapStringIntegerValue("/messaging_service/messages/pending");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Completed tasks for Command(Mutations, Read etc) TCP Connections
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Long> getCommandCompletedTasks() {
|
2015-12-30 07:47:32 +01:00
|
|
|
log("getCommandCompletedTasks()");
|
2016-10-11 14:06:33 +02:00
|
|
|
Map<String, Long> res = client.getListMapStringLongValue("/messaging_service/messages/sent");
|
2015-05-17 13:59:09 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dropped tasks for Command(Mutations, Read etc) TCP Connections
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Long> getCommandDroppedTasks() {
|
|
|
|
log(" getCommandDroppedTasks()");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getMapStringLongValue("/messaging_service/messages/dropped");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pending tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Integer> getResponsePendingTasks() {
|
|
|
|
log(" getResponsePendingTasks()");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getMapStringIntegerValue("/messaging_service/messages/respond_pending");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Completed tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Long> getResponseCompletedTasks() {
|
|
|
|
log(" getResponseCompletedTasks()");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getMapStringLongValue("/messaging_service/messages/respond_completed");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dropped message counts for server lifetime
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Integer> getDroppedMessages() {
|
|
|
|
log(" getDroppedMessages()");
|
2015-11-16 10:56:40 +01:00
|
|
|
Map<String, Integer> res = new HashMap<String, Integer>();
|
2016-10-11 14:06:33 +02:00
|
|
|
JsonArray arr = client.getJsonArray("/messaging_service/messages/dropped_by_ver");
|
2015-11-16 10:56:40 +01:00
|
|
|
for (int i = 0; i < arr.size(); i++) {
|
|
|
|
JsonObject obj = arr.getJsonObject(i);
|
|
|
|
res.put(obj.getString("verb"), obj.getInt("count"));
|
|
|
|
}
|
|
|
|
return res;
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:06:33 +02:00
|
|
|
private Map<String, Integer> recent;
|
|
|
|
|
2015-05-17 13:59:09 +02:00
|
|
|
/**
|
|
|
|
* dropped message counts since last called
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Integer> getRecentlyDroppedMessages() {
|
|
|
|
log(" getRecentlyDroppedMessages()");
|
2016-10-11 14:06:33 +02:00
|
|
|
|
|
|
|
Map<String, Integer> dropped = getDroppedMessages(), result = new HashMap<>(dropped), old = recent;
|
|
|
|
|
|
|
|
recent = dropped;
|
|
|
|
|
|
|
|
if (old != null) {
|
|
|
|
for (Map.Entry<String, Integer> e : old.entrySet()) {
|
|
|
|
result.put(e.getKey(), result.get(e.getKey()) - e.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Total number of timeouts happened on this node
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public long getTotalTimeouts() {
|
|
|
|
log(" getTotalTimeouts()");
|
2015-11-11 08:48:49 +01:00
|
|
|
Map<String, Long> timeouts = getTimeoutsPerHost();
|
|
|
|
long res = 0;
|
|
|
|
for (Entry<String, Long> t : timeouts.entrySet()) {
|
|
|
|
res += t.getValue();
|
|
|
|
}
|
|
|
|
return res;
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of timeouts per host
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Long> getTimeoutsPerHost() {
|
|
|
|
log(" getTimeoutsPerHost()");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getMapStringLongValue("/messaging_service/messages/timeout");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of timeouts since last check.
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public long getRecentTotalTimouts() {
|
|
|
|
log(" getRecentTotalTimouts()");
|
2015-11-17 10:57:07 +01:00
|
|
|
long timeoutCount = getTotalTimeouts();
|
|
|
|
long recent = timeoutCount - recentTimeoutCount;
|
|
|
|
recentTimeoutCount = timeoutCount;
|
|
|
|
return recent;
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of timeouts since last check per host.
|
|
|
|
*/
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public Map<String, Long> getRecentTimeoutsPerHost() {
|
|
|
|
log(" getRecentTimeoutsPerHost()");
|
2015-11-17 10:57:07 +01:00
|
|
|
Map<String, Long> timeouts = getTimeoutsPerHost();
|
|
|
|
Map<String, Long> result = new HashMap<String, Long>();
|
2016-10-11 14:06:33 +02:00
|
|
|
for (Entry<String, Long> e : timeouts.entrySet()) {
|
|
|
|
long res = e.getValue().longValue()
|
|
|
|
- ((resentTimeouts.containsKey(e.getKey())) ? (resentTimeouts.get(e.getKey())).longValue() : 0);
|
|
|
|
resentTimeouts.put(e.getKey(), e.getValue());
|
|
|
|
result.put(e.getKey(), res);
|
2015-11-17 10:57:07 +01:00
|
|
|
}
|
|
|
|
return result;
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
2015-05-17 13:59:09 +02:00
|
|
|
public int getVersion(String address) throws UnknownHostException {
|
|
|
|
log(" getVersion(String address) throws UnknownHostException");
|
2016-10-11 14:06:33 +02:00
|
|
|
return client.getIntValue("");
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-17 10:36:02 +02:00
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getLargeMessagePendingTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return getCommandPendingTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getLargeMessageCompletedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return getCommandCompletedTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getLargeMessageDroppedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return getCommandDroppedTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getSmallMessagePendingTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return getResponsePendingTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getSmallMessageCompletedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return getResponseCompletedTasks();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getSmallMessageDroppedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return emptyMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getGossipMessagePendingTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return emptyMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getGossipMessageCompletedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return emptyMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Long> getGossipMessageDroppedTasks() {
|
|
|
|
// TODO: implement for realsies
|
|
|
|
return emptyMap();
|
|
|
|
}
|
2015-05-17 13:59:09 +02:00
|
|
|
}
|