Issue #5 resolved

Can't open database after wrong db.create() call

ont
created an issue

Run this code twice:

from CodernityDB.database_thread_safe import ThreadSafeDatabase


def main():
    db = ThreadSafeDatabase('/tmp/tut_xxx')
    db.create()
    for x in xrange(100):
        print db.insert(dict(x=x))

    for curr in db.all('id'):
        print curr

if __name__ == '__main__':
    main()

You will receive message that DB already exists, then change code to this:

from CodernityDB.database_thread_safe import ThreadSafeDatabase


def main():
    db = ThreadSafeDatabase('/tmp/tut_xxx')
    if db.exists():
        db.open()
        db.reindex()
    else:
        db.create()
        for x in xrange(100):
            print db.insert(dict(x=x))


    for curr in db.all('id'):
        print curr

if __name__ == '__main__':
    main()

And you should receive this error traceback:

Traceback (most recent call last):
  File "ccc.py", line 19, in <module>
    main()
  File "ccc.py", line 7, in main
    db.open()
  File "CodernityDB/database_safe_shared.py", line 103, in open
    res = super(SafeDatabase, self).open(*args, **kwargs)
  File "CodernityDB/database.py", line 502, in open
    self._read_indexes()
  File "CodernityDB/database.py", line 435, in _read_indexes
    self.add_index('path:' + ind, create=False)
  File "CodernityDB/database_safe_shared.py", line 127, in add_index
    res = super(SafeDatabase, self).add_index(*args, **kwargs)
  File "CodernityDB/database.py", line 305, in add_index
    ind_obj, name = self.__write_index(new_index, _next, edit=False)
  File "CodernityDB/database.py", line 250, in __write_index
    raise IndexConflict("Already exists")
CodernityDB.index.IndexConflict: Already exists

So one wrong call to db.create() can lock whole database.

Comments (1)

  1. Log in to comment