跑單測用例的時候,以前執行成功的用例,運行時控制台仍然會報 dubbo 相關的錯誤:
Failed to save registry store file, cause: Can not lock the registry cache file
2016-03-22 17:16:05,493 [DubboSaveRegistryCache-thread-1] WARN com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry - [DUBBO] Failed to save registry store file, cause: Can not lock the registry cache file /Users/baidu/.dubbo/dubbo-registry-1*.9*.3*.3*.cache, ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties, dubbo version: 2.5.3, current host: 1*.9*.3*.3*.
java.io.IOException: Can not lock the registry cache file /Users/baidu/.dubbo/dubbo-registry-1*.9*.3*.3*.cache, ignore and retry later, maybe multi java process use the file, please config: dubbo.registry.file=xxx.properties
at com.alibaba.dubbo.registry.support.AbstractRegistry.doSaveProperties(AbstractRegistry.java:193) ~[dubbo-2.5.3.jar:2.5.3]
at com.alibaba.dubbo.registry.support.AbstractRegistry$SaveProperties.run(AbstractRegistry.java:150) [dubbo-2.5.3.jar:2.5.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
Dubbo在保存服務列表時失敗,Can not lock the registry cache file /Users/baidu/.dubbo/dubbo-registry-1*.9*.3*.3*.cache,拿不到文件鎖,無法保存服務列表。
Dubbo通過注冊中心發現服務,發現的服務Dubbo同時也會保存到本地緩存一份,緩存的好處有很多,比如不需要每次使用的時候都通過注冊中心獲取,注冊中心不可用了,不影響消費端的調用,因為本地緩存了一份服務提供者列表。Dubbo本地緩存默認采用的文件,會根據注冊中心自動在當前用戶目錄下生成一個緩存文件,類似/home/newad/.dubbo/dubbo-registry-*.*.*.*.cache,星號表示注冊中心的IP地址,當同一台機器上同時啟動多個進程,就會出現多個進程爭奪此文件的寫入權限,觖此問題的方法也很簡單,日志里面都說了重新配置一下這個緩存文件就可以了。
我的解決辦法是進入到目錄:/Users/baidu/.dubbo/ 下,把文件重新命名一下,或者刪除,就可以了。