@@ -114,8 +114,12 @@ func NewC1File(ctx context.Context, dbFilePath string, opts ...C1FOption) (*C1Fi
114114
115115 rawDB , err := sql .Open ("sqlite" , dbFilePath )
116116 if err != nil {
117- return nil , err
117+ return nil , fmt . Errorf ( "new-c1-file: error opening raw db: %w" , err )
118118 }
119+ l := ctxzap .Extract (ctx )
120+ l .Debug ("new-c1-file: opened raw db" ,
121+ zap .String ("db_file_path" , dbFilePath ),
122+ )
119123
120124 // Limit to a single connection so idle pool connections don't hold WAL
121125 // read locks that prevent PRAGMA wal_checkpoint(TRUNCATE) from completing
@@ -147,7 +151,7 @@ func NewC1File(ctx context.Context, dbFilePath string, opts ...C1FOption) (*C1Fi
147151
148152 err = c1File .init (ctx )
149153 if err != nil {
150- return nil , err
154+ return nil , fmt . Errorf ( "new-c1-file: error initializing c1file: %w" , err )
151155 }
152156
153157 return c1File , nil
@@ -225,6 +229,11 @@ func NewC1ZFile(ctx context.Context, outputFilePath string, opts ...C1ZOption) (
225229 if err != nil {
226230 return nil , err
227231 }
232+ l := ctxzap .Extract (ctx )
233+ l .Debug ("new-c1z-file: decompressed c1z" ,
234+ zap .String ("db_file_path" , dbFilePath ),
235+ zap .String ("output_file_path" , outputFilePath ),
236+ )
228237
229238 var c1fopts []C1FOption
230239 for _ , pragma := range options .pragmas {
@@ -383,14 +392,18 @@ func (c *C1File) init(ctx context.Context) error {
383392
384393 err = c .InitTables (ctx )
385394 if err != nil {
395+ l .Error ("c1file-init: error initializing tables" , zap .Error (err ))
386396 return err
387397 }
398+ l .Debug ("c1file-init: initialized tables" ,
399+ zap .String ("db_file_path" , c .dbFilePath ),
400+ )
388401
389402 // // Checkpoint the WAL after migrations. Migrations like backfillGrantExpansionColumn
390403 // // can update many rows, filling the WAL. Without a checkpoint, subsequent reads are
391404 // // slow because SQLite must scan the WAL hash table for every page read.
392405 if _ , err = c .db .ExecContext (ctx , "PRAGMA wal_checkpoint(TRUNCATE)" ); err != nil {
393- l .Warn ("WAL checkpoint after init failed" , zap .Error (err ))
406+ l .Warn ("c1file-init: WAL checkpoint after init failed" , zap .Error (err ))
394407 }
395408
396409 if c .readOnly {
@@ -415,16 +428,17 @@ func (c *C1File) init(ctx context.Context) error {
415428 }
416429 }
417430 if ! hasLockingPragma {
431+ l .Debug ("c1file-init: setting locking mode to EXCLUSIVE" , zap .String ("db_file_path" , c .dbFilePath ))
418432 _ , err = c .db .ExecContext (ctx , "PRAGMA main.locking_mode = EXCLUSIVE" )
419433 if err != nil {
420- return err
434+ return fmt . Errorf ( "c1file-init: error setting locking mode to EXCLUSIVE: %w" , err )
421435 }
422436 }
423437
424438 for _ , pragma := range c .pragmas {
425439 _ , err := c .db .ExecContext (ctx , fmt .Sprintf ("PRAGMA %s = %s" , pragma .name , pragma .value ))
426440 if err != nil {
427- return err
441+ return fmt . Errorf ( "c1file-init: error setting pragma %s = %s: %w" , pragma . name , pragma . value , err )
428442 }
429443 }
430444
@@ -440,16 +454,23 @@ func (c *C1File) InitTables(ctx context.Context) error {
440454 return err
441455 }
442456
457+ l := ctxzap .Extract (ctx ).With (zap .String ("db_file_path" , c .dbFilePath ))
443458 for _ , t := range allTableDescriptors {
444459 query , args := t .Schema ()
445460 _ , err = c .db .ExecContext (ctx , fmt .Sprintf (query , args ... ))
446461 if err != nil {
447- return err
462+ return fmt . Errorf ( "c1file-init-tables: error initializing table %s: %w" , t . Name (), err )
448463 }
464+ l .Debug ("c1file-init-tables: initialized table schema, running migrations" ,
465+ zap .String ("table_name" , t .Name ()),
466+ )
449467 err = t .Migrations (ctx , c .db )
450468 if err != nil {
451- return err
469+ return fmt . Errorf ( "c1file-init-tables: error running migration for table %s: %w" , t . Name (), err )
452470 }
471+ l .Debug ("c1file-init-tables: ran migrations for table" ,
472+ zap .String ("table_name" , t .Name ()),
473+ )
453474 }
454475
455476 return nil
0 commit comments