Some bsddb changes

* allow to use bsddb3 as database via a config setting
  * set async write to disk to improve speed, eg import * 40


svn: r16446
This commit is contained in:
Benny Malengier 2011-01-23 21:25:51 +00:00
parent 551b70a8f3
commit b3beba53d8
18 changed files with 112 additions and 26 deletions

View File

@ -30,7 +30,6 @@
from gen.ggettext import gettext as _
import os
import sys
import bsddb
##import logging
##_LOG = logging.getLogger(".GrampsAboutDialog")
@ -54,6 +53,12 @@ import gtk
#-------------------------------------------------------------------------
import const
from GrampsDisplay import url as display_url
import config
if config.get('preferences.use-bsddb3'):
import bsddb3 as bsddb
else:
import bsddb
#-------------------------------------------------------------------------
#

View File

@ -5,8 +5,13 @@ import gtk
import pygtk
import gobject
import cairo
import sys, os,bsddb
import sys, os
import config
if config.get('preferences.use-bsddb3'):
import bsddb3 as bsddb
else:
import bsddb
class ErrorReportAssistant(object):

View File

@ -108,7 +108,10 @@ class CLIDbManager(object):
Returns (people_count, version_number) of current DB.
Returns ("Unknown", "Unknown") if invalid DB or other error.
"""
from bsddb import dbshelve, db
if config.get('preferences.use-bsddb3'):
from bsddb3 import dbshelve, db
else:
from bsddb import dbshelve, db
from gen.db import META, PERSON_TBL
env = db.DBEnv()
flags = db.DB_CREATE | db.DB_PRIVATE |\

View File

@ -288,6 +288,7 @@ register('preferences.sprefix', 'S%04d')
register('preferences.use-last-view', True)
register('preferences.last-view', '')
register('preferences.last-views', [])
register('preferences.use-bsddb3', False)
register('researcher.researcher-addr', '')
register('researcher.researcher-locality', '')

View File

@ -188,7 +188,11 @@ class BSDDBTxn(object):
# test code
if __name__ == "__main__":
print "1"
from bsddb import db, dbshelve
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db, dbshelve
else:
from bsddb import db, dbshelve
print "2"
x = db.DBEnv()
print "3"

View File

@ -24,7 +24,12 @@
#
#-------------------------------------------------------------------------
from cPickle import dumps, loads
from bsddb import db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db
else:
from bsddb import db
#-------------------------------------------------------------------------
#

View File

@ -63,7 +63,11 @@ DBLOCKS = 25000 # Maximum number of locks supported
DBOBJECTS = 25000 # Maximum number of simultaneously locked objects
DBUNDO = 1000 # Maximum size of undo buffer
from bsddb.db import DB_CREATE, DB_AUTO_COMMIT, DB_DUP, DB_DUPSORT, DB_RDONLY
import config
if config.get('preferences.use-bsddb3'):
from bsddb3.db import DB_CREATE, DB_AUTO_COMMIT, DB_DUP, DB_DUPSORT, DB_RDONLY
else:
from bsddb.db import DB_CREATE, DB_AUTO_COMMIT, DB_DUP, DB_DUPSORT, DB_RDONLY
DBFLAGS_O = DB_CREATE | DB_AUTO_COMMIT # Default flags for database open
DBFLAGS_R = DB_RDONLY # Flags to open a database read-only
DBFLAGS_D = DB_DUP | DB_DUPSORT # Default flags for duplicate keys

View File

@ -36,7 +36,12 @@ import random
import locale
import os
from sys import maxint
from bsddb import db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db
else:
from bsddb import db
from gen.ggettext import gettext as _
import logging

View File

@ -32,8 +32,14 @@ database.
#-------------------------------------------------------------------------
from __future__ import with_statement
import cPickle as pickle
from bsddb import dbshelve, db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import dbshelve, db
else:
from bsddb import dbshelve, db
import logging
from collections import defaultdict
#-------------------------------------------------------------------------

View File

@ -33,10 +33,15 @@ undos and redos.
from __future__ import with_statement
import time, os
import cPickle as pickle
from bsddb import db
from gen.ggettext import gettext as _
from collections import deque
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db
else:
from bsddb import db
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# Gramps modules

View File

@ -29,7 +29,11 @@ import time
"""
methods to upgrade a database from version 13 to current version
"""
from bsddb import db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db
else:
from bsddb import db
from gen.db import BSDDBTxn
from gen.lib.nameorigintype import NameOriginType
from gen.db.write import _mkname, SURNAMES

View File

@ -38,12 +38,16 @@ import time
import locale
import bisect
from functools import wraps
from gen.ggettext import gettext as _
from bsddb import dbshelve, db
import logging
from sys import maxint
from gen.ggettext import gettext as _
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import dbshelve, db
else:
from bsddb import dbshelve, db
#-------------------------------------------------------------------------
#
# Gramps modules
@ -413,6 +417,10 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
except:
pass
raise DbEnvironmentError(msg)
# Set not to flush to disk synchronous
self.env.set_flags(db.DB_TXN_NOSYNC, 1)
self.env.set_flags(db.DB_TXN_WRITE_NOSYNC, 1)
self.env.txn_checkpoint()
if callback:
@ -1636,8 +1644,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
self.undodb.clear()
self.env.txn_checkpoint()
if db.version() < (4, 7):
self.env.set_flags(db.DB_TXN_NOSYNC, 1) # async txn
#if db.version() < (4, 7):
# self.env.set_flags(db.DB_TXN_NOSYNC, 1) # async txn
if self.secondary_connected and not no_magic:
# Disconnect unneeded secondary indices
@ -1676,8 +1684,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
"""
if transaction.batch:
self.env.txn_checkpoint()
if db.version() < (4, 7):
self.env.set_flags(db.DB_TXN_NOSYNC, 0) # sync txn
#if db.version() < (4, 7):
# self.env.set_flags(db.DB_TXN_NOSYNC, 0) # sync txn
if not transaction.no_magic:
# create new secondary indices to replace the ones removed

View File

@ -21,7 +21,11 @@
# $Id$
import bsddb
import config
if config.get('preferences.use-bsddb3'):
import bsddb3 as bsddb
else:
import bsddb
import types
from gen.ggettext import gettext as _

View File

@ -191,11 +191,18 @@ def show_settings():
except ImportError:
cairover_str = 'not found'
import config
usebsddb3 = config.get('preferences.use-bsddb3')
try:
import bsddb
if usebsddb3:
import bsddb3 as bsddb
else:
import bsddb
bsddb_str = bsddb.__version__
bsddb_db_str = str(bsddb.db.version())
except:
bsddb_str = 'not found'
bsddb_db_str = 'not found'
try:
import const
@ -243,6 +250,7 @@ def show_settings():
print ' pygtk : %s' % pygtkver_str
print ' gobject : %s' % gobjectver_str
print ' bsddb : %s' % bsddb_str
print ' bsddb.db : %s' % bsddb_db_str
print ' cairo : %s' % cairover_str
print ' o.s. : %s' % operating_system
if kernel:
@ -302,9 +310,13 @@ def run():
argpars = ArgParser(sys.argv)
if argpars.need_gui():
#A GUI is needed, set it up
from gui.grampsgui import startgtkloop
startgtkloop(error, argpars)
#A GUI is needed, set it up
if "--qml" in sys.argv:
from guiQML.grampsqml import startqml
startqml(error, argpars)
else:
from gui.grampsgui import startgtkloop
startgtkloop(error, argpars)
else:
#CLI use of GRAMPS
argpars.print_help()

View File

@ -36,7 +36,12 @@ import tempfile
from gen.ggettext import gettext as _
import cPickle as pickle
import time
from bsddb import dbshelve, db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import dbshelve, db
else:
from bsddb import dbshelve, db
import logging
LOG = logging.getLogger(".Db")

View File

@ -86,6 +86,8 @@ EVENT_PERSON_STR = _("%(event_name)s of %(person)s")
#
#-------------------------------------------------------------------------
def importData(database, filename, callback=None, cl=0):
## return Utils.profile(importDataPro, database, filename, callback, cl)
##def importDataPro(database, filename, callback=None, cl=0):
if DbMixin not in database.__class__.__bases__:
database.__class__.__bases__ = (DbMixin,) + \

View File

@ -36,7 +36,11 @@ import random
import locale
import os
from sys import maxint
from bsddb import db
import config
if config.get('preferences.use-bsddb3'):
from bsddb3 import db
else:
from bsddb import db
from gen.ggettext import gettext as _
import logging

View File

@ -32,7 +32,11 @@ Show uncollected objects in a window.
#
#------------------------------------------------------------------------
from gen.ggettext import gettext as _
from bsddb.db import DBError
import config
if config.get('preferences.use-bsddb3'):
from bsddb3.db import DBError
else:
from bsddb.db import DBError
#------------------------------------------------------------------------
#