make txn optional
svn: r6102
This commit is contained in:
parent
e5375d15fc
commit
de2a6f4d1e
@ -1,3 +1,6 @@
|
|||||||
|
2006-03-08 Don Allingham <don@gramps-project.org>
|
||||||
|
* src/GramspDb/_GrampsBSDDB.py: make txn support optional via UseTXN
|
||||||
|
|
||||||
2006-03-07 Don Allingham <don@gramps-project.org>
|
2006-03-07 Don Allingham <don@gramps-project.org>
|
||||||
* src/AddMedia.py: remove WindowsUtils dependency
|
* src/AddMedia.py: remove WindowsUtils dependency
|
||||||
* src/WindowUtils.py: remove
|
* src/WindowUtils.py: remove
|
||||||
|
@ -120,12 +120,20 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
"""GRAMPS database object. This object is a base class for other
|
"""GRAMPS database object. This object is a base class for other
|
||||||
objects."""
|
objects."""
|
||||||
|
|
||||||
|
UseTXN = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""creates a new GrampsDB"""
|
"""creates a new GrampsDB"""
|
||||||
GrampsDbBase.__init__(self)
|
GrampsDbBase.__init__(self)
|
||||||
self.txn = None
|
self.txn = None
|
||||||
self.secondary_connected = False
|
self.secondary_connected = False
|
||||||
|
|
||||||
|
def open_flags(self):
|
||||||
|
if self.UseTXN:
|
||||||
|
return db.DB_CREATE|db.DB_AUTO_COMMIT
|
||||||
|
else:
|
||||||
|
return db.DB_CREATE
|
||||||
|
|
||||||
def open_table(self,name,dbname,no_txn=False,dbtype=db.DB_HASH):
|
def open_table(self,name,dbname,no_txn=False,dbtype=db.DB_HASH):
|
||||||
dbmap = dbshelve.DBShelf(self.env)
|
dbmap = dbshelve.DBShelf(self.env)
|
||||||
dbmap.db.set_pagesize(16384)
|
dbmap.db.set_pagesize(16384)
|
||||||
@ -134,8 +142,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
elif no_txn:
|
elif no_txn:
|
||||||
dbmap.open(name, dbname, dbtype, db.DB_CREATE, 0666)
|
dbmap.open(name, dbname, dbtype, db.DB_CREATE, 0666)
|
||||||
else:
|
else:
|
||||||
dbmap.open(name, dbname, dbtype,
|
dbmap.open(name, dbname, dbtype, self.open_flags(), 0666)
|
||||||
db.DB_CREATE|db.DB_AUTO_COMMIT, 0666)
|
|
||||||
return dbmap
|
return dbmap
|
||||||
|
|
||||||
def _all_handles(self,table):
|
def _all_handles(self,table):
|
||||||
@ -264,15 +271,21 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.env.set_lk_max_objects(25000)
|
self.env.set_lk_max_objects(25000)
|
||||||
self.env.set_flags(db.DB_LOG_AUTOREMOVE,1) # clean up unused logs
|
self.env.set_flags(db.DB_LOG_AUTOREMOVE,1) # clean up unused logs
|
||||||
# The DB_PRIVATE flag must go if we ever move to multi-user setup
|
# The DB_PRIVATE flag must go if we ever move to multi-user setup
|
||||||
|
|
||||||
|
if self.UseTXN:
|
||||||
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
|
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
|
||||||
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
|
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
|
||||||
db.DB_INIT_LOG|db.DB_INIT_TXN
|
db.DB_INIT_LOG|db.DB_INIT_TXN
|
||||||
|
else:
|
||||||
|
env_flags = db.DB_CREATE|db.DB_PRIVATE|\
|
||||||
|
db.DB_INIT_MPOOL|db.DB_INIT_LOG
|
||||||
|
|
||||||
self.undolog = "%s.undo" % name
|
self.undolog = "%s.undo" % name
|
||||||
env_name = os.path.expanduser(const.bsddbenv_dir)
|
env_name = os.path.expanduser(const.bsddbenv_dir)
|
||||||
if not os.path.isdir(env_name):
|
if not os.path.isdir(env_name):
|
||||||
os.mkdir(env_name)
|
os.mkdir(env_name)
|
||||||
self.env.open(env_name,env_flags)
|
self.env.open(env_name,env_flags)
|
||||||
|
if self.UseTXN:
|
||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
|
|
||||||
callback(25)
|
callback(25)
|
||||||
@ -349,7 +362,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
if self.readonly:
|
if self.readonly:
|
||||||
table_flags = db.DB_RDONLY
|
table_flags = db.DB_RDONLY
|
||||||
else:
|
else:
|
||||||
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
table_flags = self.open_flags()
|
||||||
|
|
||||||
self.surnames = db.DB(self.env)
|
self.surnames = db.DB(self.env)
|
||||||
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
self.surnames.set_flags(db.DB_DUP|db.DB_DUPSORT)
|
||||||
@ -443,7 +456,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
if self.readonly:
|
if self.readonly:
|
||||||
return
|
return
|
||||||
|
|
||||||
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
table_flags = self.open_flags()
|
||||||
|
|
||||||
# remove existing secondary indices
|
# remove existing secondary indices
|
||||||
self.id_trans.close()
|
self.id_trans.close()
|
||||||
@ -784,6 +797,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.source_map.close()
|
self.source_map.close()
|
||||||
self.media_map.close()
|
self.media_map.close()
|
||||||
self.event_map.close()
|
self.event_map.close()
|
||||||
|
if self.UseTXN:
|
||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
self.env.close()
|
self.env.close()
|
||||||
|
|
||||||
@ -922,9 +936,13 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
handle = str(obj.handle)
|
handle = str(obj.handle)
|
||||||
|
|
||||||
if transaction.batch:
|
if transaction.batch:
|
||||||
|
if self.UseTXN:
|
||||||
the_txn = self.env.txn_begin()
|
the_txn = self.env.txn_begin()
|
||||||
|
else:
|
||||||
|
the_txn = None
|
||||||
self._update_reference_map(obj,transaction,txn=the_txn)
|
self._update_reference_map(obj,transaction,txn=the_txn)
|
||||||
data_map.put(handle,obj.serialize(),txn=the_txn)
|
data_map.put(handle,obj.serialize(),txn=the_txn)
|
||||||
|
if the_txn:
|
||||||
the_txn.commit()
|
the_txn.commit()
|
||||||
old_data = None
|
old_data = None
|
||||||
else:
|
else:
|
||||||
@ -977,6 +995,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
|
|
||||||
transaction = BdbTransaction(msg,self.undodb,batch,no_magic)
|
transaction = BdbTransaction(msg,self.undodb,batch,no_magic)
|
||||||
if transaction.batch:
|
if transaction.batch:
|
||||||
|
if self.UseTXN:
|
||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
self.env.set_flags(db.DB_TXN_NOSYNC,1) # async txn
|
self.env.set_flags(db.DB_TXN_NOSYNC,1) # async txn
|
||||||
|
|
||||||
@ -995,7 +1014,10 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
def transaction_commit(self,transaction,msg):
|
def transaction_commit(self,transaction,msg):
|
||||||
|
|
||||||
# Start BSD DB transaction -- DBTxn
|
# Start BSD DB transaction -- DBTxn
|
||||||
|
if self.UseTXN:
|
||||||
self.txn = self.env.txn_begin()
|
self.txn = self.env.txn_begin()
|
||||||
|
else:
|
||||||
|
self.txn = None
|
||||||
|
|
||||||
GrampsDbBase.transaction_commit(self,transaction,msg)
|
GrampsDbBase.transaction_commit(self,transaction,msg)
|
||||||
|
|
||||||
@ -1006,14 +1028,16 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.reference_map.delete(str(key),txn=self.txn)
|
self.reference_map.delete(str(key),txn=self.txn)
|
||||||
|
|
||||||
# Commit BSD DB transaction -- DBTxn
|
# Commit BSD DB transaction -- DBTxn
|
||||||
|
if self.UseTXN:
|
||||||
self.txn.commit()
|
self.txn.commit()
|
||||||
if transaction.batch:
|
if transaction.batch:
|
||||||
|
if self.UseTXN:
|
||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
self.env.set_flags(db.DB_TXN_NOSYNC,0) # sync txn
|
self.env.set_flags(db.DB_TXN_NOSYNC,0) # sync txn
|
||||||
|
|
||||||
if not transaction.no_magic:
|
if not transaction.no_magic:
|
||||||
# create new secondary indices to replace the ones removed
|
# create new secondary indices to replace the ones removed
|
||||||
open_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
open_flags = self.open_flags()
|
||||||
dupe_flags = db.DB_DUP|db.DB_DUPSORT
|
dupe_flags = db.DB_DUP|db.DB_DUPSORT
|
||||||
|
|
||||||
self.surnames = db.DB(self.env)
|
self.surnames = db.DB(self.env)
|
||||||
@ -1034,15 +1058,19 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
print "Undoing it"
|
print "Undoing it"
|
||||||
|
if self.UseTXN:
|
||||||
self.txn = self.env.txn_begin()
|
self.txn = self.env.txn_begin()
|
||||||
GrampsDbBase.undo(self)
|
GrampsDbBase.undo(self)
|
||||||
|
if self.UseTXN:
|
||||||
self.txn.commit()
|
self.txn.commit()
|
||||||
self.txn = None
|
self.txn = None
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
print "Redoing it"
|
print "Redoing it"
|
||||||
|
if self.UseTXN:
|
||||||
self.txn = self.env.txn_begin()
|
self.txn = self.env.txn_begin()
|
||||||
GrampsDbBase.redo(self)
|
GrampsDbBase.redo(self)
|
||||||
|
if self.UseTXN:
|
||||||
self.txn.commit()
|
self.txn.commit()
|
||||||
self.txn = None
|
self.txn = None
|
||||||
|
|
||||||
@ -1151,7 +1179,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
|
|
||||||
# Create one secondary index for reference_map
|
# Create one secondary index for reference_map
|
||||||
# because every commit will require this to exist
|
# because every commit will require this to exist
|
||||||
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
table_flags = self.open_flags()
|
||||||
self.reference_map_primary_map = db.DB(self.env)
|
self.reference_map_primary_map = db.DB(self.env)
|
||||||
self.reference_map_primary_map.set_flags(db.DB_DUP)
|
self.reference_map_primary_map.set_flags(db.DB_DUP)
|
||||||
self.reference_map_primary_map.open(self.full_name,
|
self.reference_map_primary_map.open(self.full_name,
|
||||||
@ -1372,7 +1400,7 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
|
|
||||||
# Turns out that a lof ot events have duplicate gramps IDs
|
# Turns out that a lof ot events have duplicate gramps IDs
|
||||||
# We need to fix this
|
# We need to fix this
|
||||||
table_flags = db.DB_CREATE|db.DB_AUTO_COMMIT
|
table_flags = self.open_flags()
|
||||||
self.eid_trans = db.DB(self.env)
|
self.eid_trans = db.DB(self.env)
|
||||||
self.eid_trans.set_flags(db.DB_DUP)
|
self.eid_trans.set_flags(db.DB_DUP)
|
||||||
self.eid_trans.open(self.full_name, "eidtrans",
|
self.eid_trans.open(self.full_name, "eidtrans",
|
||||||
|
Loading…
Reference in New Issue
Block a user