#include <metadb.h>
It provides a number of lookup functions as well as addition functions publically. Internally, it stores various cross-referenced lists to provide fast lookups. The contents of this class are stored in metadb.xml, and loaded on each runtime.
The purpose of this class is to provide a application-central database through which it is possible to perform cross-referencing between FilesList and this list.
Definition at line 45 of file metadb.h.
Public Member Functions | |
| void | load (std::istream &is) |
| Load the MetaDb contents from input stream, adding all found entries in the stream to the database, merging duplicate entries. | |
| void | save (std::ostream &os) const |
| Write the contents of the database into output stream. | |
| void | push (MetaData *md) |
| Add a metadata object to the database. | |
| void | push (MetaData *md, SharedFile *sf) |
| Add a metadata object to the database, associating it with a SharedFile. | |
| MetaData * | find (const HashBase &h) const |
| Find Metadata by searching with hash. | |
| std::vector< MetaData * > | find (const std::string &filename) const |
| Find MetaData by searching with file name. | |
| MetaData * | find (SharedFile *sf) const |
| Find MetaData by searching with SharedFile. | |
| SharedFile * | findSharedFile (const HashBase &h) const |
| Locate SharedFile by searching with hash. | |
| std::vector< SharedFile * > | findSharedFile (const std::string &filename) const |
| Locate SharedFile by searching with file name. | |
Static Public Member Functions | |
| static MetaDb & | instance () |
| This class is a Singleton. | |
Private Types | |
| typedef std::set< MetaData * >::iterator | LIter |
| List Iterator. | |
| typedef std::set< MetaData * >::const_iterator | CLIter |
| Constant List Iterator. | |
| typedef std::map< SharedFile *, MetaData * >::iterator | SFMDIter |
| SharedFile to MetaData Iterator. | |
| typedef std::map< SharedFile *, MetaData * >::const_iterator | CSFMDIter |
| Constant SharedFile to MetaData Iterator. | |
| typedef std::multimap< std::string, MetaData * >::iterator | FNIter |
| File Name Iterator. | |
| typedef std::multimap< std::string, MetaData * >::const_iterator | CFNIter |
| Constant File Name Iterator. | |
| typedef std::multimap< std::string, SharedFile * >::iterator | NTSFIter |
| Name To SharedFile Iterator. | |
| typedef std::multimap< std::string, SharedFile * >::const_iterator | CNTSFIter |
| Constant Name To SharedFile Iterator. | |
| typedef std::map< CGComm::HashTypeId, std::map< HashWrapper, SharedFile * > >::iterator | HTSFIter |
| Hash To SharedFile Iterator. | |
| typedef std::map< CGComm::HashTypeId, std::map< HashWrapper, SharedFile * > >::const_iterator | CHTSFIter |
| Constant Hash To SharedFile Iterator. | |
| typedef std::map< HashWrapper, SharedFile * >::iterator | HWTSFIter |
| HashWrapper To SharedFile Iterator. | |
| typedef std::map< HashWrapper, SharedFile * >::const_iterator | CHWTSFIter |
| Constant HashWrapper To SharedFile Iterator. | |
| typedef std::map< CGComm::HashTypeId, std::map< HashWrapper, MetaData * > >::iterator | HTMDIter |
| Hash To Meta Data Iterator. | |
| typedef std::map< CGComm::HashTypeId, std::map< HashWrapper, MetaData * > >::const_iterator | CHTMDIter |
| Constant Hash To Meta Data Iterator. | |
| typedef std::map< HashWrapper, MetaData * >::iterator | HWTMDIter |
| Hash Wrapper To Meta Data Iterator. | |
| typedef std::map< HashWrapper, MetaData * >::const_iterator | CHWTMDIter |
| Constant Hash Wrapper To Meta Data Iterator. | |
Private Member Functions | |
| void | onMetaDataEvent (MetaData *md, int evt) |
| Event handler for MetaData events, called from event table. | |
| void | onSharedFileEvent (SharedFile *sf, int evt) |
| Event handler for SharedFile events, called from event table. | |
| void | tryAddFileName (MetaData *source, const std::string &name) |
| Attempt to add entry to m_filenames list. | |
| void | tryAddFileName (SharedFile *sf, const std::string &name) |
| Attempt to add entry to m_nameToId map. | |
| void | tryAddHashSet (MetaData *source, const HashSetBase *hash) |
| Attempt to add entry to m_hashes list. | |
| void | tryAddHashSet (SharedFile *sf, const HashSetBase *hash) |
| Attempt to add entry to m_hashToId map. | |
| void | clear () |
| Clears all lists. | |
Singleton | |
| MetaDb () | |
| MetaDb (MetaDb &) | |
| MetaDb & | operator= (const MetaDb &) |
| ~MetaDb () | |
Private Attributes | |
| std::set< MetaData * > | m_list |
| Primary List ------------ Pure metadata objects. | |
| std::map< SharedFile *, MetaData * > | m_sfToMd |
| SharedFile To MetaData Map ---------------------- SharedFile* keyed map to locate MetaData objects by searching with SharedFile pointer. | |
| std::multimap< std::string, MetaData * > | m_filenames |
| File Name to MetaData Map ------------------------- This map allows finding MetaData knowing file name. | |
| std::multimap< std::string, SharedFile * > | m_nameToSF |
| File Name to SharedFile Map ------------------------ This map allows searching with file name and locating the corresponding SharedFile's. | |
| std::map< CGComm::HashTypeId, std::map< HashWrapper, SharedFile * > > | m_hashToSF |
| Hash To SharedFile Map ---------------------- A dual map which allows us to locate SharedFiles given a hash. | |
| std::map< CGComm::HashTypeId, std::map< HashWrapper, MetaData * > > | m_hashes |
| Hash To Meta Data Map --------------------- Last, but not least, a recursive map which allows us to look up MetaData objects given we know one hash. | |
Friends | |
| std::ostream & | operator<< (std::ostream &o, const MetaDb &md) |
| Output operator for streams. | |
| void | test_metadb () |
Classes | |
| class | HashWrapper |
| HashWrapper structure acts as a container for HashBase pointers in order to allow us to have a map of those keyed by the Hash. More... | |
|
|
Constant File Name Iterator.
|
|
|
Constant Hash To Meta Data Iterator.
|
|
|
Constant Hash To SharedFile Iterator.
|
|
|
Constant Hash Wrapper To Meta Data Iterator.
|
|
|
Constant HashWrapper To SharedFile Iterator.
|
|
|
Constant List Iterator.
|
|
|
Constant Name To SharedFile Iterator.
|
|
|
Constant SharedFile to MetaData Iterator.
|
|
|
File Name Iterator.
|
|
|
Hash To Meta Data Iterator.
|
|
|
Hash To SharedFile Iterator.
|
|
|
Hash Wrapper To Meta Data Iterator.
|
|
|
HashWrapper To SharedFile Iterator.
|
|
|
List Iterator.
|
|
|
Name To SharedFile Iterator.
|
|
|
SharedFile to MetaData Iterator.
|
|
|
Definition at line 27 of file metadb.cpp. |
|
|
|
|
|
Definition at line 35 of file metadb.cpp. References m_list. |
|
|
Clears all lists. This is used for debugging purposes in metadata regress-test. Definition at line 439 of file metadb.cpp. References m_filenames, m_hashes, m_hashToSF, m_list, m_nameToSF, and m_sfToMd. |
|
|
Find MetaData by searching with SharedFile.
Definition at line 329 of file metadb.cpp. References m_sfToMd. |
|
|
Find MetaData by searching with file name. Note that this function may return any number of MetaData objects in case the filename is ambigious.
Definition at line 313 of file metadb.cpp. References logTrace(), m_filenames, and METADB. |
Here is the call graph for this function:

|
|
Find Metadata by searching with hash.
Definition at line 289 of file metadb.cpp. References logTrace(), m_hashes, and METADB. Referenced by SharedFile::findMetaData(), and tryAddHashSet(). |
Here is the call graph for this function:

|
|
Locate SharedFile by searching with file name. Note that this function may return any number of SharedFiles if the file name is ambigious.
Definition at line 352 of file metadb.cpp. References m_nameToSF. |
|
|
Locate SharedFile by searching with hash.
Definition at line 338 of file metadb.cpp. References m_hashToSF. Referenced by SharedFile::isDuplicate(). |
|
|
This class is a Singleton. The only instance of this class may be retrieved through this function. Note that the very first call to this function also initializes this class.
Definition at line 41 of file metadb.cpp. Referenced by HydraNode::cleanup(), FilesList::createDownload(), SharedFile::findMetaData(), HydraNode::initFiles(), SharedFile::isDuplicate(), FilesList::loadTempFile(), HydraNode::onEvent(), SharedFile::onHashEvent(), and SharedFile::verify(). |
|
|
Load the MetaDb contents from input stream, adding all found entries in the stream to the database, merging duplicate entries.
Definition at line 51 of file metadb.cpp. References CHECK_THROW, logError(), logMsg(), logTrace(), OP_MDB_VERSION, push(), and TRACE_MD. Referenced by HydraNode::initFiles(). |
Here is the call graph for this function:

|
||||||||||||
|
Event handler for MetaData events, called from event table.
Definition at line 369 of file metadb.cpp. References CHECK_THROW, MD_ADDED_FILENAME, MD_ADDED_HASHSET, tryAddFileName(), and tryAddHashSet(). Referenced by push(). |
Here is the call graph for this function:

|
||||||||||||
|
Event handler for SharedFile events, called from event table.
Definition at line 387 of file metadb.cpp. References HashSetBase::getFileHash(), HashSetBase::getFileHashTypeId(), MetaData::getFileName(), MetaData::getHashSet(), logWarning(), m_hashToSF, m_nameToSF, m_sfToMd, and SF_DESTROY. Referenced by push(), tryAddFileName(), and tryAddHashSet(). |
Here is the call graph for this function:

|
|
|
|
||||||||||||
|
Add a metadata object to the database, associating it with a SharedFile.
Definition at line 263 of file metadb.cpp. References CHECK_THROW, m_sfToMd, onSharedFileEvent(), push(), tryAddFileName(), and tryAddHashSet(). |
Here is the call graph for this function:

|
|
Add a metadata object to the database.
Definition at line 240 of file metadb.cpp. References CHECK_THROW, m_list, onMetaDataEvent(), tryAddFileName(), and tryAddHashSet(). Referenced by FilesList::createDownload(), load(), FilesList::loadTempFile(), SharedFile::onHashEvent(), push(), and SharedFile::verify(). |
Here is the call graph for this function:

|
|
Write the contents of the database into output stream.
Definition at line 96 of file metadb.cpp. |
|
||||||||||||
|
Attempt to add entry to m_nameToId map.
Definition at line 146 of file metadb.cpp. References CHECK_THROW, logTrace(), m_nameToSF, METADB, and onSharedFileEvent(). |
Here is the call graph for this function:

|
||||||||||||
|
Attempt to add entry to m_filenames list.
Definition at line 119 of file metadb.cpp. References CHECK_THROW, logTrace(), m_filenames, and METADB. Referenced by onMetaDataEvent(), and push(). |
Here is the call graph for this function:

|
||||||||||||
|
Attempt to add entry to m_hashToId map.
Definition at line 206 of file metadb.cpp. References CHECK_THROW, HashBase::getTypeId(), m_hashToSF, and onSharedFileEvent(). |
Here is the call graph for this function:

|
||||||||||||
|
Attempt to add entry to m_hashes list.
Definition at line 172 of file metadb.cpp. References CHECK_THROW, find(), HashBase::getTypeId(), logTrace(), m_hashes, and METADB. Referenced by onMetaDataEvent(), and push(). |
Here is the call graph for this function:

|
||||||||||||
|
Output operator for streams.
Definition at line 101 of file metadb.cpp. |
|
|
|
|
|
File Name to MetaData Map ------------------------- This map allows finding MetaData knowing file name. The file name key here is only that - file name. No paths may be included in the name. Multiple objects may have the same file name - for this reason, this is a multi-map. Definition at line 213 of file metadb.h. Referenced by clear(), find(), and tryAddFileName(). |
|
|
Hash To Meta Data Map --------------------- Last, but not least, a recursive map which allows us to look up MetaData objects given we know one hash. The outer map is keyed on hash types, so there are generally only 5-6 entries in the outer map. For each of the outer map, there is an inner map, which is keyed on the actual Hash, and returns MetaData pointer. Note that we use HashWrapper wrapper class around HashBase pointer, doing virtual function calls on lookups. While it is known that virtual function calls come with some performance tradeoff, I really don't see other way of doing it. Also keep in mind that when HashSet object (contained in MetaData object) is destroyed, it would invalidate the HashWrapper pointer - make sure to not have any HashWrappers containing the HashBase objects around anymore when deleting MetaData. Definition at line 278 of file metadb.h. Referenced by clear(), find(), and tryAddHashSet(). |
|
|
Hash To SharedFile Map ---------------------- A dual map which allows us to locate SharedFiles given a hash. The outer map is keyed on HashTypeId, so there are generally only 5-6 entries there. For each of the outer maps, there's an inner map, containing hashes of the given type. Lookups in the inner map return the SharedFile of the searched entry. Definition at line 245 of file metadb.h. Referenced by clear(), findSharedFile(), onSharedFileEvent(), and tryAddHashSet(). |
|
|
Primary List ------------ Pure metadata objects. We really cannot rely on any data existing in the contained MetaData pointer, so we can't turn this into some kind of map or anything. However, other lists contain iterators to this list for faster access - iterate directly on this list only as last resort. This list is also used to save in metadata.xml file, and is also ready for publishing to outside world. |
|
|
File Name to SharedFile Map ------------------------ This map allows searching with file name and locating the corresponding SharedFile's. Note that this is a multimap - same file name may point to several SharedFiles. Definition at line 226 of file metadb.h. Referenced by clear(), findSharedFile(), onSharedFileEvent(), and tryAddFileName(). |
|
|
SharedFile To MetaData Map ---------------------- SharedFile* keyed map to locate MetaData objects by searching with SharedFile pointer. This list is populated by FilesList (and contained) classes, and generally contains only part of the entire m_list contents - only entries which are also in FilesList are listed here. Definition at line 199 of file metadb.h. Referenced by clear(), find(), onSharedFileEvent(), and push(). |