@@ -506,8 +506,40 @@ func (db *DB) OpenLTXFile(txID uint64) (*os.File, error) {
506506 return os .Open (db .LTXPath (txID , txID ))
507507}
508508
509- // WriteDatabase writes data to the main database file.
510- func (db * DB ) WriteDatabase (f * os.File , data []byte , offset int64 ) error {
509+ // OpenDatabase returns a handle for the database file.
510+ func (db * DB ) OpenDatabase (ctx context.Context ) (* os.File , error ) {
511+ return os .OpenFile (db .DatabasePath (), os .O_RDWR , 0666 )
512+ }
513+
514+ // CloseDatabase closes a handle associated with the database file.
515+ func (db * DB ) CloseDatabase (ctx context.Context , f * os.File ) error {
516+ return f .Close ()
517+ }
518+
519+ // TruncateDatabase sets the size of the database file.
520+ func (db * DB ) TruncateDatabase (ctx context.Context , size int64 ) error {
521+ return os .Truncate (db .DatabasePath (), size )
522+ }
523+
524+ // SyncDatabase fsync's the database file.
525+ func (db * DB ) SyncDatabase (ctx context.Context ) error {
526+ f , err := os .Open (db .DatabasePath ())
527+ if err != nil {
528+ return err
529+ } else if err := f .Sync (); err != nil {
530+ _ = f .Close ()
531+ return err
532+ }
533+ return f .Close ()
534+ }
535+
536+ // ReadDatabaseAt reads from the database at the specified index.
537+ func (db * DB ) ReadDatabaseAt (f * os.File , data []byte , offset int64 ) (int , error ) {
538+ return f .ReadAt (data , offset )
539+ }
540+
541+ // WriteDatabaseAt writes data to the main database file at the given index.
542+ func (db * DB ) WriteDatabaseAt (f * os.File , data []byte , offset int64 ) error {
511543 // Return an error if the current process is not the leader.
512544 if ! db .store .IsPrimary () {
513545 return ErrReadOnlyReplica
@@ -544,6 +576,11 @@ func (db *DB) WriteDatabase(f *os.File, data []byte, offset int64) error {
544576 return nil
545577}
546578
579+ // UnlockDatabase unlocks all locks from the database file.
580+ func (db * DB ) UnlockDatabase (ctx context.Context , guardSet * GuardSet ) {
581+ guardSet .UnlockDatabase ()
582+ }
583+
547584// CreateJournal creates a new journal file on disk.
548585func (db * DB ) CreateJournal () (* os.File , error ) {
549586 if ! db .store .IsPrimary () {
@@ -552,11 +589,21 @@ func (db *DB) CreateJournal() (*os.File, error) {
552589 return os .OpenFile (db .JournalPath (), os .O_RDWR | os .O_CREATE | os .O_EXCL | os .O_TRUNC , 0666 )
553590}
554591
592+ // RemoveJournal deletes the journal file from disk.
593+ func (db * DB ) RemoveJournal (ctx context.Context ) error {
594+ return db .CommitJournal (JournalModeDelete )
595+ }
596+
555597// CreateWAL creates a new WAL file on disk.
556598func (db * DB ) CreateWAL () (* os.File , error ) {
557599 return os .OpenFile (db .WALPath (), os .O_RDWR | os .O_CREATE | os .O_EXCL | os .O_TRUNC , 0666 )
558600}
559601
602+ // RemoveWAL deletes the WAL file from disk.
603+ func (db * DB ) RemoveWAL (ctx context.Context ) error {
604+ return os .Remove (db .WALPath ())
605+ }
606+
560607// WriteWAL writes data to the WAL file. On final commit write, an LTX file is
561608// generated for the transaction.
562609func (db * DB ) WriteWAL (f * os.File , data []byte , offset int64 ) error {
@@ -863,6 +910,11 @@ func (db *DB) CreateSHM() (*os.File, error) {
863910 return os .OpenFile (db .SHMPath (), os .O_RDWR | os .O_CREATE | os .O_EXCL | os .O_TRUNC , 0666 )
864911}
865912
913+ // RemoveSHM removes the SHM file from disk.
914+ func (db * DB ) RemoveSHM (ctx context.Context ) error {
915+ return os .Remove (db .SHMPath ())
916+ }
917+
866918// WriteSHM writes data to the SHM file.
867919func (db * DB ) WriteSHM (f * os.File , data []byte , offset int64 ) (int , error ) {
868920 dbSHMWriteCountMetricVec .WithLabelValues (db .name ).Inc ()
0 commit comments