How to use the bsddb3.db.DB_THREAD function in bsddb3

To help you get started, we’ve selected a few bsddb3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freenas / freenas / gui / common / freenascache.py View on Github external
def __init__(self, cachedir=FREENAS_CACHEDIR):
        log.debug("FreeNAS_BaseCache._init__: enter")

        self.cachedir = cachedir
        self.__cachefile = os.path.join(self.cachedir, ".cache.db")

        if not self.__dir_exists(self.cachedir):
            os.makedirs(self.cachedir)

        flags = db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_LOG | \
            db.DB_INIT_MPOOL | db.DB_THREAD | db.DB_INIT_TXN

        self.__dbenv = db.DBEnv()
        self.__dbenv.open(
            self.cachedir,
            flags,
            0o700
        )

        self.__cache = db.DB(self.__dbenv)
        self.__cache.open(self.__cachefile, None, db.DB_HASH, db.DB_CREATE)

        log.debug("FreeNAS_BaseCache._init__: cachedir = %s", self.cachedir)
        log.debug(
            "FreeNAS_BaseCache._init__: cachefile = %s",
            self.__cachefile
github RDFLib / rdflib / rdflib / plugins / sleepycat.py View on Github external
has_bsddb = True
except ImportError:
    try:
        from bsddb3 import db
        has_bsddb = True
    except ImportError:
        has_bsddb = False


if has_bsddb:
    # These are passed to bsddb when creating DBs

    # passed to db.DBEnv.set_flags
    ENVSETFLAGS = db.DB_CDB_ALLDB
    # passed to db.DBEnv.open
    ENVFLAGS = db.DB_INIT_MPOOL | db.DB_INIT_CDB | db.DB_THREAD
    CACHESIZE = 1024 * 1024 * 50

    # passed to db.DB.Open()
    DBOPENFLAGS = db.DB_THREAD

logger = logging.getLogger(__name__)

__all__ = ['Sleepycat']


class Sleepycat(Store):
    context_aware = True
    formula_aware = True
    transaction_aware = False
    graph_aware = True
    db_env = None
github RDFLib / rdflib / rdflib / backends / SleepyCat.py View on Github external
def open(self, file):
        homeDir = file        
        envsetflags  = db.DB_CDB_ALLDB
        envflags = db.DB_INIT_MPOOL | db.DB_INIT_CDB | db.DB_THREAD
        try:
            if not exists(homeDir):
                mkdir(homeDir)
        except Exception, e:
            print e
        self.env = env = db.DBEnv()
        env.set_cachesize(0, 1024*1024*50)
        #env.set_lg_max(1024*1024)
        env.set_flags(envsetflags, 1)
        env.open(homeDir, envflags | db.DB_CREATE)

        self.__open = 1
        
        dbname = None
        dbtype = db.DB_BTREE
        dbopenflags = db.DB_THREAD
github RDFLib / rdflib / rdflib / store / backends / SleepyCatBacked.py View on Github external
def open(self, file):
        homeDir = file        
        envsetflags  = 0
        envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_CDB
        try:
            if not exists(homeDir):
                mkdir(homeDir)
        except Exception, e:
            print e
        self.env = env = db.DBEnv()
        env.set_cachesize(0, 1024*1024*50)
        #env.set_lg_max(1024*1024)
        env.set_flags(envsetflags, 1)
        env.open(homeDir, envflags | db.DB_CREATE)

        self.__open = 1
        
        dbname = None
        dbtype = db.DB_BTREE
        dbopenflags = db.DB_THREAD #| db.DB_AUTO_COMMIT
github RDFLib / rdfextras / rdfextras / store / BerkeleyDB.py View on Github external
def _init_db_environment(self, homeDir, create=True):
        #NOTE: The identifier is appended to the path as the location for the 
        # db. This provides proper isolation for stores which have the same 
        # path but different identifiers
        
        if SUPPORT_MULTIPLE_STORE_ENVIRON:
            fullDir = join(homeDir,self.identifier)
        else:
            fullDir = homeDir
        envsetflags  = db.DB_CDB_ALLDB
        envflags = db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_THREAD | \
                                            db.DB_INIT_TXN | db.DB_RECOVER
        if not exists(fullDir):
            if create==True:
                makedirs(fullDir)
                self.create(fullDir)
            else:
                return NO_STORE
        
        db_env = db.DBEnv()
        db_env.set_cachesize(0, 1024*1024*50) # TODO
        
        # enable deadlock-detection
        db_env.set_lk_detect(db.DB_LOCK_MAXLOCKS)
        
        # increase the number of locks, this is correlated to the size 
        # (num triples) that can be added/removed with a single transaction
github RDFLib / rdflib / rdflib / plugins / sleepycat.py View on Github external
def _init_db_environment(self, homeDir, create=True):
        envsetflags  = db.DB_CDB_ALLDB
        envflags = db.DB_INIT_MPOOL | db.DB_INIT_CDB | db.DB_THREAD
        if not exists(homeDir):
            if create==True:
                mkdir(homeDir) # TODO: implement create method and refactor this to it
                self.create(homeDir)
            else:
                return NO_STORE
        db_env = db.DBEnv()
        db_env.set_cachesize(0, 1024*1024*50) # TODO
        #db_env.set_lg_max(1024*1024)
        db_env.set_flags(envsetflags, 1)
        db_env.open(homeDir, envflags | db.DB_CREATE)
        return db_env
github RDFLib / rdflib / rdflib / backends / SleepyCat.py View on Github external
try:
            if not exists(homeDir):
                mkdir(homeDir)
        except Exception, e:
            print e
        self.env = env = db.DBEnv()
        env.set_cachesize(0, 1024*1024*50)
        #env.set_lg_max(1024*1024)
        env.set_flags(envsetflags, 1)
        env.open(homeDir, envflags | db.DB_CREATE)

        self.__open = 1
        
        dbname = None
        dbtype = db.DB_BTREE
        dbopenflags = db.DB_THREAD
        
        dbmode = 0660
        dbsetflags   = 0

        # create and open the DBs
        self.__contexts = db.DB(env)
        self.__contexts.set_flags(dbsetflags)
        self.__contexts.open("contexts", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
        self.__spo = db.DB(env)
        self.__spo.set_flags(dbsetflags)
        self.__spo.open("spo", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__pos = db.DB(env)
        self.__pos.set_flags(dbsetflags)
        self.__pos.open("pos", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
github RDFLib / rdflib / rdflib / plugins / sleepycat.py View on Github external
def open(self, path, create=True):
        homeDir = path

        if self.__identifier is None:
            self.__identifier = URIRef(pathname2url(abspath(homeDir)))

        db_env = self._init_db_environment(homeDir, create)
        if db_env == NO_STORE:
            return NO_STORE
        self.db_env = db_env
        self.__open = True

        dbname = None
        dbtype = db.DB_BTREE
        # auto-commit ensures that the open-call commits when transactions are enabled
        dbopenflags = db.DB_THREAD 
        if self.transaction_aware == True:
            dbopenflags |= db.DB_AUTO_COMMIT

        dbmode = 0660
        dbsetflags   = 0

        # create and open the DBs
        self.__indicies = [None,] * 3
        self.__indicies_info = [None,] * 3
        for i in xrange(0, 3):
            index_name = to_key_func(i)(("s", "p", "o"), "c")
            index = db.DB(db_env)
            index.set_flags(dbsetflags)
            index.open(index_name, dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
            self.__indicies[i] = index
            self.__indicies_info[i] = (index, to_key_func(i), from_key_func(i))