Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

concurrent writes and deadlocks #739

Open
@winteraz

Description

Only one read-write transaction is allowed at a time.

From documentation I understand that concurrent writes are not allowed. I'm not sure if this is correct thus this question to clarify: is boltdb designed only for one single writer (globally)? Am I suppose to maintain a lock on any write?
Use case:
I want to store access logs of http requests. Does this mean that I need to use a global channel to serialise the access bolt writes ?


e.g. 

var globalChan = make(chan string, 10)

func init() {
	const bucketName = "widgets"
	tx, err := db.Begin(true)
	if err != nil {
		panic(err)
	}
	_, err = tx.CreateBucketIfNotExists([]byte(bucketName))
	if err != nil {
		return err
	}
	go func() {
		for URL := range globalCHan {
			tx, err := db.Begin(true)
			if err != nil {
				panic(err)
			}
			bk := tx.Bucket([]byte(bucketName))
			// Set the value "bar" for the key "foo".
			if err := b.Put([]byte(time.Now().String()), []byte("bar")); err != nil {
				return err
			}
		}

	}()
}

func HandleFunc(w http.ResponseWriter, r *http.Request) {
    globalChan <- r.URL.String()
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions