def __init__(self, base_dir):
        self.base_dir = base_dir
        self.blobs_dir = os.path.join(base_dir, 'blobs')
        self.links_dir = os.path.join(base_dir, 'links')
        self.locks_dir = os.path.join(base_dir, 'locks')
        self.db_dir = os.path.join(base_dir, 'db')

        _makedirs(self.blobs_dir)
        _makedirs(self.links_dir)
        _makedirs(self.locks_dir)
        _makedirs(self.db_dir)

        # https://docs.oracle.com/cd/E17076_05/html/programmer_reference/transapp_env_open.html
        self.db_env = bsddb3.db.DBEnv()
        try:
            self.db_env.open(
                self.db_dir,
                bsddb3.db.DB_CREATE
                | bsddb3.db.DB_INIT_LOCK
                | bsddb3.db.DB_INIT_LOG
                | bsddb3.db.DB_INIT_MPOOL
                | bsddb3.db.DB_INIT_TXN
                | bsddb3.db.DB_REGISTER,
            )
        except bsddb3.db.DBRunRecoveryError:
            raise RuntimeError(
                'DB requires recovery! It should have run in .run.main...'
            )

        self.db = bsddb3.db.DB(self.db_env)
        self.db.open(
            'metadata',
            dbtype=bsddb3.db.DB_HASH,
            flags=bsddb3.db.DB_CREATE | bsddb3.db.DB_AUTO_COMMIT,
        )