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

add subscribePosition to options and use mysql.format #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

add subscribePosition to options and use mysql.format #65

wants to merge 4 commits into from

Conversation

flarestart
Copy link

add a way to subscribe current binlog position

includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows', 'rotate']
});
```
> Notice: `pos.filename` won't be updated when `rotate` event is disabled
Copy link
Owner

Choose a reason for hiding this comment

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

We should always receive rotate event when we subscribed position event. Otherwise, it sounds like a bug.

@nevill
Copy link
Owner

nevill commented Aug 13, 2017

Thanks for your PR, can you add some tests for this feature ?

@flarestart
Copy link
Author

Yes, I have just add a test case for this feature, plz have a look.

…previous code, it will got wrong binlog_position event
@numtel
Copy link
Collaborator

numtel commented Aug 23, 2017

This PR is adding a new feature without explicitly stating the bug that necessitated it. In the current implementation, if a binlog event occurs that is filtered, (due to not being in the includeEvents option) there is no update to the binlogName and binlogNextPos property values.

This approach of adding another option introduces too much code to solve the problem. Instead, make those existing properties update before the filtering occurs:

if(event === undefined || event._filtered === true) return;

And then just always emit a position event, even for filtered events. The binlog_ prefix is unneeded here. Since the position and filename values are properties of the ZongJi instance object, passing these values as another object on every position update is unnecessary bloat. I recommend having no arguments for this position event. Event handlers may reference the values on the ZongJi instance.

// Add before `event === undefined || event._filtered === true`, so that all nextPosition can be caught
if(event){
var changed = false;
if(event.getTypeName() == 'Rotate'){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and many other places, ==, != is used where ===, !== should be used.

Copy link
Author

Choose a reason for hiding this comment

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

just like you say, '==' and '!=' is not strict. :)

return;
}
// newer position should bigger than previous position
var lastPos;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is some spaghetti logic. If you're testing that the position increases with each event, just do it directly.

var lastPos = null;
zongji.on('position', function() {
  lastPos !== null && test.ok(zongji.binlogNextPos <= lastPos);
  lastPos = zongji.binlogNextPos;
});

You might also want to test that there are the correct number of position events.

Copy link
Author

Choose a reason for hiding this comment

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

I have a consider of check the number of position events, but I'm not sure if the binlog event is triggered as provided number.

})
}, 1000);
},
subscribe_position: function (test) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the difference between these tests?

@@ -23,6 +23,26 @@ zongji.start({
});
```

## Subscribe Binary Log Position
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of a section here, create a section just above **Options Available:** for **Events Emitted:** and take out the current text for the on method to bind handlers:

Add a listener to the binlog or error event. Each handler function accepts one argument.

@flarestart
Copy link
Author

@numtel thanks for your comments, I'll check my code more carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants