summaryrefslogtreecommitdiff
path: root/jstests/libs/retryable_writes_util.js
blob: 5105157eba15ab9fab9af6778f508aef6fe74387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * Utilities for testing retryable writes.
 */
var RetryableWritesUtil = (function() {
    /**
     * Returns true if the error code is retryable, assuming the command is idempotent.
     */
    function isRetryableCode(code) {
        return ErrorCodes.isNetworkError(code) || ErrorCodes.isNotMasterError(code) ||
            ErrorCodes.isWriteConcernError(code) || ErrorCodes.isInterruption(code);
    }

    const kRetryableWriteCommands =
        new Set(["delete", "findandmodify", "findAndModify", "insert", "update"]);

    /**
     * Returns true if the command name is that of a retryable write command.
     */
    function isRetryableWriteCmdName(cmdName) {
        return kRetryableWriteCommands.has(cmdName);
    }

    const kStorageEnginesWithoutDocumentLocking = new Set(["ephemeralForTest", "mmapv1"]);

    /**
     * Returns true if the given storage engine supports retryable writes (i.e. supports
     * document-level locking).
     */
    function storageEngineSupportsRetryableWrites(storageEngineName) {
        return !kStorageEnginesWithoutDocumentLocking.has(storageEngineName);
    }

    return {isRetryableCode, isRetryableWriteCmdName, storageEngineSupportsRetryableWrites};
})();