dgraph-io/dgraph · error

p directory does not exist for group [%d]: [%s]

Error message

p directory does not exist for group [%d]: [%s]

What it means

While streaming the snapshot, streamSnapshot expects baseDir to contain a numeric subdirectory per group (group-1) with a p/ inside (bulk output layout). os.Stat failing means that expected p directory is missing, so data for that group cannot be streamed.

Source

Thrown at dgraph/cmd/dgraphimport/import_client.go:120

			return nil, ctx.Err()
		case <-time.After(retryDelay):
		}
		retryDelay = min(retryDelay*2, 10*time.Second)
	}
}

// streamSnapshot takes a p directory and a set of group IDs and streams the data from the
// p directory to the corresponding group IDs. It first scans the provided directory for
// subdirectories named with numeric group IDs.
func streamSnapshot(ctx context.Context, dc api.DgraphClient, baseDir string, groups []uint32) error {
	glog.Infof("[import] Starting to stream snapshot from directory: %s", baseDir)

	errG, errGrpCtx := errgroup.WithContext(ctx)
	for _, group := range groups {
		errG.Go(func() error {
			pDir := filepath.Join(baseDir, fmt.Sprintf("%d", group-1), "p")
			if _, err := os.Stat(pDir); err != nil {
				return fmt.Errorf("p directory does not exist for group [%d]: [%s]", group, pDir)
			}
			glog.Infof("[import] Streaming data for group [%d] from directory: [%s]", group, pDir)
			if err := streamSnapshotForGroup(errGrpCtx, dc, pDir, group); err != nil {
				glog.Errorf("[import] Failed to stream data for group [%v] from directory: [%s]: %v", group, pDir, err)
				return err
			}

			return nil
		})
	}

	if err := errG.Wait(); err != nil {
		glog.Errorf("[import] failed to stream external snapshot: %v", err)
		// If errors occurs during streaming of the external snapshot, we drop all the data and
		// go back to ensure a clean slate and the cluster remains in working state.
		glog.Info("[import] dropping all the data and going back to clean slate")
		req := &api.UpdateExtSnapshotStreamingStateRequest{
			Start:    false,

View on GitHub (pinned to 759e242be6)

Solutions

  1. Verify the layout: bulkOutDir must contain directories 0/p, 1/p, ... for each group id returned in resp.Groups.
  2. Re-run `dgraph bulk` if the p directories were deleted or the export is incomplete; point bulkOutDir at its output root.
  3. Confirm the volume/mount holding the bulk output is attached and paths are absolute/correct.
  4. Match group count: if the cluster has more groups than exported shards, produce bulk output for all groups or stream only exported ones.

Example fix

// before
err := dgraphimport.Import(ctx, addr, "/data/bulk_output/shards") // wrong level: p dirs live in 0/p, 1/p
// after
err := dgraphimport.Import(ctx, addr, "/data/bulk_output")       // root containing <group-1>/p
Defensive patterns

Strategy: validation

Validate before calling

if err := validateBulkLayout(bulkDir, groups); err != nil { return err }

func validateBulkLayout(base string, groups []uint32) error {
    for _, g := range groups {
        p := filepath.Join(base, fmt.Sprintf("%d", g-1), "p")
        if _, err := os.Stat(p); err != nil {
            return fmt.Errorf("missing %s for group %d", p, g)
        }
    }
    return nil
}

Try / catch

if err := dgraphimport.Import(ctx, addr, bulkDir); err != nil {
    if strings.Contains(err.Error(), "p directory does not exist") {
        return fmt.Errorf("bulk output layout mismatch: expected <root>/<group-1>/p; got root %q", bulkDir)
    }
    return err
}

Prevention

When it happens

Trigger: The bulkOutDir passed to Import does not follow the dgraph bulk output layout — missing <N>/p subdirectory for one of the groups reported by the snapshot initiation response.

Common situations: Pointing at the wrong (parent or partial) directory, bulk output moved/trimmed (p dirs deleted to save space), group count from the cluster larger than the number of exported shards, path typos or volume not mounted.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/063f8faff4be5104. Report an issue: GitHub.