You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
code below, db unable to be opened by "client" program. why and how to make it work so that the db can be opened by all?
server
package main
import (
"fmt"
"log"
"time"
bolt "go.etcd.io/bbolt"
)
func main() {
db, err := bolt.Open("/dev/shm/bbolt.db", 0600, &bolt.Options{
ReadOnly: false,
NoFreelistSync: true, // This disables freelist sync
})
if err != nil {
log.Fatal(err)
}
defer db.Close()
key := []byte("key")
value := []byte("value")
start := time.Now()
for i := 0; i < 100000; i++ {
err = db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte("MyBucket"))
if err != nil {
return err
}
err = b.Put(key, value)
if err != nil {
return err
}
return nil
})
if err != nil {
log.Fatal(err)
}
time.Sleep(1 * time.Second) // Slows down updates for demonstration
}
end := time.Now()
fmt.Printf("Iteration %d took %s\n", 100000, end.Sub(start))
}
client
package main
import (
"fmt"
"log"
"time"
bolt "go.etcd.io/bbolt"
)
func main() {
log.Printf("can't open while server running")
db, err := bolt.Open("/dev/shm/bbolt.db", 0600, &bolt.Options{ReadOnly: true})
if err != nil {
log.Fatalf("Failed to open db: %v", err)
}
defer db.Close()
log.Printf("stuck before here")
key := []byte("key")
for {
err = db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("MyBucket"))
if b == nil {
return fmt.Errorf("bucket MyBucket not found")
}
value := b.Get(key)
if value == nil {
return fmt.Errorf("key not found")
}
fmt.Printf("Latest value: %s\n", value)
return nil
})
if err != nil {
log.Printf("Error reading db: %v", err)
}
time.Sleep(1 * time.Second) // Check for new values every second
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
code below, db unable to be opened by "client" program. why and how to make it work so that the db can be opened by all?
server
client
Beta Was this translation helpful? Give feedback.
All reactions