Yenya's World

Wed, 11 Jan 2006

Using BerkeleyDB in Perl

I have rewritten parts of the software for access terminals so that it uses BerkeleyDB for the internal communication and data storage. It used SysV IPC before - semaphores for locking and shared memory segments for data transfer. SysV IPC has a drawback that the key value has to be set explicitly, so that if multiple installations of the same software are to be run on one host, the keys have to be carefully set to different values.

Since I use BerkeleyDB Hash database as cache of allowed cards, I have decided to use the BerkeleyDB for other things as well - the Queue database instead of SysV SHM as a queue of operations, and a dummy Hash database in the Concurrent Data Store mode for locking.

There is a minor glitch in the Perl bindings to BerkeleyDB - when this module is used with Recno or Queue databases tied to a Perl array, the shift operator does not work as expected: It returns and removes the first value of an array, but does not shift the indices of the array members:

@a = (1, 2, 3); shift @a;
# Expected: @a = (2, 3);
# Actual results: @a = (undef, 2, 3);

The renumbering would be too expensive in BerkeleyDB by default, so I expect it has been omitted for performance reasons. The solution is to use the Recno database opened with -Property => DB_RENUMBER option, which does exactly what is expected. I hope I will get time to submit a patch to the (rather incomplete) documentation.

Section: /computers (RSS feed) | Permanent link | 0 writebacks


Yenya's World: Linux and beyond - Yenya's blog.


RSS feed

Jan "Yenya" Kasprzak

The main page of this blog



Blog roll:

alphabetically :-)