[pybsddb] BDB Indexing and Joined Cursor issue

phu kungphu at gmail.com
Tue Oct 21 07:29:58 CEST 2008


If your question is how to avoid joining empty cursors, just create an empty
list and append your non-zero-count cursors to it; if you end up with at
least one cursor in your list, you can run your join (joining one cursor
should not cause errors, but you can either do that or just use the single
cursor, whichever you prefer).  If you end up with an empty list, then you
know you have no cursors which return values, and should not attempt to
either join or get from your cursors.  pget will not be an option once you
have joined, as joined cursors only support get and close.

On Mon, Oct 20, 2008 at 11:41 PM, Sury Soni <ssoni at nextdigital.com> wrote:

>  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
>
> _______________________________________________
> pybsddb mailing list
> pybsddb at argo.es
> http://mailman.argo.es/listinfo/pybsddb
> http://www.argo.es/~jcea/programacion/pybsddb.htm<http://www.argo.es/%7Ejcea/programacion/pybsddb.htm>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.jcea.es/pipermail/pybsddb/attachments/20081021/97b1f1e9/attachment.htm>


More information about the pybsddb mailing list