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

feat: ignore event whose modify time is out of date #337

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -111,11 +111,20 @@ public void close() {
public void childEvent(CuratorFramework client, TreeCacheEvent event)
throws Exception {
TreeCacheEvent.Type eventType = event.getType();
if (eventType == NODE_ADDED || eventType == NODE_REMOVED
|| eventType == NODE_UPDATED) {
this.publisher
.publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
if (eventType != NODE_ADDED && eventType != NODE_REMOVED
&& eventType != NODE_UPDATED) {
return;
}

// ignore event whose modify time is out of date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "out of date"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every exist node in zookeeper will trigger a add event. Maybe we can ignore these add event for we have get all data when start up. That's my test:

    @Override
    public void childEvent(CuratorFramework client, TreeCacheEvent event)
            throws Exception {
        TreeCacheEvent.Type eventType = event.getType();
        if (eventType != NODE_ADDED && eventType != NODE_REMOVED
                && eventType != NODE_UPDATED) {
            return;
        }

        String path = event.getData().getPath();
        long currentTime = System.currentTimeMillis();
        long validTime = currentTime - TimeUnit.MINUTES.toMillis(1);
        if (eventType == NODE_ADDED
                && event.getData().getStat().getMtime() < validTime) {
            log.info("currentTime:{},dataModifyTime:{},difference:{} second", currentTime, event.getData().getStat().getMtime(),
                    (currentTime - event.getData().getStat().getMtime()) / 1000);
            return;
        }
}

And loginfo is below

currentTime:1737443876150,dataModifyTime:1709799075357,difference:27644800 second
currentTime:1737443876152,dataModifyTime:1701227490791,difference:36216385 second
currentTime:1737443876153,dataModifyTime:1672281805849,difference:65162070 second
currentTime:1737443876154,dataModifyTime:1734484683314,difference:2959192 second
currentTime:1737443876154,dataModifyTime:1734404672179,difference:3039203 second
currentTime:1737443876155,dataModifyTime:1733982210881,difference:3461665 second

String path = event.getData().getPath();
long validTime = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be configurable. Can you say why you chose 1 minute as the definition of out of date?

if (eventType == NODE_ADDED
&& event.getData().getStat().getMtime() < validTime) {
return;
}

this.publisher.publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
}

public String getEventDesc(TreeCacheEvent event) {
Expand Down