microsoft/garnet · error · Exception

Cannot use null device for AOF when cluster is enabled and y

Error message

Cannot use null device for AOF when cluster is enabled and you are not using main memory replication

What it means

Garnet blocks the AOF null device when cluster mode is active without main-memory replication. The null device discards AOF data on close, but cluster replication depends on AOF contents for replica sync. Only when FastAofTruncate is true (main-memory replication mode) is the null device acceptable in cluster mode. The check fires in GetAofDevice().

Source

Thrown at libs/server/Servers/GarnetServerOptions.cs:1123

                logger?.LogInformation("Warning: using lower AOF memory size than specified (power of 2)");
            return (int)Math.Log(adjustedSize, 2);
        }

        /// <summary>
        /// Get integer value of ReplicaDisklessSyncFullSyncAofThreshold
        /// </summary>
        /// <returns></returns>
        public long ReplicaDisklessSyncFullSyncAofThresholdValue()
            => ParseSize(string.IsNullOrEmpty(ReplicaDisklessSyncFullSyncAofThreshold) ? AofMemorySize : ReplicaDisklessSyncFullSyncAofThreshold, out _);

        /// <summary>
        /// Get device for AOF
        /// </summary>
        /// <returns></returns>
        IDevice GetAofDevice(int dbId, int subLogIdx = -1)
        {
            if (UseAofNullDevice && EnableCluster && !FastAofTruncate)
                throw new Exception("Cannot use null device for AOF when cluster is enabled and you are not using main memory replication");
            if (UseAofNullDevice) return new NullDevice();

            if (subLogIdx == -1)
            {
                return GetInitializedDeviceFactory(AppendOnlyFileBaseDirectory)
                    .Get(new FileDescriptor(GetAppendOnlyFileDirectoryName(dbId), "aof.log"));
            }
            else
            {
                return GetInitializedDeviceFactory(AppendOnlyFileBaseDirectory)
                    .Get(new FileDescriptor(GetAppendOnlyFileDirectoryName(dbId), $"aof.{subLogIdx}.log"));
            }
        }

        /// <summary>
        /// Indicates whether AOF auto-commit is enabled.
        /// </summary>
        public bool AofAutoCommit

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Remove --aof-null-device so a real on-disk AOF device is used (required for cluster replication).
  2. Add --fast-aof-truncate to enable main-memory replication, which permits the null device in cluster mode.
  3. Disable cluster mode if you are running a single node and want the null device.

Example fix

// before
--aof-null-device --cluster

// after
--aof-null-device --cluster --fast-aof-truncate
Defensive patterns

Strategy: validation

Validate before calling

if (options.UseAofNullDevice && options.EnableCluster && !options.FastAofTruncate)
    throw new InvalidOperationException("Null AOF device requires --fast-aof-truncate when cluster mode is enabled.");

Prevention

When it happens

Trigger: Calling GetAofDevice() with UseAofNullDevice=true AND EnableCluster=true AND FastAofTruncate=false simultaneously. Typically from config or command-line flags: --aof-null-device --cluster without --fast-aof-truncate.

Common situations: Enabling cluster mode for the first time while keeping a single-node AOF null device config; testing with null device and accidentally enabling cluster mode; misunderstanding that FastAofTruncate is the flag that permits the null device in cluster.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/4a0b293933c8b87a. Report an issue: GitHub.