Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

helm: reject emptyDir for volume idx, and rebuild a missing idx on restart (#10005)

Chris Lu40615e3d9d9f
diff --git a/k8s/charts/seaweedfs/templates/volume/volume-statefulset.yaml b/k8s/charts/seaweedfs/templates/volume/volume-statefulset.yaml
index 22012212bf..625e182272 100644
--- a/k8s/charts/seaweedfs/templates/volume/volume-statefulset.yaml
+++ b/k8s/charts/seaweedfs/templates/volume/volume-statefulset.yaml
@@ -4,6 +4,10 @@
{{- $volumeName := trimSuffix "-" (printf "volume-%s" $vname) }}
{{- $volume := mergeOverwrite (deepCopy $.Values.volume) (dict "enabled" true) $volume }}
+{{- if and $volume.idx (eq ($volume.idx.type | toString) "emptyDir") }}
+{{- fail (printf "%s: idx.type \"emptyDir\" is not supported. An ephemeral index is wiped on every pod restart while the data persists, forcing a full index rebuild from the .dat on each start (a fatal crash on older versions). Use the default (idx: {}, kept next to the data) or a persistentVolumeClaim/hostPath/existingClaim for a separate persistent index." $volumeName) }}
+{{- end }}
+
{{- if $volume.enabled }}
---
apiVersion: apps/v1
@@ -79,7 +83,23 @@ spec:
image: {{ template "seaweedfs.volume.image" $ }}
imagePullPolicy: {{ $.Values.global.seaweedfs.imagePullPolicy | default "IfNotPresent" }}
command: [ '/bin/sh', '-c' ]
- args: [ '{{range $dir := $volume.dataDirs }}if ls /{{$dir.name}}/*.idx >/dev/null 2>&1; then mv /{{$dir.name}}/*.idx /idx/ ; fi; {{end}}' ]
+ args:
+ - |
+ for dir in {{ range $index, $dir := $volume.dataDirs }}{{ if ne $index 0 }} {{ end }}/{{ $dir.name }}{{ end }}; do
+ # Rebuild a .idx missing from both dirs (e.g. an index volume that lost files) from the .dat, else the server fatally exits on its idx check.
+ for dat in "$dir"/*.dat; do
+ [ -e "$dat" ] || continue
+ base=${dat##*/}; base=${base%.dat}
+ if [ ! -e "$dir/$base.idx" ] && [ ! -e "/idx/$base.idx" ]; then
+ echo "rebuilding missing idx in $dir (trigger: volume $base)"
+ weed fix "$dir"
+ break
+ fi
+ done
+ if ls "$dir"/*.idx >/dev/null 2>&1; then
+ mv "$dir"/*.idx /idx/
+ fi
+ done
volumeMounts:
- name: idx
mountPath: /idx
diff --git a/k8s/charts/seaweedfs/values.yaml b/k8s/charts/seaweedfs/values.yaml
index 8e7f9f080f..f17de6ad6b 100644
--- a/k8s/charts/seaweedfs/values.yaml
+++ b/k8s/charts/seaweedfs/values.yaml
@@ -385,7 +385,7 @@ volume:
enabled: true
image: alpine/k8s:1.28.4
- # idx can be defined by:
+ # idx (the volume index) may use a separate PERSISTENT volume:
#
# idx:
# type: "hostPath"
@@ -404,13 +404,14 @@ volume:
# type: "existingClaim"
# claimName: "myClaim"
#
- # or
+ # "emptyDir" is rejected for idx (the chart fails to render): an ephemeral
+ # index is wiped on every restart while the data persists, forcing a full
+ # rebuild each start (a fatal crash on older versions). "logs" may still use
+ # any of the above or emptyDir.
#
- # idx:
- # type: "emptyDir"
-
- # same applies to "logs"
-
+ # Default {} keeps the index next to the data, so it persists with the data and
+ # needs no separate volume. Recommended unless you must split the index onto
+ # its own persistent storage.
idx: {}
# Resource requests, limits, etc. for the vol-move-idx initContainer. This