Automatically Export and Import Queue on RabbitMQ Chart Version Upgrades

Open
#215 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
helm, kubernetes, rabbitmq

Research direction

No repository files or tests are named. Start by reviewing the Helm Chart Hooks documentation and RabbitMQ Backup and Restore documentation, then determine how message data can be preserved and how RabbitMQ version changes are detected. Done means upgrades and uninstalls preserve the queue without importing on unrelated Helm upgrades, with the behavior tested outside production.

Written by the indexing model from the issue text.

Description

Purpose

When changing RabbitMQ sub-chart versions, provide automatic functionality (via helm hooks) to export the queue on helm uninstall and import it on helm install (and do both on helm upgrade).

Background

Issue #202 introduced the creation of a new PV/PVC for RabbitMQ, each time RabbitMQ sub-chart is upgraded, since a fresh install bypasses onerous manual upgrade requirements.

Currently, before upgrading, the operator must ensure the RabbitMQ queue is empty, otherwise indexing tasks may be "lost" (they will still remain on the old PV, but will no longer be used by the newer RabbitMQ version).

This isn't a problem for less-trafficked installations, but could become onerous on sites like arcticdata.io, or the production CN, for example.

Potential Difficulties
  • The example below uses rabbitmqadmin export/import; however, the rabbitMQ docs imply this processes only the Schema definition, and not the actual messages. It appears that messages may be more difficult to back up:

    • From Backing Up Messages:

      Manually Backing Up Messages
      Presently this is the only way of backing up messages. You can copy the folders mentioned above.

    • From Backup and Restore):

      Modern versions of RabbitMQ (3.8.0+) only support backup restore from disk when they are restored to a RabbitMQ node with exactly the same node name as the node the data was backed up from

  • We need to make sure the export/import process does not interfere with helm installations and upgrades that do NOT involve a RabbitMQ version change - in those instances, we could still do the export (for safety), but the import should be skipped, since RMQ uses its own on-disk cache of the queue items

References

From my experience, replacing the PVC for RabbitMQ is relatively quick when there is only a single pod. However, scaling to multiple pods might indeed increase the complexity and time required.

One potential solution could be to implement a Helm hook to automate this process during upgrades. For instance, we currently use Helm hooks to trigger backups for PostgreSQL and Solr prior to upgrades and uninstalls. Similarly, a pre- and post-upgrade hook for preserving the RabbitMQ queue could streamline the process and ensure data integrity during updates ( See idea below).


To preserve RabbitMQ queues during upgrades, you can use Helm pre and post hooks. These hooks can help ensure the state is preserved and restored effectively. Depending on your setup, temporary PVCs may or may not be required. Here's an approach:

Pre-Upgrade Hook
  1. Backup Messages in the Queue:

    • Use a Helm pre-upgrade hook to export messages from RabbitMQ to a temporary storage solution (e.g., a temporary PVC or a cloud storage bucket).
    • Tools like rabbitmqadmin or rabbit-dump-queue can be used to dump the queue data.

    Example Hook:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: rabbitmq-backup
      annotations:
        "helm.sh/hook": pre-upgrade
    spec:
      template:
        spec:
          containers:
          - name: backup
            image: rabbitmq:management
            command: ["sh", "-c", "rabbitmqadmin export /backup/queues.json"]
            volumeMounts:
            - name: backup-pvc
              mountPath: /backup
          volumes:
          - name: backup-pvc
            persistentVolumeClaim:
              claimName: rabbitmq-backup-pvc
          restartPolicy: OnFailure
    
  2. Temporary PVC:

    • Request a temporary PVC for storing the backup during the upgrade process.
    • Define a PVC with appropriate storage configuration.

    Example PVC:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: rabbitmq-backup-pvc
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
    
Post-Upgrade Hook
  1. Restore Messages to the Queue:

    • Use a Helm post-upgrade hook to restore the RabbitMQ queues from the backup.
    • Tools like rabbitmqadmin or similar can be used to import the queue configuration and messages.

    Example Hook:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: rabbitmq-restore
      annotations:
        "helm.sh/hook": post-upgrade
    spec:
      template:
        spec:
          containers:
          - name: restore
            image: rabbitmq:management
            command: ["sh", "-c", "rabbitmqadmin import /backup/queues.json"]
            volumeMounts:
            - name: backup-pvc
              mountPath: /backup
          volumes:
          - name: backup-pvc
            persistentVolumeClaim:
              claimName: rabbitmq-backup-pvc
          restartPolicy: OnFailure
    
  2. Delete Temporary PVC (Optional):

    • Add a cleanup step to delete the temporary PVC if it's no longer needed.

    Example Cleanup Hook:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: rabbitmq-cleanup
      annotations:
        "helm.sh/hook": post-upgrade
    spec:
      template:
        spec:
          containers:
          - name: cleanup
            image: bitnami/kubectl:latest
            command: ["sh", "-c", "kubectl delete pvc rabbitmq-backup-pvc"]
          restartPolicy: OnFailure
    
Key Points:
  • Temporary PVCs can be used to ensure data persists during the upgrade process.
  • Ensure proper PVC sizing and resource requests to handle your RabbitMQ queues.
  • Test the pre- and post-hooks in a non-production environment to ensure they work as expected.
Dominant language
Java
Stars
0
Forks
2
Avg merge
6d 6h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataONEorg/dataone-indexer

All issues in DataONEorg/dataone-indexer

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.