symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

Error while requesting database lock #105

Closed pewsplosions closed 4 years ago

pewsplosions commented 4 years ago

I am trying to just get started. I'm stuck with this error though. I'm using a Macbook.

I pulled the source from here. Made a build dir. Inside the build dir, ran cmake .. which worked fine. Ran make. It built fine. So then I copy libunqlite.a and unqlite.h to my project. Made this simple main.c file.

#include <stdio.h>
#include <unqlite.h>

int main()
{
  int rc;
  unqlite *pDb;

  // Open our database;
  rc = unqlite_open(&pDb, "test.db", UNQLITE_OPEN_CREATE);
  if (rc != UNQLITE_OK)
  {
    printf("%s", "Failed to open/create database.");
    return 1;
  }

  // Store some records
  rc = unqlite_kv_store(pDb, "test", -1, "Hello World", 11); //test => 'Hello World'
  if (rc != UNQLITE_OK)
  {
    printf("%s", "Failed to do kv store.");
    return 1;
  }

  unqlite_close(pDb);
  return 0;
}

1st, I tried just the open, then close statements. This did nothing, not even create a test.db.

2nd, I added the kv store statement. This made it create a test.db file. But the call to unqlite_kv_store returns -76, which is UNQLITE_LOCKERR or if I use the error printing method from the examples, I get the message Error while requesting database lock.

I cannot seem to find any information about this error. So I don't really know where to go from here. Any help would be appreciated. Thanks!

symisc commented 4 years ago

Looks like the test database is opened by another thread or process from your terminal? Instead of using 'test.db' as database name, using something else and try running your program again.

pewsplosions commented 4 years ago

@symisc Hi thanks for the reply. I changed the name and it has the same behavior.

Not sure if this will help but I use meson. It builds fine. puts my executable 'sandbox' in the build folder. I am just running ./build/sandbox

The database does not exist yet. When I run the program, it creates a test.db file (or whatever the name is.) Then on the kv store line it gets the locker error.

The test.db file it creates seems to just be an empty file. It is 0 bytes. When I open it with a text editor it is just an empty file.

So even though the open call seems to work, maybe it is not properly creating the database?

symisc commented 4 years ago

Looks like the issue come from your sandbox environment which is not granting the exclusive write lock required by the database in the current directory. In which case, the database is put in waiting state until it got the exclusive lock to start writing...

pewsplosions commented 4 years ago

@symisc That makes sense. Everything else I've tried that involves messing with files/dirs seems okay. But I haven't really looked into any kind of permissions that may be causing problems. I am currently working off a network drive. So I will copy my project over to the main drive and try again.

Is there anything that comes to mind that may cause this that I could try to fix things with if it isn't the network drive?

Thanks again for the help.

pewsplosions commented 4 years ago

Quick update. When I copied the project to my main drive, everything worked fine. So it is definitely something odd about my networked drive.

So I guess that leads me to the question of... why would this happen on a network drive?

Either way... thanks for the help. If the network drive thing is not something that needs looking into, this can probably be closed then. I'll just work with my project on the main drive.