2023-12-22 09:58:20 +00:00
|
|
|
package writecache
|
2021-09-14 16:20:31 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-21 10:38:44 +00:00
|
|
|
"io/fs"
|
2021-09-14 16:20:31 +00:00
|
|
|
"os"
|
2022-02-02 13:28:08 +00:00
|
|
|
"path/filepath"
|
2022-06-09 11:08:13 +00:00
|
|
|
"time"
|
2021-09-14 16:20:31 +00:00
|
|
|
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// OpenDB opens BoltDB instance for write-cache. Opens in read-only mode if ro is true.
|
2023-03-21 10:38:44 +00:00
|
|
|
func OpenDB(p string, ro bool, openFile func(string, int, fs.FileMode) (*os.File, error)) (*bbolt.DB, error) {
|
2022-02-02 13:28:08 +00:00
|
|
|
return bbolt.Open(filepath.Join(p, dbName), os.ModePerm, &bbolt.Options{
|
2021-09-14 16:20:31 +00:00
|
|
|
NoFreelistSync: true,
|
|
|
|
ReadOnly: ro,
|
2022-06-09 11:08:13 +00:00
|
|
|
Timeout: 100 * time.Millisecond,
|
2023-03-21 10:38:44 +00:00
|
|
|
OpenFile: openFile,
|
2021-09-14 16:20:31 +00:00
|
|
|
})
|
|
|
|
}
|