Compare commits
3 Commits
developmen
...
bugfix/ARS
Author | SHA1 | Date |
---|---|---|
Taylor McKinnon | bbd926bb09 | |
Taylor McKinnon | 03989ecc4d | |
Taylor McKinnon | e140b63f6a |
|
@ -1,6 +1,6 @@
|
||||||
import errors, { ArsenalError } from '../errors';
|
import errors, { ArsenalError } from '../errors';
|
||||||
import { Version } from './Version';
|
import { Version } from './Version';
|
||||||
import { generateVersionId as genVID } from './VersionID';
|
import { generateVersionId as genVID, getInfVid } from './VersionID';
|
||||||
import WriteCache from './WriteCache';
|
import WriteCache from './WriteCache';
|
||||||
import WriteGatheringManager from './WriteGatheringManager';
|
import WriteGatheringManager from './WriteGatheringManager';
|
||||||
|
|
||||||
|
@ -381,10 +381,13 @@ export default class VersioningRequestProcessor {
|
||||||
const versionKey = formatVersionKey(request.key, versionId);
|
const versionKey = formatVersionKey(request.key, versionId);
|
||||||
const ops = [{ key: versionKey, value: request.value }];
|
const ops = [{ key: versionKey, value: request.value }];
|
||||||
if (data === undefined ||
|
if (data === undefined ||
|
||||||
(Version.from(data).getVersionId() ?? '') >= versionId) {
|
(Version.from(data).getVersionId() ?? '') >= versionId ||
|
||||||
|
(versionId === getInfVid(this.replicationGroupId) && !Version.from(data).getVersionId())) {
|
||||||
// master does not exist or is not newer than put
|
// master does not exist or is not newer than put
|
||||||
// version and needs to be updated as well.
|
// version and needs to be updated as well.
|
||||||
// Note that older versions have a greater version ID.
|
// Note that older versions have a greater version ID.
|
||||||
|
// If an infinite version ID is used and the master does not have a versionId,
|
||||||
|
// then the master is updated.
|
||||||
ops.push({ key: request.key, value: request.value });
|
ops.push({ key: request.key, value: request.value });
|
||||||
}
|
}
|
||||||
return callback(null, ops, versionId);
|
return callback(null, ops, versionId);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
const { getInfVid } = require('../../../lib/versioning/VersionID');
|
||||||
|
|
||||||
const Version = require('../../../lib/versioning/Version').Version;
|
const Version = require('../../../lib/versioning/Version').Version;
|
||||||
|
|
||||||
|
@ -219,4 +220,53 @@ describe('test VSP', () => {
|
||||||
}],
|
}],
|
||||||
done);
|
done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update master if a infinite versionId is passed and the master does not have a versionId', done => {
|
||||||
|
async.waterfall([next => {
|
||||||
|
const request = {
|
||||||
|
db: 'foo',
|
||||||
|
key: 'bar',
|
||||||
|
value: '{"qux":"quz"}',
|
||||||
|
options: { versioning: false },
|
||||||
|
};
|
||||||
|
vsp.put(request, logger, next);
|
||||||
|
},
|
||||||
|
(res, next) => {
|
||||||
|
// should overwrite the master
|
||||||
|
const request = {
|
||||||
|
db: 'foo',
|
||||||
|
key: 'bar',
|
||||||
|
value: '{"qux":"quz2"}',
|
||||||
|
options: { versioning: true, versionId: getInfVid('PARIS') },
|
||||||
|
};
|
||||||
|
vsp.put(request, logger, next);
|
||||||
|
},
|
||||||
|
(_, next) => {
|
||||||
|
// fetch master
|
||||||
|
const request = {
|
||||||
|
db: 'foo',
|
||||||
|
key: 'bar',
|
||||||
|
};
|
||||||
|
vsp.get(request, logger, next);
|
||||||
|
},
|
||||||
|
(res, next) => {
|
||||||
|
// check that master has been updated
|
||||||
|
assert.strictEqual(JSON.parse(res).qux, 'quz2');
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
(next) => {
|
||||||
|
// check that the version is accessible
|
||||||
|
const request = {
|
||||||
|
db: 'foo',
|
||||||
|
key: 'bar',
|
||||||
|
versionId: getInfVid('PARIS'),
|
||||||
|
};
|
||||||
|
vsp.get(request, logger, next);
|
||||||
|
},
|
||||||
|
(res, next) => {
|
||||||
|
assert.strictEqual(JSON.parse(res).qux, 'quz2');
|
||||||
|
next();
|
||||||
|
}],
|
||||||
|
done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue