MCPcopy Index your code
hub / github.com/dagger/dagger / NewCache

Function NewCache

dagql/cache.go:103–208  ·  view source on GitHub ↗
(
	ctx context.Context,
	dbPath string,
	snapshotManager bkcache.SnapshotManager,
	snapshotGC func(context.Context) error,
)

Source from the content-addressed store, hash-verified

101)
102
103func NewCache(
104 ctx context.Context,
105 dbPath string,
106 snapshotManager bkcache.SnapshotManager,
107 snapshotGC func(context.Context) error,
108) (*Cache, error) {
109 c := &Cache{
110 traceBootID: newTraceBootID(),
111 snapshotManager: snapshotManager,
112 snapshotGC: snapshotGC,
113 }
114
115 if dbPath == "" {
116 return c, nil
117 }
118
119 db, persistDB, err := prepareCacheDBs(ctx, dbPath)
120 if err != nil {
121 return nil, err
122 }
123 c.sqlDB = db
124 c.pdb = persistDB
125
126 schemaVersionVal, found, err := c.pdb.SelectMetaValue(ctx, persistdb.MetaKeySchemaVersion)
127 if err != nil {
128 if closeErr := closeCacheDBs(db, c.pdb); closeErr != nil {
129 return nil, errors.Join(fmt.Errorf("read schema_version metadata: %w", err), closeErr)
130 }
131 return nil, fmt.Errorf("read schema_version metadata: %w", err)
132 }
133 if found && schemaVersionVal != cachePersistenceSchemaVersion {
134 c.persistenceResetReason = CachePersistenceResetSchemaMismatch
135 c.tracePersistStoreWipedSchemaMismatch(ctx, cachePersistenceSchemaVersion, schemaVersionVal)
136 slog.Warn("dagql persistence store schema version mismatch; wiping and cold-starting", "expected", cachePersistenceSchemaVersion, "actual", schemaVersionVal)
137 if closeErr := closeCacheDBs(db, c.pdb); closeErr != nil {
138 return nil, errors.Join(fmt.Errorf("close db before schema-version wipe"), closeErr)
139 }
140 if err := wipeSQLiteFiles(dbPath); err != nil {
141 return nil, fmt.Errorf("wipe schema-mismatched persistence db: %w", err)
142 }
143
144 db, persistDB, err = prepareCacheDBs(ctx, dbPath)
145 if err != nil {
146 return nil, err
147 }
148 c.sqlDB = db
149 c.pdb = persistDB
150 }
151
152 cleanShutdownVal, found, err := c.pdb.SelectMetaValue(ctx, persistdb.MetaKeyCleanShutdown)
153 if err != nil {
154 if closeErr := closeCacheDBs(db, c.pdb); closeErr != nil {
155 return nil, errors.Join(fmt.Errorf("read clean_shutdown metadata: %w", err), closeErr)
156 }
157 return nil, fmt.Errorf("read clean_shutdown metadata: %w", err)
158 }
159 if found && cleanShutdownVal != "1" {
160 c.persistenceResetReason = CachePersistenceResetUncleanShutdown

Calls 11

importPersistedStateMethod · 0.95
WarnFunction · 0.92
newTraceBootIDFunction · 0.85
prepareCacheDBsFunction · 0.85
closeCacheDBsFunction · 0.85
wipeSQLiteFilesFunction · 0.85
SelectMetaValueMethod · 0.80
UpsertMetaMethod · 0.80