-
Notifications
You must be signed in to change notification settings - Fork 118
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
base: master
Are you sure you want to change the base?
Conversation
includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows', 'rotate'] | ||
}); | ||
``` | ||
> Notice: `pos.filename` won't be updated when `rotate` event is disabled |
There was a problem hiding this comment.
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.
Thanks for your PR, can you add some tests for this feature ? |
Yes, I have just add a test case for this feature, plz have a look. |
…previous code, it will got wrong binlog_position event
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 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 |
// Add before `event === undefined || event._filtered === true`, so that all nextPosition can be caught | ||
if(event){ | ||
var changed = false; | ||
if(event.getTypeName() == 'Rotate'){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
orerror
event. Each handler function accepts one argument.
@numtel thanks for your comments, I'll check my code more carefully. |
add a way to subscribe current binlog position