This commit is contained in:
parent
e06f8fafee
commit
c0c82564c4
|
@ -5,7 +5,7 @@ pingInterval: 300
|
|||
flushInterval: 30
|
||||
restartTimeout: 30
|
||||
queueFlushDelay: 200
|
||||
maxBulkLog: 100
|
||||
maxBulkLog: 25
|
||||
upperCaseTable: true
|
||||
serverId: 1
|
||||
srcDb:
|
||||
|
|
40
mylogger.js
40
mylogger.js
|
@ -541,9 +541,9 @@ module.exports = class MyLogger {
|
|||
|
||||
if (!changes.length) return;
|
||||
|
||||
if (this.debug) {
|
||||
console.debug('Log:'.blue, `[${action}]`.yellow, tableName);
|
||||
}
|
||||
if (this.debug)
|
||||
console.debug('Evt:'.blue,
|
||||
`[${action}]`[actionColor[action]], `${tableName}: ${changes.length} changes`);
|
||||
|
||||
this.queue.push({
|
||||
tableInfo,
|
||||
|
@ -562,31 +562,36 @@ module.exports = class MyLogger {
|
|||
async flushQueue() {
|
||||
if (this.isFlushed || this.isFlushing || !this.isOk) return;
|
||||
this.isFlushing = true;
|
||||
const {conf, db} = this;
|
||||
const {conf, db, queue} = this;
|
||||
let op;
|
||||
|
||||
try {
|
||||
if (this.queue.length) {
|
||||
if (queue.length) {
|
||||
do {
|
||||
let appliedOps;
|
||||
const ops = [];
|
||||
let txStarted;
|
||||
try {
|
||||
await db.query('START TRANSACTION');
|
||||
appliedOps = [];
|
||||
txStarted = true;
|
||||
|
||||
for (let i = 0; i < conf.maxBulkLog && this.queue.length; i++) {
|
||||
op = this.queue.shift();
|
||||
appliedOps.push(op);
|
||||
for (let i = 0; i < conf.maxBulkLog && queue.length; i++) {
|
||||
op = queue.shift();
|
||||
ops.push(op);
|
||||
await this.applyOp(op);
|
||||
}
|
||||
|
||||
this.debug('Queue', `applied: ${ops.length}, remaining: ${queue.length}`);
|
||||
await this.savePosition(op.binlogName, op.evt.nextPosition)
|
||||
await db.query('COMMIT');
|
||||
} catch(err) {
|
||||
this.queue = appliedOps.concat(this.queue);
|
||||
await db.query('ROLLBACK');
|
||||
queue.unshift(...ops);
|
||||
if (txStarted)
|
||||
try {
|
||||
await db.query('ROLLBACK');
|
||||
} catch (err) {}
|
||||
throw err;
|
||||
}
|
||||
} while (this.queue.length);
|
||||
} while (queue.length);
|
||||
} else {
|
||||
await this.savePosition(this.binlogName, this.binlogPosition);
|
||||
}
|
||||
|
@ -638,6 +643,9 @@ module.exports = class MyLogger {
|
|||
: modelId;
|
||||
|
||||
let deleteRow;
|
||||
if (this.debug)
|
||||
console.debug('Log:'.blue,
|
||||
`[${action}]`[actionColor[action]], `${modelName}: ${modelId}`);
|
||||
|
||||
try {
|
||||
if (isDelete) {
|
||||
|
@ -723,6 +731,12 @@ const actions = {
|
|||
deleterows: 'delete'
|
||||
};
|
||||
|
||||
const actionColor = {
|
||||
insert: 'green',
|
||||
update: 'yellow',
|
||||
delete: 'red'
|
||||
};
|
||||
|
||||
function toUpperCamelCase(str) {
|
||||
str = str.replace(/[-_ ][a-z]/g,
|
||||
match => match.charAt(1).toUpperCase());
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "mylogger",
|
||||
"version": "0.1.12",
|
||||
"version": "0.1.13",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "mylogger",
|
||||
"version": "0.1.12",
|
||||
"version": "0.1.13",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mylogger",
|
||||
"version": "0.1.12",
|
||||
"version": "0.1.13",
|
||||
"author": "Verdnatura Levante SL",
|
||||
"description": "MySQL and MariaDB logger using binary log",
|
||||
"license": "GPL-3.0",
|
||||
|
|
Loading…
Reference in New Issue