Skip to content

Instantly share code, notes, and snippets.

@GregIngelmo
Created February 22, 2015 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GregIngelmo/a0b6b023bea4d9f7d692 to your computer and use it in GitHub Desktop.
Save GregIngelmo/a0b6b023bea4d9f7d692 to your computer and use it in GitHub Desktop.
Bolt #299
package main
import (
"log"
"os"
"github.com/boltdb/bolt"
)
var path = "bolt.db"
func main() {
os.Remove(path)
var val []byte
// 255.996055603 MiB ... no problem
val = make([]byte, 268431320)
writeKey("testkey", val)
// 255.9960565567 MiB ... panic
val = make([]byte, 268431321)
writeKey("testkey", val)
}
func writeKey(key string, val []byte) {
db, err := bolt.Open(path, 0600, nil)
defer db.Close()
if err != nil {
log.Fatal(err)
}
err = db.Update(func(tx *bolt.Tx) error {
bucket, _ := tx.CreateBucketIfNotExists([]byte("testbucket"))
err := bucket.Put([]byte(key), val)
if err != nil {
return err
}
return nil
})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment