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
I created bolt databases under Windows/Linux/Mac and insert 100000 and 1000 records into the database. Then I got the result below:
file
records
created under
file size
md5sum
win_1000.db
1000
Windows
262144
05d62c9653360e15d35625759947e8ea
linux_1000.db
1000
Linux
262144
05d62c9653360e15d35625759947e8ea
mac_1000.db
1000
Mac
262144
05d62c9653360e15d35625759947e8ea
win_100000.db
100000
Windows
33554432
aa11783743dc42f44778ffbcbc4b0ba9
linux_100000.db
100000
Linux
34795520
b7cc6445179f70911d27f682903632d9
mac_100000.db
100000
Mac
34795520
b7cc6445179f70911d27f682903632d9
Things I found:
If the number of the data is small, no matter which OS you use to create the database, the database files are all the same (same size and same content).
If insert a large number of date into the database, the one created under Windows is different with the one created under Linux or Mac. See win_100000.db above.
All database files can be recognized under Linux or Mac no matter which OS the database is created from.
A database with a large number of data created under Linux or Mac can not be recognized under Windows. There will be an error when opening the database: CreateFileMapping: Not enough storage is available to process this command.
Could the 2nd and 4th point above be fixed?
Below is the code for test:
// file: test-bolt.gopackage main
import (
"crypto/sha512""flag""fmt""io""os""github.com/coreos/bbolt"
)
funcfileExist(filenamestring) bool {
_, err:=os.Stat(filename)
iferr==nil {
returntrue
}
ifos.IsNotExist(err) {
returnfalse
}
returntrue
}
funcgenData(nint) []byte {
h:=sha512.New()
io.WriteString(h, fmt.Sprintf("%d", n))
returnh.Sum(nil)
}
funccreate(filenamestring, nint) (errerror) {
iffileExist(filename) {
err=fmt.Errorf("%s already exist, please use another file name", filename)
return
}
db, err:=bolt.Open(filename, 0600, nil)
iferr!=nil {
return
}
deferdb.Close()
fmt.Fprintf(os.Stderr, "add %d records to %s:\n", n, filename)
err=db.Update(func(tx*bolt.Tx) error {
b, err:=tx.CreateBucket([]byte("data"))
iferr!=nil {
returnerr
}
variintfori=1; i<=n; i++ {
err=b.Put([]byte(fmt.Sprintf("%d", i)), genData(i))
iferr!=nil {
returnerr
}
ifi%2000==0 {
fmt.Printf("%d records added\n", i)
}
}
i--ifi%2000!=0 {
fmt.Printf("%d records added\n", i)
}
returnnil
})
iferr==nil {
fmt.Println("done")
}
return
}
funccheck(filenamestring) (errerror) {
if!fileExist(filename) {
err=fmt.Errorf("%s not exist", filename)
return
}
db, err:=bolt.Open(filename, 0600, &bolt.Options{ReadOnly:true})
iferr!=nil {
return
}
deferdb.Close()
err=db.View(func(tx*bolt.Tx) error {
b:=tx.Bucket([]byte("data"))
ifb==nil {
returnfmt.Errorf(`bucket "data" not found`)
}
fmt.Printf("%s has %d records.\n", filename, b.Stats().KeyN)
returnnil
})
return
}
constusage=`test-boltUsage: test-bolt -m create -n <integer> <filename> test-bolt -m check <filename>Options: -m <create|check> create or check bolt database -n <integer> number of records to insert into the database -h help message`funcmain() {
varmethod, filenamestringvarnintvarhelpboolflag.StringVar(&method, "m", "", "create or check bolt database")
flag.IntVar(&n, "n", 0, "number of records to insert into the database")
flag.BoolVar(&help, "h", false, "help message")
flag.Parse()
ifhelp {
fmt.Println(usage)
os.Exit(0)
}
ifmethod!="create"&&method!="check" {
fmt.Fprintln(os.Stderr, `value of -m must be "create" or "check"`)
os.Exit(1)
}
ifmethod=="create"&&n<=0 {
fmt.Fprintln(os.Stderr, "value of -n must > 0")
os.Exit(1)
}
args:=flag.Args()
iflen(args) ==0 {
fmt.Fprintln(os.Stderr, "please input database filename")
os.Exit(1)
}
filename=args[0]
ifmethod=="create" {
err:=create(filename, n)
iferr!=nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
} else {
err:=check(filename)
iferr!=nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}
Test command:
Create database with 1000 records under Windows:
go run test-bolt.go -m create -n 1000 win_1000.db
Create database with 100000 records under Windows:
go run test-bolt.go -m create -n 100000 win_100000.db
Create database with 1000 records under Linux:
go run test-bolt.go -m create -n 1000 linux_1000.db
Create database with 100000 records under Linux:
go run test-bolt.go -m create -n 100000 linux_100000.db
Create database with 1000 records under Mac:
go run test-bolt.go -m create -n 1000 mac_1000.db
Create database with 100000 records under Mac:
go run test-bolt.go -m create -n 100000 mac_100000.db
Check database under Windows, Linux and Mac:
go run test-bolt.go -m check win_1000.db
go run test-bolt.go -m check win_100000.db
go run test-bolt.go -m check linux_1000.db
go run test-bolt.go -m check linux_100000.db
go run test-bolt.go -m check mac_1000.db
go run test-bolt.go -m check mac_100000.db
The text was updated successfully, but these errors were encountered:
m3ng9i
changed the title
Large database created under Windows is not the same as created under Linux Or Mac
Large database created under Windows is not the same as created under Linux or Mac
Apr 24, 2018
I found that in function mmap in bolt_windows.go, if the parameter sz's value is greater than the database's file size, an error of CreateFileMapping: Not enough storage is available to process this command. will return.
If run go run test-bolt.go -m check linux_100000.db under Windows, the value of sz in mmap is 67108864, and the size of linux_100000.db is 34795520, so the error return.
The parameter sz of function mmap is returned by function mmapSize in db.go.
I created bolt databases under Windows/Linux/Mac and insert 100000 and 1000 records into the database. Then I got the result below:
Things I found:
win_100000.db
above.CreateFileMapping: Not enough storage is available to process this command.
Could the 2nd and 4th point above be fixed?
Below is the code for test:
Test command:
Create database with 1000 records under Windows:
Create database with 100000 records under Windows:
Create database with 1000 records under Linux:
Create database with 100000 records under Linux:
Create database with 1000 records under Mac:
Create database with 100000 records under Mac:
Check database under Windows, Linux and Mac:
The text was updated successfully, but these errors were encountered: