Skip to content

Bug: PDP datastore fails to initialize with PostgreSQL backend #448

@frrist

Description

@frrist

Summary

When using PostgreSQL as the database backend, piri fails to start with:

creating pdp object store: mkdir /data/piri/pdp/datastore: no such file or directory

Root Cause

The flatfs.create() function uses os.Mkdir() which only creates a single directory level. It fails if the parent directory doesn't exist.

Why it worked with SQLite:

  1. ensureSQLiteDir() is called for SQLite, which uses os.MkdirAll()
  2. SQLite path is /data/piri/pdp/state/state.db
  3. This inadvertently creates /data/piri/pdp/ as a side effect
  4. Later, PDP store creation at /data/piri/pdp/datastore succeeds because parent exists

Why it fails with PostgreSQL:

  1. ensureSQLiteDir() is never called (postgres doesn't need local DB file)
  2. /data/piri/pdp/ is never created
  3. PDP store creation fails because os.Mkdir() can't create parent directories

Fix

In pkg/store/objectstore/flatfs/flatfs.go, line 137:

// Before
err := os.Mkdir(path, 0755)
if err != nil && !os.IsExist(err) {
    return err
}

// After
err := os.MkdirAll(path, 0755)
if err != nil {
    return err
}

os.MkdirAll() creates the entire directory tree including parents, and doesn't error if the directory already exists.

Affected Code

  • pkg/store/objectstore/flatfs/flatfs.go - create() function
  • Hidden dependency on SQLite initialization order

Testing

Discovered via smelt integration tests with --profile piri-postgres. All existing flatfs unit tests pass with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Inbox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions