Skip to content

Commit

Permalink
Merge pull request #231 from cloudant/fix-concurrent-backups
Browse files Browse the repository at this point in the history
Fix concurrent backups
  • Loading branch information
smithsz authored Jun 14, 2018
2 parents 05e8f4f + cc2e14b commit 07e83c7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- [FIXED] Concurrent database backups use the same default log file.
- [FIXED] IAM token URL override option.

# 2.3.0 (2018-05-22)
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

const backupFull = require('./includes/backup.js');
const defaults = require('./includes/config.js').apiDefaults();
const defaults = require('./includes/config.js').apiDefaults;
const error = require('./includes/error.js');
const request = require('./includes/request.js');
const restoreInternal = require('./includes/restore.js');
Expand Down Expand Up @@ -198,7 +198,7 @@ module.exports = {
if (callback) callback(err);
});

opts = Object.assign({}, defaults, opts);
opts = Object.assign({}, defaults(), opts);

const ee = new events.EventEmitter();

Expand Down Expand Up @@ -305,7 +305,7 @@ module.exports = {
opts = {};
}
validateArgs(targetUrl, opts, callback);
opts = Object.assign({}, defaults, opts);
opts = Object.assign({}, defaults(), opts);

const ee = new events.EventEmitter();

Expand Down
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions test/ci_concurrent_backups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright © 2018 IBM Corp. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* global describe it */
'use strict';

const fs = require('fs');
const readline = require('readline');
const u = require('./citestutils.js');
const uuid = require('uuid/v4');

const params = { useApi: true };

describe(u.scenario('Concurrent database backups', params), function() {
it('should run concurrent API database backups correctly #slower', function(done) {
// Allow up to 900 s to backup and compare (it should be much faster)!
u.setTimeout(this, 900);

var doneCount = 0;
var doneErr;
var finished = function(err) {
doneCount++;
if (doneCount === 2) {
done(doneErr || err);
}
doneErr = err;
};

var checkForEmptyBatches = function(fileName, cb) {
var foundEmptyBatch = false;

var rd = readline.createInterface({
input: fs.createReadStream(fileName),
output: fs.createWriteStream('/dev/null'),
terminal: false
});

rd.on('line', function(line) {
if (JSON.parse(line).length === 0) {
// Note: Empty batch arrays indicate that the running backup is
// incorrectly sharing a log file with another ongoing backup job.
foundEmptyBatch = true;
}
});

rd.on('close', function() {
if (foundEmptyBatch) {
cb(new Error(`Log file '${fileName}' contains empty batches`));
} else {
cb();
}
});
};

// [1] Run 'largedb2g' database backup
const actualBackup1 = `./${uuid()}`;
const output1 = fs.createWriteStream(actualBackup1);
output1.on('open', function() {
u.testBackup(params, 'largedb2g', output1, function(err) {
if (err) {
finished(err);
} else {
checkForEmptyBatches(actualBackup1, finished);
}
});
});

// [2] Run 'largedb1g' database backup
const actualBackup2 = `./${uuid()}`;
const output2 = fs.createWriteStream(actualBackup2);
output2.on('open', function() {
u.testBackup(params, 'largedb1g', output2, function(err) {
if (err) {
finished(err);
} else {
checkForEmptyBatches(actualBackup2, finished);
}
});
});
});
});

0 comments on commit 07e83c7

Please sign in to comment.