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

LocalRegistryHelper#checkModified returns true even if the file has not changed #412

Closed
ScienJus opened this issue Dec 11, 2018 · 6 comments · Fixed by #413
Closed

LocalRegistryHelper#checkModified returns true even if the file has not changed #412

ScienJus opened this issue Dec 11, 2018 · 6 comments · Fixed by #413
Labels
bug Something isn't working
Milestone

Comments

@ScienJus
Copy link
Member

ScienJus commented Dec 11, 2018

Describe the bug

/**
 * Check file's digest.
 *
 * @param address    the address
 * @param lastDigest the update digest
 * @return true被修改,false未被修改
 */
public static boolean checkModified(String address, String lastDigest) {
    // 检查文件是否被修改了
    String newDigest = calMD5Checksum(address);
    return StringUtils.equals(newDigest, lastDigest);
}

这个方法在修改时间戳变为 md5 之后,逻辑是否改变了?

Environment

  • SOFARPC version: the master branch
@leizhiyuan
Copy link
Contributor

这个原始的需求确实也是希望在文件内容发生变更的时候,进行重载,以前的实现是根据时间,这个确实不太合理。你遇到了啥问题么?

@ScienJus
Copy link
Member Author

@leizhiyuan 最后的返回值是不是应该是 !StringUtils.equals(newDigest, lastDigest);

@leizhiyuan
Copy link
Contributor

是的。com.alipay.sofa.rpc.registry.local.LocalRegistryHelperTest#testModify 测试用例没有覆盖到。我改一下。

@leizhiyuan leizhiyuan added the bug Something isn't working label Dec 11, 2018
@ScienJus
Copy link
Member Author

@leizhiyuan 我来吧,刚才补测试验证了,直接提交了…

@leizhiyuan
Copy link
Contributor

@ScienJus 好的,辛苦~ 提到master即可

@ScienJus
Copy link
Member Author

ScienJus commented Dec 11, 2018

@leizhiyuan 有一些其他疑问,顺便在这里问下:

  1. LocalRegistry#init 中,最开始并没有从文件中读取 Provider 信息,但是依旧计算了 lastDigest,假设程序启动时本地已经有了一个文件(例如程序故障重启了),因为 lastDigest 会一直和 init 时的相同,那么在下次更新之前定时 task 是不是都不会读取这个文件?(在修复这个问题之后)
  2. 如果上文成立的话,在 init 时不去计算 lastDigest 比较好,还是在 init 的时候同步拉取一次所有 Provider 信息比较好?个人倾向于第二种?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants