diamond源码阅读-diamond-server
2016-10-26 18:14
302 查看
diamond-server
1 增加一条数据 /diamond-server/admin.do?method=postConfig
1.1 调用 this.configService.addConfigInfo(dataId, group, content);
public void addConfigInfo(String dataId, String group, String content) { ConfigInfo configInfo = new ConfigInfo(dataId, group, content);//md5加密content // 保存顺序:先数据库,再磁盘 try { checkParameter(dataId, group, content);//参数校验 persistService.addConfigInfo(configInfo);//插入数据库 // 切记更新缓存 this.contentMD5Cache.put(generateMD5CacheKey(dataId, group), configInfo.getMd5());// key = group + "/" + dataId value=MD5 diskService.saveToDisk(configInfo);//保存到文件 // 通知其他节点() HTTP 方式通知 this.notifyOtherNodes(dataId, group);//http://ip:port/diamond-server/notify.do?method=notifyConfigInfo&dataId=" + dataId + "&group=" + group } catch (Exception e) { log.error("保存ConfigInfo失败", e); throw new ConfigServiceException(e); } }
1.2 其他节点接收到信息后
this.configService.loadConfigInfoToDisk(dataId, group);public void loadConfigInfoToDisk(String dataId, String group) { try { ConfigInfo configInfo = this.persistService.findConfigInfo(dataId, group);//数据库读取配置 if (configInfo != null) { this.contentMD5Cache.put(generateMD5CacheKey(dataId, group), configInfo.getMd5());//保存到内存 key = group + "/" + dataId value=MD5 this.diskService.saveToDisk(configInfo);//保存到文件 } else { // 删除文件 this.contentMD5Cache.remove(generateMD5CacheKey(dataId, group)); this.diskService.removeConfigInfo(dataId, group); } } catch (Exception e) { log.error("保存ConfigInfo到磁盘失败", e); throw new ConfigServiceException(e); } }
1.3 删除同样是修改数据库,修改内存,修改本地文件,通知其他节点
2 定时任务TimerTaskService DumpConfigInfoTask
如果通过http请求并没有通知到其他实例,通过定时任务保证从数据库读取信息,更新缓存信息和写入硬盘文件相关文章推荐
- diamond源码阅读-diamond-server
- diamond源码阅读-diamond-server
- 分布式文件系统KFS源码阅读与分析(三):RPC实现机制(MetaServer端)
- [hadoop源码阅读][6]-org.apache.hadoop.ipc-ipc.server
- diamond源码阅读-diamond-client
- diamond源码阅读-循环探测配置信息是否变化rotateCheckConfigInfo
- 如何阅读别人的源码项目包(ASP.NET+SQL SERVER)
- diamond源码阅读-目录监控
- diamond源码阅读-目录监控
- Netty源码阅读(一) ServerBootstrap启动
- diamond源码阅读-获取服务器列表
- zabbix源码阅读——zabbix_server
- Tomcat源码阅读(四)Server
- Go语言Http Server源码阅读
- diamond源码阅读-循环探测配置信息是否变化rotateCheckConfigInfo
- 分布式文件系统KFS源码阅读与分析(三):RPC实现机制(MetaServer端)
- webpy源码阅读(2)——CherryPyWSGIServer
- 淘宝动态配置diamond-server 源码讲解
- diamond源码阅读-获取服务器列表
- diamond源码阅读-目录监控