Skip to content

Commit

Permalink
Migrate from bsddb3 to berkeleydb
Browse files Browse the repository at this point in the history
Following official documentation, move away from bsddb3 to berkeleydb.
https://www.jcea.es/programacion/pybsddb.htm

Main change: key and values are now bytes and not strings.

The code diff is really simple because all operations on keys/values is
done from elixir/data.py and that works fine with both bytes and
strings (it does explicit casting).
  • Loading branch information
fstachura authored and tleb committed Nov 7, 2024
1 parent 7df3543 commit 5e8eb77
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ RUN \

WORKDIR /build/

# TODO switch to berkeleydb
# NOTE wheel version MUST be sycnhronized with requirements.txt
RUN pip wheel bsddb3==6.2.9
RUN pip wheel berkeleydb==18.1.10

FROM debian:bookworm

Expand All @@ -37,11 +36,11 @@ COPY . /usr/local/elixir/

WORKDIR /usr/local/elixir/

COPY --from=build /build/bsddb3-6.2.9-*.whl /tmp/build/
COPY --from=build /build/berkeleydb-*.whl /tmp/build/

RUN python3 -m venv venv && \
. ./venv/bin/activate && \
pip install /tmp/build/bsddb3-6.2.9-*.whl && \
pip install /tmp/build/berkeleydb-*.whl && \
pip install -r requirements.txt

RUN mkdir -p /srv/elixir-data/
Expand Down
2 changes: 1 addition & 1 deletion elixir/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import json
from urllib import parse
from bsddb3.db import DB_SET_RANGE
from berkeleydb.db import DB_SET_RANGE
import falcon

from .lib import autoBytes, validFamily
Expand Down
12 changes: 6 additions & 6 deletions elixir/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.

import bsddb3
import berkeleydb
import re
from .lib import autoBytes
import os
Expand Down Expand Up @@ -147,15 +147,15 @@ def pack(self):
class BsdDB:
def __init__(self, filename, readonly, contentType, shared=False):
self.filename = filename
self.db = bsddb3.db.DB()
flags = bsddb3.db.DB_THREAD if shared else 0
self.db = berkeleydb.db.DB()
flags = berkeleydb.db.DB_THREAD if shared else 0

if readonly:
flags |= bsddb3.db.DB_RDONLY
flags |= berkeleydb.db.DB_RDONLY
self.db.open(filename, flags=flags)
else:
flags |= bsddb3.db.DB_CREATE
self.db.open(filename, flags=flags, mode=0o644, dbtype=bsddb3.db.DB_BTREE)
flags |= berkeleydb.db.DB_CREATE
self.db.open(filename, flags=flags, mode=0o644, dbtype=berkeleydb.db.DB_BTREE)
self.ctype = contentType

def exists(self, key):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pygments~=2.18.0
Falcon @ git+https://github.com/falconry/falcon.git@cbca63dc7739720eab856f48b32f9e782438be7a
pytest==7.2.1

# NOTE binary wheels of bsddb3 are not distributed - on Debian this may
# NOTE binary wheels of berkeleydb are not distributed - on Debian this may
# require installing build-essentials, python3-dev and libdb-dev
# NOTE keep in sync with wheel version in the Dockerfile
bsddb3==6.2.9
berkeleydb==18.1.10

0 comments on commit 5e8eb77

Please sign in to comment.