1
0
Fork 0

Fix tick overflow (#8840) (#8856)

This commit is contained in:
Simon 2019-04-26 19:20:38 +02:00 committed by Jan
parent 5b66fa7aa0
commit b58bf82871
3 changed files with 117 additions and 6 deletions

View File

@ -48,7 +48,7 @@ bool SimpleAttributeEqualityMatcher::matchOne(arangodb::Index const* index,
size_t const n = node->numMembers();
for (size_t i = 0; i < n; ++i) {
auto op = node->getMember(i);
auto op = node->getMemberUnchecked(i);
if (op->type == arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ) {
TRI_ASSERT(op->numMembers() == 2);

View File

@ -136,10 +136,10 @@ class WBReader final : public rocksdb::WriteBatch::Handler {
std::map<uint64_t, uint64_t> _generators;
// max tick found
uint64_t _maxTick = 0;
uint64_t _maxHLC = 0;
uint64_t _maxTick;
uint64_t _maxHLC;
/// @brief last document removed
TRI_voc_rid_t _lastRemovedDocRid = 0;
TRI_voc_rid_t _lastRemovedDocRid;
rocksdb::SequenceNumber _startSequence; /// start of batch sequence nr
rocksdb::SequenceNumber _currentSequence; /// current sequence nr
@ -148,7 +148,11 @@ class WBReader final : public rocksdb::WriteBatch::Handler {
public:
/// @param seqs sequence number from which to count operations
explicit WBReader(std::map<uint64_t, rocksdb::SequenceNumber> const& seqs)
: _startSequence(0), _currentSequence(0) {
: _maxTick(TRI_NewTickServer()),
_maxHLC(0),
_lastRemovedDocRid(0),
_startSequence(0),
_currentSequence(0) {
for (auto const& pair : seqs) {
try {
_deltas.emplace(pair.first, Operations(pair.second));
@ -162,6 +166,7 @@ class WBReader final : public rocksdb::WriteBatch::Handler {
_startSequence = startSequence;
_currentSequence = startSequence;
_startOfBatch = true;
TRI_ASSERT(_maxTick > 0);
}
Result shutdownWBReader() {
@ -374,7 +379,7 @@ class WBReader final : public rocksdb::WriteBatch::Handler {
if (valid) {
// if no previous _maxTick set or the numeric value found is
// "near" our previous _maxTick, then we update it
if (tick > _maxTick && (_maxTick == 0 || tick - _maxTick < 2048)) {
if (tick > _maxTick && (tick - _maxTick) < 2048) {
storeMaxTick(tick);
}
}

View File

@ -0,0 +1,106 @@
/* jshint globalstrict:false, strict:false, unused: false */
/* global assertTrue, assertFalse, assertEqual */
// //////////////////////////////////////////////////////////////////////////////
// / @brief tests for traditional keygenerator
// /
// / @file
// /
// / DISCLAIMER
// /
// / Copyright 2019 ArangoDB GmbH, Cologne, Germany
// /
// / 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.
// /
// / Copyright holder is ArangoDB GmbH, Cologne, Germany
// /
// / @author Simon Grätzer
// //////////////////////////////////////////////////////////////////////////////
var db = require('@arangodb').db;
var internal = require('internal');
var jsunity = require('jsunity');
const bigNumber = 99999999999999;
function runSetup () {
'use strict';
internal.debugClearFailAt();
var c, i;
// write a documents with a large numeric key
db._drop('UnitTestsRecovery1');
c = db._create('UnitTestsRecovery1', { keyOptions: { type: 'traditional'} } );
c.save({ _key: String(bigNumber) });
for (let i = 0; i < 10000; i++) { // fill up the WAL
c.save({some: 'valuexxxxxxxxxxxxx'});
}
// write to other collection
db._drop('UnitTestsRecovery2');
c = db._create('UnitTestsRecovery2');
c.save({ value: 0 });
c.save({ value: 1 }, { waitForSync: true });
internal.debugSegfault('crashing server');
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief test suite
// //////////////////////////////////////////////////////////////////////////////
function recoverySuite () {
'use strict';
jsunity.jsUnity.attachAssertions();
return {
setUp: function () {},
tearDown: function () {},
// //////////////////////////////////////////////////////////////////////////////
// / @brief test whether the server properly handles large numeric keys
// //////////////////////////////////////////////////////////////////////////////
testCollectionKeyGenTraditional: function () {
let c = db._collection('UnitTestsRecovery1');
assertEqual(c.count(), 10001);
let d = c.save({ value: 'a'});
assertTrue(parseInt(d._key) > bigNumber + 1);
// check that the second collection is unaffected
c = db._collection('UnitTestsRecovery2');
assertEqual(c.count(), 2);
d = c.save({ value: 'a'});
assertTrue(parseInt(d._key) < bigNumber);
}
};
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief executes the test suite
// //////////////////////////////////////////////////////////////////////////////
function main (argv) {
'use strict';
if (argv[1] === 'setup') {
runSetup();
return 0;
} else {
jsunity.run(recoverySuite);
return jsunity.writeDone().status ? 0 : 1;
}
}