Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix client beat #959

Merged
merged 4 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.consistency.ApplyAction;
import com.alibaba.nacos.naming.consistency.RecordListener;
import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.consistency.RecordListener;
import com.alibaba.nacos.naming.core.Instances;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.misc.*;
Expand Down Expand Up @@ -312,7 +312,7 @@ public void onPublish(Datum datum, RaftPeer source) throws Exception {
}
raftStore.updateTerm(local.term.get());

notifier.addTask(datum, ApplyAction.CHANGE);
notifier.addTask(datum.key, ApplyAction.CHANGE);

Loggers.RAFT.info("data added/updated, key={}, term={}", datum.key, local.term);
}
Expand Down Expand Up @@ -353,6 +353,8 @@ public void onDelete(Datum datum, RaftPeer source) throws Exception {
raftStore.updateTerm(local.term.get());
}

Loggers.RAFT.info("data removed, key={}, term={}", datum.key, local.term);

}

public class MasterElection implements Runnable {
Expand Down Expand Up @@ -699,7 +701,7 @@ public Integer onCompleted(Response response) throws Exception {
}

datums.put(datum.key, datum);
notifier.addTask(datum, ApplyAction.CHANGE);
notifier.addTask(datum.key, ApplyAction.CHANGE);

local.resetLeaderDue();

Expand Down Expand Up @@ -844,7 +846,7 @@ public int datumSize() {

public void addDatum(Datum datum) {
datums.put(datum.key, datum);
notifier.addTask(datum, ApplyAction.CHANGE);
notifier.addTask(datum.key, ApplyAction.CHANGE);
}

public void loadDatum(String key) {
Expand All @@ -862,18 +864,17 @@ public void loadDatum(String key) {

private void deleteDatum(String key) {

Datum deleted = null;
Datum deleted;
try {
deleted = datums.remove(URLDecoder.decode(key, "UTF-8"));
if (deleted != null) {
raftStore.delete(deleted);
Loggers.RAFT.info("datum deleted, key: {}", key);
}
notifier.addTask(URLDecoder.decode(key, "UTF-8"), ApplyAction.DELETE);
} catch (UnsupportedEncodingException e) {
Loggers.RAFT.warn("datum key decode failed: {}", key);
}
// FIXME should we ignore the value of 'deleted'?
if (deleted != null) {
raftStore.delete(deleted);
notifier.addTask(deleted, ApplyAction.DELETE);
Loggers.RAFT.info("datum deleted, key: {}", key);
}
}

public boolean isInitialized() {
Expand All @@ -886,15 +887,15 @@ public class Notifier implements Runnable {

private BlockingQueue<Pair> tasks = new LinkedBlockingQueue<Pair>(1024 * 1024);

public void addTask(Datum datum, ApplyAction action) {
public void addTask(String datumKey, ApplyAction action) {

if (services.containsKey(datum.key) && action == ApplyAction.CHANGE) {
if (services.containsKey(datumKey) && action == ApplyAction.CHANGE) {
return;
}
if (action == ApplyAction.CHANGE) {
services.put(datum.key, StringUtils.EMPTY);
services.put(datumKey, StringUtils.EMPTY);
}
tasks.add(Pair.with(datum, action));
tasks.add(Pair.with(datumKey, action));
}

public int getTaskSize() {
Expand All @@ -914,58 +915,58 @@ public void run() {
continue;
}

Datum datum = (Datum) pair.getValue0();
String datumKey = (String) pair.getValue0();
ApplyAction action = (ApplyAction) pair.getValue1();

services.remove(datum.key);
services.remove(datumKey);

int count = 0;

if (listeners.containsKey(KeyBuilder.SERVICE_META_KEY_PREFIX)) {

if (KeyBuilder.matchServiceMetaKey(datum.key) && !KeyBuilder.matchSwitchKey(datum.key)) {
if (KeyBuilder.matchServiceMetaKey(datumKey) && !KeyBuilder.matchSwitchKey(datumKey)) {

for (RecordListener listener : listeners.get(KeyBuilder.SERVICE_META_KEY_PREFIX)) {
try {
if (action == ApplyAction.CHANGE) {
listener.onChange(datum.key, getDatum(datum.key).value);
listener.onChange(datumKey, getDatum(datumKey).value);
}

if (action == ApplyAction.DELETE) {
listener.onDelete(datum.key);
listener.onDelete(datumKey);
}
} catch (Throwable e) {
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datum.key, e);
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datumKey, e);
}
}
}
}

if (!listeners.containsKey(datum.key)) {
if (!listeners.containsKey(datumKey)) {
continue;
}

for (RecordListener listener : listeners.get(datum.key)) {
for (RecordListener listener : listeners.get(datumKey)) {

count++;

try {
if (action == ApplyAction.CHANGE) {
listener.onChange(datum.key, getDatum(datum.key).value);
listener.onChange(datumKey, getDatum(datumKey).value);
continue;
}

if (action == ApplyAction.DELETE) {
listener.onDelete(datum.key);
listener.onDelete(datumKey);
continue;
}
} catch (Throwable e) {
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datum.key, e);
Loggers.RAFT.error("[NACOS-RAFT] error while notifying listener of key: {} {}", datumKey, e);
}
}

if (Loggers.RAFT.isDebugEnabled()) {
Loggers.RAFT.debug("[NACOS-RAFT] datum change notified, key: {}, listener count: {}", datum.key, count);
Loggers.RAFT.debug("[NACOS-RAFT] datum change notified, key: {}, listener count: {}", datumKey, count);
}
} catch (Throwable e) {
Loggers.RAFT.error("[NACOS-RAFT] Error while handling notifying task", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public synchronized ConcurrentHashMap<String, Datum> loadDatums(RaftCore.Notifie
datum = readDatum(datumFile, cache.getName());
if (datum != null) {
datums.put(datum.key, datum);
notifier.addTask(datum, ApplyAction.CHANGE);
notifier.addTask(datum.key, ApplyAction.CHANGE);
}
}
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.push.ClientInfo;
import com.alibaba.nacos.naming.web.OverrideParameterRequestWrapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.util.VersionUtil;
Expand Down Expand Up @@ -116,7 +117,6 @@ public String hello(HttpServletRequest request) throws Exception {
@ResponseBody
public JSONObject srvIPXT(HttpServletRequest request) throws Exception {


String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID,
Constants.DEFAULT_NAMESPACE_ID);

Expand All @@ -137,4 +137,12 @@ public JSONObject srvIPXT(HttpServletRequest request) throws Exception {
return doSrvIPXT(namespaceId, NamingUtils.getGroupedName(dom, Constants.DEFAULT_GROUP),
agent, clusters, clientIP, udpPort, env, isCheck, app, tenant, healthyOnly);
}

@RequestMapping("/clientBeat")
public JSONObject clientBeat(HttpServletRequest request) throws Exception {
OverrideParameterRequestWrapper requestWrapper = OverrideParameterRequestWrapper.buildRequest(request);
requestWrapper.addParameter(CommonParams.SERVICE_NAME,
Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + WebUtils.required(request, "dom"));
return beat(requestWrapper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ public void updateIPs(Collection<Instance> instances, boolean ephemeral) {
stringBuilder.append(instance.toIPAddr()).append("_").append(instance.isHealthy()).append(",");
}

Loggers.EVT_LOG.info("[IP-UPDATED] service: {}, ips: {}", getName(), stringBuilder.toString());
Loggers.EVT_LOG.info("[IP-UPDATED] namespace: {}, service: {}, ips: {}",
getNamespaceId(), getName(), stringBuilder.toString());

}

Expand Down Expand Up @@ -285,7 +286,7 @@ public List<Instance> allIPs(List<String> clusters) {
for (String cluster : clusters) {
Cluster clusterObj = clusterMap.get(cluster);
if (clusterObj == null) {
throw new IllegalArgumentException("can not find cluster: " + cluster + ", service:" + getName());
continue;
}

allIPs.addAll(clusterObj.allIPs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public void updatedHealthStatus(String namespaceId, String serviceName, String s
stringBuilder.append(instance.toIPAddr()).append("_").append(instance.isHealthy()).append(",");
}

Loggers.EVT_LOG.info("[IP-UPDATED] service: {}, ips: {}", service.getName(), stringBuilder.toString());
Loggers.EVT_LOG.info("[IP-UPDATED] namespace: {}, service: {}, ips: {}",
service.getNamespaceId(), service.getName(), stringBuilder.toString());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void init() {
initClassMethod(RaftController.class);
initClassMethod(DistroController.class);
initClassMethod(OperatorController.class);
initClassMethod(ApiController.class);
}

public Method getMethod(String httpMethod, String path) {
Expand Down