Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read-Only mode? #13

Closed
coreyog opened this issue Jun 3, 2017 · 1 comment
Closed

Read-Only mode? #13

coreyog opened this issue Jun 3, 2017 · 1 comment

Comments

@coreyog
Copy link

coreyog commented Jun 3, 2017

I have a trivial testing app:

package main

import (
	"fmt"
	"strconv"

	"github.com/boltdb/bolt"
)

func main() {
	db, err := bolt.Open("my.db", 0600, nil)
	if err != nil {
		panic(err)
	}
	defer db.Close()

	err = db.Update(func(tx *bolt.Tx) (err error) {
		bucket, err := tx.CreateBucketIfNotExists([]byte("Test"))
		if err != nil {
			return err
		}
		raw := bucket.Get([]byte("num"))
		num := 0
		if len(raw) != 0 {
			num, err = strconv.Atoi(string(raw))
			if err != nil {
				return err
			}
		}
		num++
		fmt.Println(num)
		bucket.Put([]byte("num"), []byte(strconv.Itoa(num)))
		return nil
	})
	if err != nil {
		panic(err)
	}
}

Every time you run it, it reads a number, increments it, and puts it back.

If I have boltbrowser connected to my.db and I run my app then my app sits and waits until boltbrowser releases it's connection. I know bolt only allows 1 write transaction at a time. It'd be nice if boltbrowser had a read only flag so viewing a DB that's currently under use won't halt all interactions with the database.

I imagine if another process is changing the DB then there's no way to know for sure if a value in a bucket didn't change immediately after being accessed and shown on the screen. Personally I'm ok with that.

It looks like all you'd have to do is prevent p/P, b/B, D, e, and r key presses if an "-ro" flag is present. Maybe just show a popup saying "Cannot do that in Read Only mode."

@coreyog
Copy link
Author

coreyog commented Jun 3, 2017

Nevermind, after a little more research I see that Bolt does not allow multiple processes to access the DB file at the same time. Nothing you can do about that.

@coreyog coreyog closed this as completed Jun 3, 2017
backwardn pushed a commit to backwardn/boltbrowser that referenced this issue Oct 2, 2019
backwardn pushed a commit to backwardn/boltbrowser that referenced this issue Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant