Files
mongo/jstests/libs/release_memory_util.js
Ivan Fefer 7c1f71ceaf SERVER-99172 Support forceSpill for DocumentSourceSort (#34098)
Co-authored-by: Gregory Noma <gregory.noma@gmail.com>
GitOrigin-RevId: ae11087f1dc7ebf7d2d1f189ed4fef3d26cb7914
2025-04-10 04:24:19 +00:00

46 lines
1.6 KiB
JavaScript

import {FixtureHelpers} from "jstests/libs/fixture_helpers.js";
/**
* Asserts that releaseMemory command failed for a given cursor with the appropriate code.
*/
export function assertReleaseMemoryFailedWithCode(result, cursorId, codes) {
if (!Array.isArray(codes)) {
codes = [codes];
}
if (!result.hasOwnProperty("cursorsWithErrors")) {
doassert("Command result does not contain 'cursorsWithErrors' field: " + tojson(result));
}
for (const releaseMemoryError of result.cursorsWithErrors) {
if (releaseMemoryError.cursorId.compare(cursorId) === 0) {
assert.contains(
releaseMemoryError.status.code,
codes,
"the following release memory error contains an unexpected error code: " +
tojson(releaseMemoryError));
return;
}
}
doassert("Cursor " + tojsononeline(cursorId) +
" did not fail during release memory. Full command result: " + tojson(result));
}
/**
* Accumulate metric from a server status
*/
export function accumulateServerStatusMetric(db, metricGetter) {
return retryOnRetryableError(() => {
let total = 0;
FixtureHelpers.mapOnEachShardNode({
db: db,
func: (db) => {
const serverStatus = db.serverStatus();
if (!serverStatus.hasOwnProperty("metrics")) {
return;
}
total += metricGetter(serverStatus.metrics);
}
});
return total;
}, 10, 100, [ErrorCodes.InterruptedDueToStorageChange]);
}