{"record":{"id":"9122ea9545810d3d","repo":"thanos-io/thanos","slug":"create-default-tenant-data-dir-v","errorCode":null,"errorMessage":"create default tenant data dir: %v","messagePattern":"create default tenant data dir: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/thanos/receive.go","lineNumber":866,"sourceCode":"\t\t\t}, func(error) {\n\t\t\t\tcancel()\n\t\t\t})\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc createDefautTenantTSDB(logger log.Logger, defaultTenantID string, dataDir *os.Root) error {\n\tif _, err := dataDir.Stat(defaultTenantID); !os.IsNotExist(err) {\n\t\tlevel.Info(logger).Log(\"msg\", \"default tenant data dir already present, will not create\")\n\t\treturn nil\n\t}\n\n\tlevel.Info(logger).Log(\"msg\", \"default tenant data dir not found, creating\", \"defaultTenantID\", defaultTenantID)\n\n\tif err := dataDir.MkdirAll(defaultTenantID, 0750); err != nil {\n\t\treturn errors.Wrapf(err, \"create default tenant data dir: %v\", path.Join(dataDir.Name(), defaultTenantID))\n\t}\n\n\treturn nil\n}\n\ntype receiveConfig struct {\n\thttpBindAddr    *string\n\thttpGracePeriod *model.Duration\n\thttpTLSConfig   *string\n\n\tgrpcConfig grpcConfig\n\n\treplicationAddr       string\n\trwAddress             string\n\trwServerCert          string\n\trwServerKey           string\n\trwServerClientCA      string\n\trwClientCert          string","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/receive.go#L848-L884","documentation":"Received fails to create the data directory for the default tenant (hashrings without an explicit tenant fall back to the default tenant, defaultTenantID \"default-tenant\"). This wraps the error returned by dataDir.MkdirAll when the per-tenant TSDB data directory cannot be created. It is fatal for startup because the default tenant must be able to store series.","triggerScenarios":"dataDir.MkdirAll(defaultTenantID, 0750) fails: the parent --tsdb.path does not exist or is not writable, the filesystem is read-only or full, or an OS-level permission/SELinux issue blocks mkdir.","commonSituations":"Running the receive container as a non-root user with a hostPath/PV owned by root; the data directory was mounted read-only; disk full on the node; a file exists where the directory is expected.","solutions":["Check that the --tsdb.path directory exists and is writable by the receive process user (ls -ld, or chown/chmod it).","Verify the mount is not read-only and the filesystem has free space (mount | grep, df -h).","If a non-directory exists at the path, remove or rename it and restart.","Run with correct security context (fsGroup/SELinux labels) in Kubernetes or as a user with write access."],"exampleFix":"// before\nmkdir -p /var/lib/thanos/receive && thanos receive --tsdb.path=/var/lib/thanos/receive  # dir owned by root\n// after\nsudo chown thanos:thanos /var/lib/thanos/receive && chmod 750 /var/lib/thanos/receive","handlingStrategy":"validation","validationCode":"import os, stat\ndef ensure_tenant_data_dir(base, tenant=\"default-tenant\"):\n    p = os.path.join(base, tenant)\n    if not os.path.isdir(base):\n        raise SystemExit(f\"tsdb path {base} does not exist\")\n    if not os.access(base, os.W_OK | os.X_OK):\n        raise SystemExit(f\"tsdb path {base} not writable by uid={os.getuid()}\")\n    if os.path.exists(p) and not os.path.isdir(p):\n        raise SystemExit(f\"{p} exists but is not a directory\")\n    return p","typeGuard":"def is_writable_dir(path):\n    return os.path.isdir(path) and os.access(path, os.W_OK)","tryCatchPattern":null,"preventionTips":["Pre-create and chown the TSDB data dir in your container/entrypoint before starting receive.","Set fsGroup in Kubernetes so PVs are writable by the process user.","Monitor disk usage; mount data volumes read-write, never :ro.","Verify no file occupies the directory path after restore/migration."],"tags":["filesystem","permissions","storage","startup"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}