Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

BDBMetadataPlugin.h

00001 /*
00002    Copyright (C) 2002 the Strongroom project
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    @author Ewald Snel
00010    @author Wouter de Vries
00011 */
00012 
00013 #ifndef __BDBMETADATAPLUGIN_H
00014 #define __BDBMETADATAPLUGIN_H
00015 
00016 #include <pthread.h>
00017 #include <db_cxx.h>
00018 
00019 #include <MetadataPlugin.h>
00020 
00021     
00025 class FastLock
00026 {
00027 public:
00028     FastLock() {}
00029     FastLock( pthread_t thread, int lockCount, int pending )
00030     : thread( thread ), lockCount( lockCount ), pending( pending ) {}
00031 
00032     pthread_t thread;
00033     int lockCount;
00034     int pending;
00035 };
00036 
00037 
00043 class BDBMetadataPlugin : public MetadataPlugin
00044 {
00045 public:
00046     BDBMetadataPlugin( const Config &cfg );
00047     ~BDBMetadataPlugin();
00048 
00053     bool init();
00054 
00055     CoreError create( NumID &docid, const Document &document );
00056     CoreError remove( NumID docid );
00057     CoreError update( NumID docid, const Document &document );
00058     CoreError get( NumID docid, Document &document );
00059     CoreError lock( NumID docid, DocumentLock lock );
00060     CoreError getLocks( map<NumID,DocumentLock> &locks );
00061     CoreError query( NumID first, int maxlen, map<NumID,NumID> &updates );
00062 
00063 private:
00068     void fastLock( NumID docid );
00069 
00075     bool fastUnlock( NumID docid );
00076 
00082     bool fastTestLock( NumID docid );
00083 
00084     bool checkSysKeyOrSetDefault( const char *syskey, NumID defaultValue );
00085     bool increaseSysKey( DbTxn *txn, const char *syskey, NumID &value );
00086     bool getSyskey( DbTxn *mothertxn, const char *syskey, NumID &value );
00087 
00088     bool _initialized;
00089     
00090     DbEnv *dbEnvHandle;
00091     Db *docTableHandle;
00092     Db *updTableHandle;
00093     Db *lockTableHandle;
00094     Db *sysTableHandle;
00095     
00096     pthread_mutex_t mutex;
00097     pthread_cond_t cond;
00098     hash_map<NumID,FastLock,_hash_NumID> fastLocks;
00099 
00100     char* key_highest_docid;
00101     char* key_highest_updid;
00102     char* dbFilename;
00103 };
00104 
00105 #endif

Generated on Wed Feb 18 13:45:55 2004 for strongroom by doxygen1.2.18