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

"invalid argument" when opening db #272

Closed
ktmn opened this issue Dec 29, 2014 · 8 comments
Closed

"invalid argument" when opening db #272

ktmn opened this issue Dec 29, 2014 · 8 comments

Comments

@ktmn
Copy link

ktmn commented Dec 29, 2014

I got a new docker container "google/golang"

gopath/src/test contains this file, main.go:

package main

import (
    "github.com/boltdb/bolt"
    "log"
)

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

I do a

go get github.com/boltdb/bolt

and then in the gopath/src/test directory I run

go run main.go

Result:

2014/12/29 01:51:34 invalid argument
exit status 1

A 16kb data.db file is created.

go version go1.3.1 linux/amd64


Probably some rookie mistake. But it works on my Windows. So what am I missing?

@kmanley
Copy link

kmanley commented Dec 29, 2014

I can't dupe this. What's your OS version? Can you step into it with gdb? Looking at the implementation of Open (https://github.com/boltdb/bolt/blob/master/db.go#L97), if you're seeing the file get created then it's possible the flock or mmap calls are failing.

@benbjohnson
Copy link
Member

@ktmn Do you know what kind of file system you're using in the Docker container? As @kmanley mentioned, it may be that flock() or mmap() aren't supported.

@ktmn
Copy link
Author

ktmn commented Jan 4, 2015

So the problem was indeed my mistake. I should have mentioned the way I ran the docker container was by mounting my files (first from Windows to VM, then) from VM to the docker container (basically I'm running docker on a virtual machine, just like boot2docker does it also)

docker run -i -t -v /media/sf_go/src/test:/gopath/src/test google/golang /bin/bash

Here's what went down when compiling main.go according to strace if it tells anyone anything: http://pastebin.com/raw.php?i=CKWuMSHL

I guess bolt couldn't deal with the Windows file system as it was running on some form of Linux.

So I mounted to volume to another path, copied them over to gopath and things worked great.

@benbjohnson
Copy link
Member

@ktmn Awesome! I'm glad to hear it worked out. As for the strace, nothing jumps out at me but thanks for posting it.

@pindamonhangaba
Copy link

This also happens when trying to open a database on a shared vagrant folder, with a Windows host.

@scotthelm
Copy link

Using Vagrant on a Mac host with a linux virtual, I experienced the same issue. I found that using nfs for the synched folders worked well.

config.vm.synced_folder local_dev_dir, "/my/go/path", nfs: true, map_uid: 0, map_gid: 0

@ascotan
Copy link

ascotan commented Aug 26, 2015

BTW I ran into this issue on vagrant with bolt. The problem is that a mmap'ed file can not be run out of a shared folder when the options to mmap are set to MAP_SHARED. strace reports the following:

stat("xxx.db", {st_mode=S_IFREG|0600, st_size=32768, ...}) = 0
open("xxx.db", O_RDWR|O_CREAT|O_CLOEXEC, 0666) = 3
flock(3, LOCK_EX|LOCK_NB)               = 0
fstat(3, {st_mode=S_IFREG|0600, st_size=32768, ...}) = 0
pread(3, "\0\0\0\0\0\0\0\0\4\0\0\0\0\0\0\0\355\332\f\355\2\0\0\0\0\20\0\0\0\0\0\0"..., 4096, 0) = 4096
fstat(3, {st_mode=S_IFREG|0600, st_size=32768, ...}) = 0
ftruncate(3, 32768)                     = 0
futex(0x609500, FUTEX_WAKE, 1)          = 1
fsync(3)                                = 0
mmap(NULL, 32768, PROT_READ, MAP_SHARED, 3, 0) = -1 EINVAL (Invalid argument)
flock(3, LOCK_UN)                       = 0
close(3)                                = 0
futex(0x609500, FUTEX_WAKE, 1)          = 1
write(1, "invalid argument\n", 17invalid argument

See here: http://man7.org/linux/man-pages/man2/mmap.2.html and here: http://stackoverflow.com/questions/18420473/invalid-argument-for-read-write-mmap and here: https://www.virtualbox.org/ticket/819

Basically you can't run a boltdb file out of a shared folder in Virtualbox, especially if your on a mac.
The workaround here is to run the boltdb file out of a non-shared folder.

@treeder
Copy link

treeder commented Jun 20, 2016

I was getting this on Mac using Docker with a mounted volume (docker-machine), so I just downloaded the Docker for Mac Beta and it fixed it. https://www.docker.com/products/docker#/mac

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants