garnet icon indicating copy to clipboard operation
garnet copied to clipboard

Feature Request: Implement Graceful Shutdown for Garnet as a Windows Service

Open yuseok-kim-edushare opened this issue 3 months ago • 2 comments

Feature request type

enhancement

Is your feature request related to a problem? Please describe

When Garnet is run as a Windows Service using Garnet.Worker.exe, it shuts down immediately upon receiving a stop signal from the Service Control Manager (e.g., via services.msc or sc stop).

This behavior can lead to data loss for any in-memory data that has not yet been persisted to disk through the AOF or a recent checkpoint. A graceful shutdown mechanism is needed to ensure data integrity.

Describe the solution you'd like

The Garnet.Worker service host should properly handle the OnStop event from the Windows Service base class. The desired workflow is as follows:

  1. The Garnet.Worker service intercepts the stop signal from Windows.
  2. Before terminating the process, the service issues a SAVE command to the Garnet server to ensure all data is flushed to disk.
  3. The service should wait for the save operation to complete successfully before allowing the process to exit.

Describe alternatives you've considered

The current alternative is to manually connect to the Garnet instance with a client (e.g., redis-cli) and issue a SAVE command before stopping the service. This is not ideal for automated environments and is prone to human error.

Additional context

For context, here is how the Garnet Windows Service is being created:

set SVCEXE="C:\garnet\Service\Garnet.Worker.exe"
sc create Garnet binPath= "%SVCEXE% --config-import-path \"C:\Garnet\garnet.conf\"" start= auto
sc description Garnet "Garnet (RESP) with storage+AOF+compaction"

yuseok-kim-edushare avatar Sep 16 '25 09:09 yuseok-kim-edushare

when AOF is enabled only we need to handle this

AOF flag is on or not checking is also needed

yuseok-kim-edushare avatar Sep 16 '25 09:09 yuseok-kim-edushare

Not Only handle commit AOF, also save to checkpoint when tiered storage is our target

yuseok-kim-edushare avatar Oct 10 '25 04:10 yuseok-kim-edushare