diff --git a/cmd/profile/main.go b/cmd/profile/main.go index 1ee542b..d06f8e1 100644 --- a/cmd/profile/main.go +++ b/cmd/profile/main.go @@ -51,7 +51,9 @@ func main() { reg := profile.NewProfileMutationRegistry() profileDir := getEnv("PROFILE_DIR", "data/profiles") - _ = os.MkdirAll(profileDir, 0755) + if err := os.MkdirAll(profileDir, 0755); err != nil { + log.Printf("warning: could not create profile data directory %s: %v", profileDir, err) + } diskStorage := actor.NewDiskStorage[profile.ProfileGrain](profileDir, reg) poolConfig := actor.GrainPoolConfig[profile.ProfileGrain]{ diff --git a/pkg/actor/disk_storage.go b/pkg/actor/disk_storage.go index 75e7376..269adf0 100644 --- a/pkg/actor/disk_storage.go +++ b/pkg/actor/disk_storage.go @@ -147,6 +147,13 @@ func (s *DiskStorage[V]) AppendMutations(id uint64, msg ...proto.Message) error return nil } else { path := s.logPath(id) + // Ensure the parent directory exists (e.g. first write to a new PVC mount). + // MkdirAll is a no-op when the directory already exists, so it's safe to + // call on every AppendMutations without extra stat overhead. + if err := os.MkdirAll(s.path, 0755); err != nil { + log.Printf("failed to create event log directory %s: %v", s.path, err) + return err + } fh, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { log.Printf("failed to open event log file: %v", err)