def __init__(self, env, primary_db, name, unique=False): BaseIndex.__init__(self, name, unique) self.db = db.DB(env) self.db.set_flags(db.DB_DUPSORT) self.db.open( 'porcupine.idx', name, dbtype = db.DB_BTREE, mode = self.db_mode, flags = self.db_flags ) primary_db.associate(self.db, self.callback, flags=db.DB_CREATE)
def __init__(self, env, primary_db, name, unique, immutable, db_flags): BaseIndex.__init__(self, name, unique) while True: try: self.db = db.DB(env) self.db.set_pagesize(1024) if not unique: self.db.set_flags(db.DB_DUPSORT) self.db.open('porcupine.idx', name, dbtype=db.DB_BTREE, mode=0o660, flags=db_flags) flags = db.DB_CREATE if immutable: if hasattr(db, 'DB_IMMUTABLE_KEY'): flags |= db.DB_IMMUTABLE_KEY #else: # flags |= 0x00000002 primary_db.associate(self.db, self.callback, flags=flags) except db.DBLockDeadlockError: self.db.close() continue except db.DBError as e: if e.args[0] == _err_unsupported_index_type: # remove index self.close() _db = db.DB(env) _db.remove('porcupine.idx', dbname=name) raise exceptions.ConfigurationError( 'Unsupported data type for index "%s".' % name) else: raise break