[pybsddb] BDB Indexing and Joined Cursor issue
Sury Soni
ssoni at nextdigital.com
Tue Oct 21 06:41:56 CEST 2008
Since, I am using indexes (secondary databases), I need to make sure, if
there are records in each (secondary database) cursor. So as per your
suggestion, I started with using count(), later changed to
get_current_size().
Following the function, I am using to find join()'ed cursor of all
secondary database, based on filter queries for each secondary database.
def search(self, pattern):
queries = splitKey(pattern)
print "Queries: ", queries
print "Secondary database count: ", len(self.dbs)
try:
if len(self.dbs)>0:
curs = []
i=0
# Iterate over all the secondary index databases to get
individual
# cursors and join to get final filter from primary
database.
# self.dbs is array of all secondary database handles
for dbsi in self.dbs:
try:
if i>(len(queries)-1):
break
cur = dbsi.cursor()
if queries[i].find("x")<0:
cur.pget(key=queries[i], flags=DB_SET_RANGE)
try:
if cur.get_current_size()>0:
## previously ## if cur.count()>0:
curs.append(cur)
else:
cur.close()
except Exception, e:
print "Exception in get current size: ",
e
traceback.print_exc(file=sys.stdout)
cur.close()
i+=1
except Exception, e:
print "Exception in search, case 0: ", e
traceback.print_exc(file=sys.stdout)
raise NextDigital.DBEOFException()
# checking, if enough secondary database handle
available to be joined!
if len(curs)<=0:
raise NextDigital.DBEOFException()
try:
# this is where, I am creating my joined cursor, on
which I only invoke, get(0) operation.
# self.db is primary database handle
joinedCursor = self.db.join(curs)
if not joinedCursor:
raise NextDigital.DBEOFException()
return (curs, joinedCursor)
except Exception, e:
raise NextDigital.DBEOFException()
else:
cur = self.db.cursor()
cur.set_range(pattern)
return ([], cur)
except Exception, e:
print "Exception in search, case last: ", e
#traceback.print_exc(file=sys.stdout)
raise NextDigital.DBEOFException()
Ideally, pget shall set the pointer to some found record on secondary
cursor. But in my particular query, no records are found, that's where I
need to handle this error before calling join().
But, if we are getting stuck to the same vicious circle of finding
non-empty cursor, how could I determine, whether to join() or not
join()? As, join() is getting deadlock or core dump if we try to join
empty cursors.
Please suggest further.
Regards,
Surya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.jcea.es/pipermail/pybsddb/attachments/20081021/806fcb87/attachment.htm>
More information about the pybsddb
mailing list