juicedata/juicefs · error

create table chunk, chunk_ref, delslices: %s

Error message

create table chunk, chunk_ref, delslices: %s

What it means

syncAllTables (pkg/meta/sql.go:588) creates/auto-migrates the data-tracking tables `chunk`, `sliceRef`, and `delslices` via xorm Sync2; failure is wrapped as "create table chunk, chunk_ref, delslices: %s". These tables map file chunks to object-storage slices and track reference counts. A failure here aborts metadata initialization after the earlier tables were created, leaving a partially initialized schema.

Source

Thrown at pkg/meta/sql.go:589

	err := m.db.Sync2(beans...)
	if err != nil && strings.Contains(err.Error(), "Duplicate key") {
		err = nil
	}
	return err
}

func (m *dbMeta) syncAllTables() error {
	if err := m.syncTable(new(setting), new(counter)); err != nil {
		return fmt.Errorf("create table setting, counter: %s", err)
	}
	if err := m.syncTable(new(edge)); err != nil {
		return fmt.Errorf("create table edge: %s", err)
	}
	if err := m.syncTable(new(node), new(symlink), new(xattr)); err != nil {
		return fmt.Errorf("create table node, symlink, xattr: %s", err)
	}
	if err := m.syncTable(new(chunk), new(sliceRef), new(delslices)); err != nil {
		return fmt.Errorf("create table chunk, chunk_ref, delslices: %s", err)
	}
	if err := m.syncTable(new(session2), new(sustained), new(delfile)); err != nil {
		return fmt.Errorf("create table session2, sustaind, delfile: %s", err)
	}
	if err := m.syncTable(new(flock), new(plock), new(dirQuota), new(userGroupQuota)); err != nil {
		return fmt.Errorf("create table flock, plock, dirQuota, userGroupQuota: %s", err)
	}
	if err := m.syncTable(new(dirStats)); err != nil {
		return fmt.Errorf("create table dirStats: %s", err)
	}
	if err := m.syncTable(new(detachedNode)); err != nil {
		return fmt.Errorf("create table detachedNode: %s", err)
	}
	if err := m.syncTable(new(acl)); err != nil {
		return fmt.Errorf("create table acl: %s", err)
	}
	if err := m.syncTable(new(delegationToken)); err != nil {
		return fmt.Errorf("create table delegationToken: %s", err)

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Check the wrapped inner error; for timeout errors retry after confirming DB health, since Sync2 is idempotent.
  2. Verify the target is a primary/writable instance, not a read replica.
  3. Grant CREATE/ALTER/INDEX privileges to the database user.
  4. For MySQL key-length errors, use utf8mb4 with adequate innodb_large_prefix settings or a supported server version.
  5. Re-run initialization; already-created tables are skipped by Sync2.
Defensive patterns

Strategy: retry

Validate before calling

// Preflight connectivity + writability so mid-init drops are unlikely
//   mysqladmin -h <host> -P <port> -u <user> -p ping
//   SELECT 1;  -- run via the app credentials
// Also confirm the target is a primary: SHOW VARIABLES LIKE 'read_only'; -- must be OFF

Try / catch

if err := initMeta(); err != nil {
    if strings.Contains(err.Error(), "create table chunk, chunk_ref, delslices") {
        if isTransient(err) { // timeout / connection reset
            return retryWithBackoff(initMeta, 3)
        }
        return fmt.Errorf("chunk table DDL failed: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Metadata engine initialization when Sync2 on chunk/sliceRef/delslices fails: DDL privileges removed after earlier tables were made, DB connection dropped mid-migration, or index-creation limits exceeded on the DB server.

Common situations: Connection timeout on a slow remote DB mid-init; MySQL index key-length limits hit with certain charsets; read-replica mistakenly used as the metadata target.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/0241167012506bc0. Report an issue: GitHub.