// SERVER-22599 Test behavior of in-memory storage engine with full cache.
|
(function() {
|
'use strict';
|
|
Random.setRandomSeed();
|
|
// Return array of approximately 1kB worth of random numbers.
|
function randomArray() {
|
var arr = [];
|
for (var j = 0; j < 85; j++)
|
arr[j] = Random.rand();
|
return arr;
|
}
|
|
// Return a document of approximately 10kB in size with arrays of random numbers.
|
function randomDoc() {
|
var doc = {};
|
for (var c of "abcdefghij")
|
doc[c] = randomArray();
|
return doc;
|
}
|
|
// Return an array with random documents totalling about 1Mb.
|
function randomBatch(batchSize) {
|
var batch = [];
|
for (var j = 0; j < batchSize; j++)
|
batch[j] = randomDoc();
|
return batch;
|
}
|
|
const cacheMB = 20;
|
const cacheKB = 1024 * cacheMB;
|
const docSizeKB = Object.bsonsize(randomDoc()) / 1024;
|
const batchSize = 100;
|
const batch = randomBatch(batchSize);
|
var mongod = MongoRunner.runMongod({
|
storageEngine: 'inMemory',
|
inMemoryEngineConfigString: 'cache_size=' + cacheMB + "M,",
|
});
|
assert.neq(null, mongod, "mongod failed to started up with --inMemoryEngineConfigString");
|
var db = mongod.getDB("test");
|
var t = db.large;
|
|
// Insert documents until full.
|
var res;
|
var count = 0;
|
for (var j = 0; j < 1000; j++) {
|
res = t.insert(batch);
|
assert.gte(res.nInserted, 0, tojson(res));
|
count += res.nInserted;
|
if (res.hasErrors())
|
break;
|
assert.eq(res.nInserted, batchSize, tojson(res));
|
print("Inserted " + count + " documents");
|
}
|
|
// Indexes are sufficiently large that it should be impossible to add a new one.
|
while(true) {
|
assert.commandFailedWithCode(t.createIndex({a: 1}), ErrorCodes.ExceededMemoryLimit);
|
assert.commandFailedWithCode(t.createIndex({a: 1, _id:1}), ErrorCodes.ExceededMemoryLimit);
|
}
|
|
}());
|