diff options
author | Chris Wilson <chris+github@qwirx.com> | 2010-02-22 22:10:04 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2010-02-22 22:10:04 +0000 |
commit | 8ac0bb684f4db95b0ce6699c995b887dda3821ed (patch) | |
tree | d6778b87271e1edd07d5255a8a8aba3dd5db586c /bin | |
parent | e4cdd81a9c972868985eb0f545a6ecff433238e4 (diff) |
Remove all references to bdb databases, use QDBM instead.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/bbackupd/BackupClientInodeToIDMap.cpp | 244 | ||||
-rw-r--r-- | bin/bbackupd/BackupClientInodeToIDMap.h | 26 | ||||
-rw-r--r-- | bin/bbackupd/BackupDaemon.cpp | 40 |
3 files changed, 84 insertions, 226 deletions
diff --git a/bin/bbackupd/BackupClientInodeToIDMap.cpp b/bin/bbackupd/BackupClientInodeToIDMap.cpp index b9f56c5a..74d5f3cd 100644 --- a/bin/bbackupd/BackupClientInodeToIDMap.cpp +++ b/bin/bbackupd/BackupClientInodeToIDMap.cpp @@ -9,32 +9,53 @@ #include "Box.h" -#ifdef HAVE_DB - // Include db headers and other OS files if they're needed for the disc implementation - #include <sys/types.h> - #include <fcntl.h> - #include <limits.h> - #include <db.h> - #include <sys/stat.h> -#endif +#include <stdlib.h> +#include <depot.h> #define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION #include "BackupClientInodeToIDMap.h" +#undef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION #include "BackupStoreException.h" - #include "MemLeakFindOn.h" -// What type of Berkeley DB shall we use? -#define TABLE_DATABASE_TYPE DB_HASH - typedef struct { int64_t mObjectID; int64_t mInDirectory; } IDBRecord; +#define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode) + +#define BOX_LOG_DBM_ERROR(stuff) \ + BOX_ERROR(BOX_DBM_MESSAGE(stuff)) + +#define THROW_DBM_ERROR(message, filename, exception, subtype) \ + BOX_LOG_DBM_ERROR(message << ": " << filename); \ + THROW_EXCEPTION_MESSAGE(exception, subtype, \ + BOX_DBM_MESSAGE(message << ": " << filename)); + +#define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \ + if(!(operation)) \ + { \ + THROW_DBM_ERROR(message, filename, exception, subtype); \ + } + +#define ASSERT_DBM_OPEN() \ + if(mpDepot == 0) \ + { \ + THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ + "Inode database not open"); \ + } + +#define ASSERT_DBM_CLOSED() \ + if(mpDepot != 0) \ + { \ + THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ + "Inode database already open: " << mFilename); \ + } + // -------------------------------------------------------------------------- // // Function @@ -44,11 +65,9 @@ typedef struct // // -------------------------------------------------------------------------- BackupClientInodeToIDMap::BackupClientInodeToIDMap() -#ifndef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION : mReadOnly(true), mEmpty(false), - dbp(0) -#endif + mpDepot(0) { } @@ -62,19 +81,12 @@ BackupClientInodeToIDMap::BackupClientInodeToIDMap() // -------------------------------------------------------------------------- BackupClientInodeToIDMap::~BackupClientInodeToIDMap() { -#ifndef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - if(dbp != 0) + if(mpDepot != 0) { -#if BDB_VERSION_MAJOR >= 3 - dbp->close(0); -#else - dbp->close(dbp); -#endif + Close(); } -#endif } - // -------------------------------------------------------------------------- // // Function @@ -83,56 +95,53 @@ BackupClientInodeToIDMap::~BackupClientInodeToIDMap() // Created: 20/11/03 // // -------------------------------------------------------------------------- -void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly, bool CreateNew) +void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly, + bool CreateNew) { -#ifndef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION + mFilename = Filename; + // Correct arguments? ASSERT(!(CreateNew && ReadOnly)); // Correct usage? - ASSERT(dbp == 0); + ASSERT_DBM_CLOSED(); ASSERT(!mEmpty); // Open the database file -#if BDB_VERSION_MAJOR >= 3 - dbp = new Db(0,0); - dbp->set_pagesize(1024); /* Page size: 1K. */ - dbp->set_cachesize(0, 32 * 1024, 0); - dbp->open(NULL, Filename, NULL, DB_HASH, DB_CREATE, 0664); -#else - dbp = dbopen(Filename, (CreateNew?O_CREAT:0) | (ReadOnly?O_RDONLY:O_RDWR), S_IRUSR | S_IWUSR | S_IRGRP, TABLE_DATABASE_TYPE, NULL); -#endif - if(dbp == NULL) + int mode = ReadOnly ? DP_OREADER : DP_OWRITER; + if(CreateNew) { - THROW_EXCEPTION(BackupStoreException, BerkelyDBFailure); + mode |= DP_OCREAT; } + mpDepot = dpopen(Filename, mode, 0); + + ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename, + BackupStoreException, BerkelyDBFailure); + // Read only flag mReadOnly = ReadOnly; -#endif } // -------------------------------------------------------------------------- // // Function // Name: BackupClientInodeToIDMap::OpenEmpty() -// Purpose: 'Open' this map. Not associated with a disc file. Useful for when a map -// is required, but is against an empty file on disc which shouldn't be created. -// Implies read only. +// Purpose: 'Open' this map. Not associated with a disc file. +// Useful for when a map is required, but is against +// an empty file on disc which shouldn't be created. +// Implies read only. // Created: 20/11/03 // // -------------------------------------------------------------------------- void BackupClientInodeToIDMap::OpenEmpty() { -#ifndef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - ASSERT(dbp == 0); + ASSERT_DBM_CLOSED(); + ASSERT(mpDepot == 0); mEmpty = true; mReadOnly = true; -#endif } - - // -------------------------------------------------------------------------- // // Function @@ -143,75 +152,46 @@ void BackupClientInodeToIDMap::OpenEmpty() // -------------------------------------------------------------------------- void BackupClientInodeToIDMap::Close() { -#ifndef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - if(dbp != 0) - { -#if BDB_VERSION_MAJOR >= 3 - if(dbp->close(0) != 0) -#else - if(dbp->close(dbp) != 0) -#endif - { - THROW_EXCEPTION(BackupStoreException, BerkelyDBFailure); - } - dbp = 0; - } -#endif + ASSERT_DBM_OPEN(); + ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", + mFilename, BackupStoreException, BerkelyDBFailure); + mpDepot = 0; } - // -------------------------------------------------------------------------- // // Function -// Name: BackupClientInodeToIDMap::AddToMap(InodeRefType, int64_t, int64_t) -// Purpose: Adds an entry to the map. Overwrites any existing entry. +// Name: BackupClientInodeToIDMap::AddToMap(InodeRefType, +// int64_t, int64_t) +// Purpose: Adds an entry to the map. Overwrites any existing +// entry. // Created: 11/11/03 // // -------------------------------------------------------------------------- -void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID, int64_t InDirectory) +void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID, + int64_t InDirectory) { -#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - mMap[InodeRef] = std::pair<int64_t, int64_t>(ObjectID, InDirectory); -#else if(mReadOnly) { THROW_EXCEPTION(BackupStoreException, InodeMapIsReadOnly); } - if(dbp == 0) + if(mpDepot == 0) { THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); } + ASSERT_DBM_OPEN(); + // Setup structures IDBRecord rec; rec.mObjectID = ObjectID; rec.mInDirectory = InDirectory; -#if BDB_VERSION_MAJOR >= 3 - Dbt key(&InodeRef, sizeof(InodeRef)); - Dbt data(&rec, sizeof(rec)); - - if (dbp->put(0, &key, &data, 0) != 0) { - THROW_EXCEPTION(BackupStoreException, BerkelyDBFailure); - } -#else - - DBT key; - key.data = &InodeRef; - key.size = sizeof(InodeRef); - - DBT data; - data.data = &rec; - data.size = sizeof(rec); - - // Add to map (or replace existing entry) - if(dbp->put(dbp, &key, &data, 0) != 0) - { - THROW_EXCEPTION(BackupStoreException, BerkelyDBFailure); - } -#endif -#endif + ASSERT_DBM_OK(dpput(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), + (const char *)&rec, sizeof(rec), DP_DOVER), + "Failed to add record to inode database", mFilename, + BackupStoreException, BerkelyDBFailure); } // -------------------------------------------------------------------------- @@ -228,100 +208,32 @@ void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID, bool BackupClientInodeToIDMap::Lookup(InodeRefType InodeRef, int64_t &rObjectIDOut, int64_t &rInDirectoryOut) const { -#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - std::map<InodeRefType, std::pair<int64_t, int64_t> >::const_iterator i(mMap.find(InodeRef)); - - // Found? - if(i == mMap.end()) - { - return false; - } - - // Yes. Return the details - rObjectIDOut = i->second.first; - rInDirectoryOut = i->second.second; - return true; -#else if(mEmpty) { // Map is empty return false; } - if(dbp == 0) + if(mpDepot == 0) { THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); } - -#if BDB_VERSION_MAJOR >= 3 - Dbt key(&InodeRef, sizeof(InodeRef)); - Dbt data(0, 0); - switch(dbp->get(NULL, &key, &data, 0)) -#else - DBT key; - key.data = &InodeRef; - key.size = sizeof(InodeRef); - DBT data; - data.data = 0; - data.size = 0; + ASSERT_DBM_OPEN(); - switch(dbp->get(dbp, &key, &data, 0)) -#endif - - { - case 1: // key not in file - return false; - - case -1: // error - default: // not specified in docs - THROW_EXCEPTION(BackupStoreException, BerkelyDBFailure); - return false; + IDBRecord rec; - case 0: // success, found it - break; - } - - // Check for sensible return -#if BDB_VERSION_MAJOR >= 3 - if(key.get_data() == 0 || data.get_size() != sizeof(IDBRecord)) + if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), + 0, sizeof(IDBRecord), (char *)&rec) == -1) { - // Assert in debug version - ASSERT(key.get_data() == 0 || data.get_size() != sizeof(IDBRecord)); - - // Invalid entries mean it wasn't found + // key not in file return false; } - - // Data alignment isn't guaranteed to be on a suitable boundary - IDBRecord rec; - - ::memcpy(&rec, data.get_data(), sizeof(rec)); -#else - if(key.data == 0 || data.size != sizeof(IDBRecord)) - { - // Assert in debug version - ASSERT(key.data == 0 || data.size != sizeof(IDBRecord)); - // Invalid entries mean it wasn't found - return false; - } - - // Data alignment isn't guaranteed to be on a suitable boundary - IDBRecord rec; - - ::memcpy(&rec, data.data, sizeof(rec)); -#endif - // Return data rObjectIDOut = rec.mObjectID; rInDirectoryOut = rec.mInDirectory; - // Don't have to worry about freeing the returned data - // Found return true; -#endif } - - diff --git a/bin/bbackupd/BackupClientInodeToIDMap.h b/bin/bbackupd/BackupClientInodeToIDMap.h index 1dfef702..fbe45114 100644 --- a/bin/bbackupd/BackupClientInodeToIDMap.h +++ b/bin/bbackupd/BackupClientInodeToIDMap.h @@ -8,25 +8,16 @@ // -------------------------------------------------------------------------- #ifndef BACKUPCLIENTINODETOIDMAP_H -#define BACKUPCLIENTINODETOIDMAP__H +#define BACKUPCLIENTINODETOIDMAP_H #include <sys/types.h> #include <map> #include <utility> -// Use in memory implementation if there isn't access to the Berkely DB on this platform -#ifndef HAVE_DB - #define BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION -#endif - // avoid having to include the DB files when not necessary #ifndef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION -#ifdef BERKELY_V4 - class Db; -#else - class DB; -#endif + class DEPOT; #endif // -------------------------------------------------------------------------- @@ -55,19 +46,12 @@ public: void Close(); private: -#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - std::map<InodeRefType, std::pair<int64_t, int64_t> > mMap; -#else bool mReadOnly; bool mEmpty; -#ifdef BERKELY_V4 - Db *dbp; // c++ style implimentation -#else - DB *dbp; // C style interface, use notation from documentation -#endif // BERKELY_V4 -#endif // BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION + std::string mFilename; + DEPOT *mpDepot; }; -#endif // BACKUPCLIENTINODETOIDMAP__H +#endif // BACKUPCLIENTINODETOIDMAP_H diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp index 5134d234..7b53f228 100644 --- a/bin/bbackupd/BackupDaemon.cpp +++ b/bin/bbackupd/BackupDaemon.cpp @@ -1784,31 +1784,11 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con // -------------------------------------------------------------------------- void BackupDaemon::SetupIDMapsForSync() { - // Need to do different things depending on whether it's an - // in memory implementation, or whether it's all stored on disc. - -#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - - // Make sure we have some blank, empty ID maps - DeleteIDMapVector(mNewIDMaps); - FillIDMapVector(mNewIDMaps, true /* new maps */); - - // Then make sure that the current maps have objects, - // even if they are empty (for the very first run) - if(mCurrentIDMaps.empty()) - { - FillIDMapVector(mCurrentIDMaps, false /* current maps */); - } - -#else - // Make sure we have some blank, empty ID maps DeleteIDMapVector(mNewIDMaps); FillIDMapVector(mNewIDMaps, true /* new maps */); DeleteIDMapVector(mCurrentIDMaps); FillIDMapVector(mCurrentIDMaps, false /* new maps */); - -#endif } @@ -1935,21 +1915,6 @@ void BackupDaemon::MakeMapBaseName(unsigned int MountNumber, std::string &rNameO // -------------------------------------------------------------------------- void BackupDaemon::CommitIDMapsAfterSync() { - // Need to do different things depending on whether it's an in memory implementation, - // or whether it's all stored on disc. - -#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION - // Remove the current ID maps - DeleteIDMapVector(mCurrentIDMaps); - - // Copy the (pointers to) "new" maps over to be the new "current" maps - mCurrentIDMaps = mNewIDMaps; - - // Clear the new ID maps vector (not delete them!) - mNewIDMaps.clear(); - -#else - // Get rid of the maps in memory (leaving them on disc of course) DeleteIDMapVector(mCurrentIDMaps); DeleteIDMapVector(mNewIDMaps); @@ -1973,8 +1938,6 @@ void BackupDaemon::CommitIDMapsAfterSync() THROW_EXCEPTION(CommonException, OSFileError) } } - -#endif } @@ -1996,8 +1959,7 @@ void BackupDaemon::DeleteIDMapVector(std::vector<BackupClientInodeToIDMap *> &rV rVector.pop_back(); // Close and delete - toDel->Close(); - delete toDel; +win32 rename delete toDel; } ASSERT(rVector.size() == 0); } |