Repository: valkey-io/valkey
File: src/debug.c (C)

Code before:
            "    The optional argument (0 by default) sets the level of detail",
            "CLIENT-EVICTION",
            "    Show low level client eviction pools info (maxmemory-clients).",
            "PAUSE-CRON <0|1>",
            "    Stop periodic cron job processing.",
            "REPLYBUFFER PEAK-RESET-TIME <NEVER||RESET|time>",
            "    Sets the time (in milliseconds) to wait between client reply buffer peak resets.",
            "    In case NEVER is provided the last observed peak will never be reset",
            "    In case RESET is provided the peak reset time will be restored to the default value",
            "REPLYBUFFER RESIZING <0|1>",
            "    Enable or disable the reply buffer resize cron job",
            "PAUSE-AFTER-FORK <0|1>",
            "    Stop the server's main process after fork.",
            "DELAY-RDB-CLIENT-FREE-SECOND <seconds>",
            "    Grace period in seconds for replica main channel to establish psync.",
            "DICT-RESIZING <0|1>",
            "    Enable or disable the main dict and expire dict resizing.",
            "CLIENT-ENFORCE-REPLY-LIST <0|1>",
            "    When set to 1, it enforces the use of the client reply list directly",
            "    and avoids using the client's static buffer.",
            "SLOTMIGRATION PREVENT-PAUSE <0|1>",
            "    When set to 1, slot migrations will be prevented from pausing on the source node.",
            "SLOTMIGRATION PREVENT-FAILOVER <0|1>",
            "    When set to 1, slot migrations will be prevented from performing the slot-level failover on the target node.",
            "HASHTABLE-CAN-ABORT-SHRINK <0|1>",
            "    Enable or disable the hashtable shrink abort.",
            NULL};
        addExtendedReplyHelp(c, help, clusterDebugCommandExtendedHelp());
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "segfault")) {
        /* Compiler gives warnings about writing to a random address
         * e.g "*((char*)-1) = 'x';". As a workaround, we map a read-only area
         * and try to write there to trigger segmentation fault. */
        char *p = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
        *p = 'x';
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "panic")) {
        serverPanic("DEBUG PANIC called at Unix time %lld", (long long)time(NULL));
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "restart") || !strcasecmp(objectGetVal(c->argv[1]), "crash-and-recover")) {
        long long delay = 0;
        if (c->argc >= 3) {
            if (getLongLongFromObjectOrReply(c, c->argv[2], &delay, NULL) != C_OK) return;
            if (delay < 0) delay = 0;
        }
        int flags = !strcasecmp(objectGetVal(c->argv[1]), "restart")
                        ? (RESTART_SERVER_GRACEFULLY | RESTART_SERVER_CONFIG_REWRITE)
                        : RESTART_SERVER_NONE;
        restartServer(c, flags, delay);
        addReplyError(c, "failed to restart the server. Check server logs.");
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "oom")) {
        void *ptr = zmalloc(SIZE_MAX / 2); /* Should trigger an out of memory. */
        zfree(ptr);
        addReply(c, shared.ok);

Review comment (bug):
To make it less random order, let's add it next to some other hashtable debug commands, such HTSTATS or DICT-RESIZING?

Code after:
            "    The optional argument (0 by default) sets the level of detail",
            "CLIENT-EVICTION",
            "    Show low level client eviction pools info (maxmemory-clients).",
            "PAUSE-CRON <0|1>",
            "    Stop periodic cron job processing.",
            "REPLYBUFFER PEAK-RESET-TIME <NEVER||RESET|time>",
            "    Sets the time (in milliseconds) to wait between client reply buffer peak resets.",
            "    In case NEVER is provided the last observed peak will never be reset",
            "    In case RESET is provided the peak reset time will be restored to the default value",
            "REPLYBUFFER RESIZING <0|1>",
            "    Enable or disable the reply buffer resize cron job",
            "PAUSE-AFTER-FORK <0|1>",
            "    Stop the server's main process after fork.",
            "DELAY-RDB-CLIENT-FREE-SECOND <seconds>",
            "    Grace period in seconds for replica main channel to establish psync.",
            "DICT-RESIZING <0|1>",
            "    Enable or disable the main dict and expire dict resizing.",
            "HASHTABLE-CAN-ABORT-SHRINK <0|1>",
            "    Enable or disable the hashtable shrink abort.",
            "CLIENT-ENFORCE-REPLY-LIST <0|1>",
            "    When set to 1, it enforces the use of the client reply list directly",
            "    and avoids using the client's static buffer.",
            "SLOTMIGRATION PREVENT-PAUSE <0|1>",
            "    When set to 1, slot migrations will be prevented from pausing on the source node.",
            "SLOTMIGRATION PREVENT-FAILOVER <0|1>",
            "    When set to 1, slot migrations will be prevented from performing the slot-level failover on the target node.",
            NULL};
        addExtendedReplyHelp(c, help, clusterDebugCommandExtendedHelp());
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "segfault")) {
        /* Compiler gives warnings about writing to a random address
         * e.g "*((char*)-1) = 'x';". As a workaround, we map a read-only area
         * and try to write there to trigger segmentation fault. */
        char *p = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
        *p = 'x';
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "panic")) {
        serverPanic("DEBUG PANIC called at Unix time %lld", (long long)time(NULL));
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "restart") || !strcasecmp(objectGetVal(c->argv[1]), "crash-and-recover")) {
        long long delay = 0;
        if (c->argc >= 3) {
            if (getLongLongFromObjectOrReply(c, c->argv[2], &delay, NULL) != C_OK) return;
            if (delay < 0) delay = 0;
        }
        int flags = !strcasecmp(objectGetVal(c->argv[1]), "restart")
                        ? (RESTART_SERVER_GRACEFULLY | RESTART_SERVER_CONFIG_REWRITE)
                        : RESTART_SERVER_NONE;
        restartServer(c, flags, delay);
        addReplyError(c, "failed to restart the server. Check server logs.");
    } else if (!strcasecmp(objectGetVal(c->argv[1]), "oom")) {
        void *ptr = zmalloc(SIZE_MAX / 2); /* Should trigger an out of memory. */
        zfree(ptr);
        addReply(c, shared.ok);