aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-12-30 23:17:16 -0300
committerEuAndreh <eu@euandre.org>2024-12-30 23:17:16 -0300
commite933fbca8ca26042787b8202a78ccf394bf18766 (patch)
tree4a33a552b253f60f2ec854126f247354d5be7aba
parentsrc/dedo.go: Remove Options.InitialMmapSize option (diff)
downloaddedo-e933fbca8ca26042787b8202a78ccf394bf18766.tar.gz
dedo-e933fbca8ca26042787b8202a78ccf394bf18766.tar.xz
src/dedo.go: Remove mode and options from Open()
-rw-r--r--src/dedo.go28
-rw-r--r--tests/dedo.go68
2 files changed, 44 insertions, 52 deletions
diff --git a/src/dedo.go b/src/dedo.go
index b81b55b..3feaf56 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -174,10 +174,6 @@ type panicked struct {
reason interface{}
}
-// Options represents the options that can be set when opening a database.
-type Options struct {
-}
-
// Stats represents statistics about the database.
type Stats struct {
// Freelist stats
@@ -624,7 +620,7 @@ func fdatasync(db *DB) error {
// flock acquires an advisory lock on a file descriptor.
-func flock(db *DB, mode os.FileMode) error {
+func flock(db *DB) error {
const exclusive = true // FIXME: allow multiple processes to cooperate
for {
@@ -1800,16 +1796,12 @@ func openFile(path string) (*os.File, error) {
// Open creates and opens a database at the given path.
// If the file does not exist then it will be created automatically.
// Passing in nil options will cause Bolt to open the database with the default options.
-func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
+func Open(path string) (*DB, error) {
var db = &DB{
opened: true,
path: path,
}
- if options == nil {
- options = &Options{}
- }
-
// Set default values for later DB operations.
db.MaxBatchSize = DefaultMaxBatchSize
db.MaxBatchDelay = DefaultMaxBatchDelay
@@ -1829,7 +1821,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
// if !options.ReadOnly.
// The database file is locked using the shared lock (more than one process may
// hold a lock at the same time) otherwise (options.ReadOnly is set).
- if err := flock(db, mode); err != nil {
+ if err := flock(db); err != nil {
_ = db.close()
return nil, err
}
@@ -4271,7 +4263,7 @@ func (cmd *CheckCommand) Run(args ...string) error {
}
// Open database.
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
return err
}
@@ -4349,7 +4341,7 @@ func (cmd *InfoCommand) Run(args ...string) error {
}
// Open the database.
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
return err
}
@@ -4753,7 +4745,7 @@ func (cmd *PagesCommand) Run(args ...string) error {
}
// Open database.
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
return err
}
@@ -4840,7 +4832,7 @@ func (cmd *StatsCommand) Run(args ...string) error {
}
// Open database.
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
return err
}
@@ -4963,7 +4955,7 @@ func (cmd *BenchCommand) Run(args ...string) error {
}
// Create database.
- db, err := Open(options.Path, 0666, nil)
+ db, err := Open(options.Path)
if err != nil {
return err
}
@@ -5492,14 +5484,14 @@ func (cmd *CompactCommand) Run(args ...string) (err error) {
initialSize := fi.Size()
// Open source database.
- src, err := Open(cmd.SrcPath, 0444, nil)
+ src, err := Open(cmd.SrcPath)
if err != nil {
return err
}
defer src.Close()
// Open destination database.
- dst, err := Open(cmd.DstPath, fi.Mode(), nil)
+ dst, err := Open(cmd.DstPath)
if err != nil {
return err
}
diff --git a/tests/dedo.go b/tests/dedo.go
index bb1d001..cef1433 100644
--- a/tests/dedo.go
+++ b/tests/dedo.go
@@ -1871,7 +1871,7 @@ func TestBucket_Delete_Quick(t *testing.T) {
func ExampleBucket_Put() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -1914,7 +1914,7 @@ func ExampleBucket_Put() {
func ExampleBucket_Delete() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -1972,7 +1972,7 @@ func ExampleBucket_Delete() {
func ExampleBucket_ForEach() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -2730,7 +2730,7 @@ func TestCursor_QuickCheck_BucketsOnly_Reverse(t *testing.T) {
func ExampleCursor() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -2784,7 +2784,7 @@ func ExampleCursor() {
func ExampleCursor_reverse() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -2846,7 +2846,7 @@ const pageSize = 4096
// Ensure that a database can be opened without error.
func TestOpen(t *testing.T) {
path := tempfile()
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
t.Fatal(err)
} else if db == nil {
@@ -2865,7 +2865,7 @@ func TestOpen(t *testing.T) {
// Ensure that opening a database with a blank path returns an error.
func TestOpen_ErrPathRequired(t *testing.T) {
- _, err := Open("", 0666, nil)
+ _, err := Open("")
if err == nil {
t.Fatalf("expected error")
}
@@ -2873,7 +2873,7 @@ func TestOpen_ErrPathRequired(t *testing.T) {
// Ensure that opening a database with a bad path returns an error.
func TestOpen_ErrNotExists(t *testing.T) {
- _, err := Open(filepath.Join(tempfile(), "bad-path"), 0666, nil)
+ _, err := Open(filepath.Join(tempfile(), "bad-path"))
if err == nil {
t.Fatal("expected error")
}
@@ -2895,7 +2895,7 @@ func TestOpen_ErrInvalid(t *testing.T) {
t.Fatal(err)
}
- if _, err := Open(path, 0666, nil); err != ErrInvalid {
+ if _, err := Open(path); err != ErrInvalid {
t.Fatalf("unexpected error: %s", err)
}
}
@@ -2933,7 +2933,7 @@ func TestOpen_ErrVersionMismatch(t *testing.T) {
}
// Reopen data file.
- if _, err := Open(path, 0666, nil); err != ErrVersionMismatch {
+ if _, err := Open(path); err != ErrVersionMismatch {
t.Fatalf("unexpected error: %s", err)
}
}
@@ -2971,7 +2971,7 @@ func TestOpen_ErrChecksum(t *testing.T) {
}
// Reopen data file.
- if _, err := Open(path, 0666, nil); err != ErrChecksum {
+ if _, err := Open(path); err != ErrChecksum {
t.Fatalf("unexpected error: %s", err)
}
}
@@ -3010,7 +3010,7 @@ func TestOpen_Size(t *testing.T) {
}
// Reopen database, update, and check size again.
- db0, err := Open(path, 0666, nil)
+ db0, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3084,7 +3084,7 @@ func TestOpen_Size_Large(t *testing.T) {
}
// Reopen database, update, and check size again.
- db0, err := Open(path, 0666, nil)
+ db0, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3114,7 +3114,7 @@ func TestOpen_Check(t *testing.T) {
path := tempfile()
defer os.Remove(path)
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3127,7 +3127,7 @@ func TestOpen_Check(t *testing.T) {
t.Fatal(err)
}
- db, err = Open(path, 0666, nil)
+ db, err = Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3152,7 +3152,7 @@ func TestOpen_FileTooSmall(t *testing.T) {
path := tempfile()
defer os.Remove(path)
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3165,7 +3165,7 @@ func TestOpen_FileTooSmall(t *testing.T) {
t.Fatal(err)
}
- db, err = Open(path, 0666, nil)
+ db, err = Open(path)
if err == nil || err.Error() != "file size too small" {
t.Fatalf("unexpected error: %s", err)
}
@@ -3184,7 +3184,7 @@ func TestDB_Open_InitialMmapSize(t *testing.T) {
testWriteSize := 1 << 27 // 134MB
- db, err := Open(path, 0666, &Options{})
+ db, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -3885,7 +3885,7 @@ func TestDB_BatchTime(t *testing.T) {
func ExampleDB_Update() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -3925,7 +3925,7 @@ func ExampleDB_Update() {
func ExampleDB_View() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -3968,7 +3968,7 @@ func ExampleDB_View() {
func ExampleDB_Begin_ReadOnly() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -4211,7 +4211,7 @@ type WDB struct {
// MustOpenDB returns a new, open DB at a temporary location.
func MustOpenDB() *WDB {
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
panic(err)
}
@@ -5701,7 +5701,7 @@ func TestTx_CopyFile(t *testing.T) {
t.Fatal(err)
}
- db2, err := Open(path, 0600, nil)
+ db2, err := Open(path)
if err != nil {
t.Fatal(err)
}
@@ -5804,7 +5804,7 @@ func TestTx_CopyFile_Error_Normal(t *testing.T) {
func ExampleTx_Rollback() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -5858,7 +5858,7 @@ func ExampleTx_Rollback() {
func ExampleTx_CopyFile() {
// Open the database.
- db, err := Open(tempfile(), 0666, nil)
+ db, err := Open(tempfile())
if err != nil {
log.Fatal(err)
}
@@ -5888,7 +5888,7 @@ func ExampleTx_CopyFile() {
}
// Open the cloned database.
- db2, err := Open(toFile, 0666, nil)
+ db2, err := Open(toFile)
if err != nil {
log.Fatal(err)
}
@@ -5917,7 +5917,7 @@ func ExampleTx_CopyFile() {
// Ensure the "info" command can print information about a database.
func TestInfoCommand_Run(t *testing.T) {
- db := MustOpen2(0666, nil)
+ db := MustOpen2()
defer db.Close()
db.DB.Close()
@@ -5935,7 +5935,7 @@ func TestStatsCommand_Run_EmptyDatabase(t *testing.T) {
t.Skip("system does not use 4KB page size")
}
- db := MustOpen2(0666, nil)
+ db := MustOpen2()
defer db.Close()
db.DB.Close()
@@ -5975,7 +5975,7 @@ func TestStatsCommand_Run(t *testing.T) {
t.Skip("system does not use 4KB page size")
}
- db := MustOpen2(0666, nil)
+ db := MustOpen2()
defer db.Close()
if err := db.Update(func(tx *Tx) error {
@@ -6063,13 +6063,13 @@ func NewMainTW() *MainTW {
}
// MustOpen creates a Bolt database in a temporary location.
-func MustOpen2(mode os.FileMode, options *Options) *WDB2 {
+func MustOpen2() *WDB2 {
// Create temporary path.
f, _ := ioutil.TempFile("", "bolt-")
f.Close()
os.Remove(f.Name())
- db, err := Open(f.Name(), mode, options)
+ db, err := Open(f.Name())
if err != nil {
panic(err.Error())
}
@@ -6095,11 +6095,11 @@ func TestCompactCommand_Run(t *testing.T) {
}
rand.Seed(s)
- dstdb := MustOpen2(0666, nil)
+ dstdb := MustOpen2()
dstdb.Close()
// fill the db
- db := MustOpen2(0666, nil)
+ db := MustOpen2()
defer db.Close()
if err := db.Update(func(tx *Tx) error {
n := 2 + rand.Intn(5)
@@ -6221,7 +6221,7 @@ func fillBucket(b *Bucket, prefix []byte) error {
}
func chkdb(path string) ([]byte, error) {
- db, err := Open(path, 0666, nil)
+ db, err := Open(path)
if err != nil {
return nil, err
}