Commit 96fdf123 by 房斌

加日志

parent 02794a27
...@@ -114,7 +114,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -114,7 +114,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
long startTime=System.currentTimeMillis(); //获取开始时间 long startTime=System.currentTimeMillis(); //获取开始时间
detail = checkNoticed(detail, str, checks, sessionExpireMs);//通过通知进行检查 detail = checkNoticed(detail, str, checks, sessionExpireMs);//通过通知进行检查
long endTime=System.currentTimeMillis(); //获取结束时间 long endTime=System.currentTimeMillis(); //获取结束时间
logger.info(" check time ip:{},name:{} ",ip,name,(endTime-startTime)+"ms"); logger.info(" check time ip:{},name:{} ,time:{} ",ip,name,(endTime-startTime)+"ms");
if (checks.size() > 0) { // 处理 没有接到通知的场景 if (checks.size() > 0) { // 处理 没有接到通知的场景
for (URL check : checks) { for (URL check : checks) {
...@@ -258,7 +258,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -258,7 +258,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
allService.put(url.getServiceKey(), url); allService.put(url.getServiceKey(), url);
} }
while (checks.size() > 0&&(System.currentTimeMillis()-beginTime<time)) { while (checks.size() > 0&&(System.currentTimeMillis()-beginTime<time)) { // 循环了一次
if (check) { if (check) {
//根据通知去判断结果 //根据通知去判断结果
for (Map.Entry<String, Boolean> entry : checkContent.entrySet()) {//循环遍历信号 for (Map.Entry<String, Boolean> entry : checkContent.entrySet()) {//循环遍历信号
...@@ -268,7 +268,10 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -268,7 +268,10 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
entry.setValue(true);//查找完后不再查找 entry.setValue(true);//查找完后不再查找
if (StringUtil.isNotEmpty(url.getAddress()) && StringUtil.isNotEmpty(name)) { if (StringUtil.isNotEmpty(url.getAddress()) && StringUtil.isNotEmpty(name)) {
List<String> check = null; List<String> check = null;
logger.info("CheckDubbo begin url:{},name:{},time:{}",url,name, " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
check = checkService(url, checks, detail, str);//检查服务去 check = checkService(url, checks, detail, str);//检查服务去
logger.info("CheckDubbo end url:{},name:{},time:{}",url,name, " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
checks.remove(url);//检查完后移除 checks.remove(url);//检查完后移除
logger.info("remove------------------- url!!!!!"+url.getServiceInterface()); logger.info("remove------------------- url!!!!!"+url.getServiceInterface());
......
...@@ -87,7 +87,7 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -87,7 +87,7 @@ public class RegistryServerSync extends Observable implements InitializingBean,
// NOTE: group and version in empty protocol is * // NOTE: group and version in empty protocol is *
if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {//移除带版本的key if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {//移除带版本的key
// services.remove(url.getServiceKey()); // services.remove(url.getServiceKey());
removeAndNotice(services,url.getServiceKey()); removeAndNotice(services,url.getServiceKey(),"1");
} else { } else {
for (Map.Entry<String, Map<String, URL>> serviceEntry : services.entrySet()) { for (Map.Entry<String, Map<String, URL>> serviceEntry : services.entrySet()) {
String service = serviceEntry.getKey(); String service = serviceEntry.getKey();
...@@ -95,7 +95,7 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -95,7 +95,7 @@ public class RegistryServerSync extends Observable implements InitializingBean,
&& (Constants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, Tool.getGroup(service))) && (Constants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, Tool.getGroup(service)))
&& (Constants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, Tool.getVersion(service)))) { && (Constants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, Tool.getVersion(service)))) {
services.remove(service);//如果版本和分组匹配就干掉 services.remove(service);//如果版本和分组匹配就干掉
removeAndNotice(services,service); removeAndNotice(services,service,"2");
} }
} }
} }
...@@ -129,18 +129,18 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -129,18 +129,18 @@ public class RegistryServerSync extends Observable implements InitializingBean,
if (categories.size() == 0) { if (categories.size() == 0) {
return; return;
} }
for (Map.Entry<String, Map<String, Map<String, URL>>> categoryEntry : categories.entrySet()) { for (Map.Entry<String, Map<String, Map<String, URL>>> categoryEntry : categories.entrySet()) {//categories带表这次通知的数据
String category = categoryEntry.getKey(); String category = categoryEntry.getKey();
ConcurrentMap<String, Map<String, URL>> services = registryCache.get(category); ConcurrentMap<String, Map<String, URL>> services = registryCache.get(category);//services代表内存中的数据
if (services == null) { if (services == null) {//和内存中得对比
services = new ConcurrentHashMap<String, Map<String, URL>>(); services = new ConcurrentHashMap<String, Map<String, URL>>();
registryCache.put(category, services); registryCache.put(category, services);
} else {// Fix map can not be cleared when service is unregistered: when a unique “group/service:version” service is unregistered, but we still have the same services with different version or group, so empty protocols can not be invoked. } else {// Fix map can not be cleared when service is unregistered: when a unique “group/service:version” service is unregistered, but we still have the same services with different version or group, so empty protocols can not be invoked.
Set<String> keys = new HashSet<String>(services.keySet()); Set<String> keys = new HashSet<String>(services.keySet());
for (String key : keys) { //接口 for (String key : keys) { //内存中的数据
if (Tool.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) { if (Tool.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) {//内存中的数据,不在目前通知的全量数据里,就把内存中的数据移除
// services.remove(key); // services.remove(key);
removeAndNotice(services,key); removeAndNotice(services,key,"3");
} }
} }
} }
...@@ -183,8 +183,11 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -183,8 +183,11 @@ public class RegistryServerSync extends Observable implements InitializingBean,
} }
} }
public void removeAndNotice(ConcurrentMap<String, Map<String, URL>> services,String serviceKey){ public void removeAndNotice(ConcurrentMap<String, Map<String, URL>> services,String serviceKey,String step){
logger.info("collection services:{},servicekey:{},step:{},time:{}",JSON.toJSON(services),serviceKey,step, " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
services.remove(serviceKey); services.remove(serviceKey);
logger.info("collection services:{},servicekey:{},step:{},remove time:{}",JSON.toJSON(services),serviceKey,step, " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
if(signal) { if(signal) {
this.setChanged(); this.setChanged();
this.notifyObservers(serviceKey); this.notifyObservers(serviceKey);
......
...@@ -7,6 +7,8 @@ import com.secoo.mall.gracefulshutdown.monitor.dubbo.Constants.Constants; ...@@ -7,6 +7,8 @@ import com.secoo.mall.gracefulshutdown.monitor.dubbo.Constants.Constants;
import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.ProviderService; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.ProviderService;
import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -15,6 +17,7 @@ import java.util.Map.Entry; ...@@ -15,6 +17,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
public class ProviderServiceImpl extends AbstractService implements ProviderService { public class ProviderServiceImpl extends AbstractService implements ProviderService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public ProviderServiceImpl(RegistryServerSync sync) { public ProviderServiceImpl(RegistryServerSync sync) {
super(sync); super(sync);
} }
...@@ -34,6 +37,7 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ ...@@ -34,6 +37,7 @@ public class ProviderServiceImpl extends AbstractService implements ProviderServ
for (Entry<String, URL> e2 : value.entrySet()) { for (Entry<String, URL> e2 : value.entrySet()) {
URL u = e2.getValue(); URL u = e2.getValue();
if (address.equals(u.getAddress())&&u.getParameter("application").equals(name)) { if (address.equals(u.getAddress())&&u.getParameter("application").equals(name)) {
logger.info("findServicesByAddressAndName is exist address:{},application:{},key:{}",address,name,e1.getKey());
ret.add(e1.getKey()); ret.add(e1.getKey());
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment