Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

can't initialise database #193

Open
gijzelaerr opened this issue Sep 6, 2017 · 7 comments
Open

can't initialise database #193

gijzelaerr opened this issue Sep 6, 2017 · 7 comments

Comments

@gijzelaerr
Copy link
Contributor

λ  virtualenv -p python2 venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /tmp/venv/bin/python2
Also creating executable in /tmp/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
λ  venv/bin/pip install numpy 
Collecting numpy
  Using cached numpy-1.13.1-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.13.1
λ  venv/bin/pip install monetdblite
Collecting monetdblite
Installing collected packages: monetdblite
Successfully installed monetdblite-0.1.9
λ  venv/bin/python -c "import monetdblite; monetdblite.init('gijs')"
!GDKenvironment: directory not an absolute path: gijs.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/venv/local/lib/python2.7/site-packages/monetdblite/__init__.py", line 40, in init
    return embeddedmonetdb.init(*args, **kwargs)
  File "/tmp/venv/local/lib/python2.7/site-packages/monetdblite/embeddedmonetdb.py", line 80, in init
    raise __throw_exception(str(retval) + ' in ' + str(directory))
  File "/tmp/venv/local/lib/python2.7/site-packages/monetdblite/embeddedmonetdb.py", line 74, in __throw_exception
    raise exceptions.DatabaseError(str.replace('MALException:', ''))
monetdblite.exceptions.DatabaseError: Failed to initialize MonetDB: GDKinit() failed. in gijs
λ  ls -al gijs
total 28
drwxr-xr-x  2 gijs gijs  4096 sep  6 09:51 .
drwxrwxrwt 19 root root 20480 sep  6 09:51 ..
@gijzelaerr
Copy link
Contributor Author

ah only now I see the absolute path error, oops. Still this is not very user friendly.

@gijzelaerr
Copy link
Contributor Author

Ok so this actually only fails the first time. So if you init/connect a database with a absolute path first time, the second time you can access DB's with a relative path.

@gijzelaerr
Copy link
Contributor Author

realize now this is probably related to #193 and I guess you can only operate on one db connection per Python session.

@hannes
Copy link
Owner

hannes commented Sep 6, 2017

You can have multiple connections but not different db directories at the same time. In the R frontend we catch this, perhaps also a good idea for Python @Mytherin

@caewok
Copy link

caewok commented Sep 9, 2017

You mention having multiple connections but not different db directories at the same time. It looks like a single R session can have multiple connections, but different R sessions (or different threads) cannot simultaneously connect to the same embedded database.

It would be useful to allow this for certain situations, such as when using threading (leaving aside the potential for data corruption if a table is modified simultaneously---that could be handled with a table lock upon modification)

Right now, multiple connections work, for example:

library(MonetDBLite)
library(DBI)
dir.create("monetdb_tmp")
dbdir <- "monetdb_tmp"
con <- ml(dbdir)
con2 <- ml(dbdir)
dbWriteTable(con, "mtcars", mtcars)
dbGetQuery(con, "SELECT MAX(mpg) FROM mtcars WHERE cyl = 8")
dbGetQuery(con2, "SELECT MAX(mpg) FROM mtcars WHERE cyl = 8")

But if you start a second R session, say in a new terminal, connecting to the database throws the error:

# in second R session
library(MonetDBLite)
library(DBI)
dbdir <- "monetdb_tmp"
con <- ml(dbdir)
# Error in monetdb_embedded_startup(embedded, !getOption("monetdb.debug.embedded",  : 
# Failed to initialize embedded MonetDB !FATAL: BBPaddfarm: bad rolemask 

A similar thing happens if you attempt multiple connections in separate threads:

library(parallel)
cl <- makeCluster(3)
parLapply(cl = cl, 1:3, function(i, dbdir) { 
library(MonetDBLite)
library(DBI)
new_con <- ml(dbdir)
out <- dbGetQuery(new_con, "SELECT MAX(mpg) FROM mtcars WHERE cyl = 8")
dbDisconnect(new_con)
out
}, dbdir = dbdir)
#   3 nodes produced errors; first error: Failed to initialize embedded MonetDB !FATAL:
# GDKlockHome: Database lock 'monetdb_tmp/.gdk_lock' denied 

Note that the mclapply family functions work (with forking), probably due to the shared memory.

@hannes
Copy link
Owner

hannes commented Sep 13, 2017

Multiple threads works, multiple processes does not. Its non-trivial to allow multiple process access to the same data directory. I suggest using a stand-alone MonetDB server in those cases.

@gijzelaerr
Copy link
Contributor Author

gijzelaerr commented Sep 15, 2017 via email

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

3 participants