Ignore:
Timestamp:
28/08/2010 10:01:16 (21 months ago)
Author:
chris
Message:

Remove QDBM, and switch BackupClientInodeToIDMap to use the bundled TDB
instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupClientInodeToIDMap.cpp

    r2631 r2717  
    1111 
    1212#include <stdlib.h> 
    13 #include <depot.h> 
     13 
     14#define _PUBLIC_ 
     15#include "tdb.h" 
    1416 
    1517#define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION 
     
    2729} IDBRecord; 
    2830 
    29 #define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode) 
     31#define BOX_DBM_MESSAGE(stuff) stuff << " (tdb): " << tdb_error(mpContext) 
    3032 
    3133#define BOX_LOG_DBM_ERROR(stuff) \ 
     
    3739                BOX_DBM_MESSAGE(message << ": " << filename)); 
    3840 
    39 #define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \ 
    40         if(!(operation)) \ 
     41#define ASSERT_DBM(success, message, exception, subtype) \ 
     42        if(!(success)) \ 
    4143        { \ 
    42                 THROW_DBM_ERROR(message, filename, exception, subtype); \ 
     44                THROW_DBM_ERROR(message, mFilename, exception, subtype); \ 
    4345        } 
    4446 
    4547#define ASSERT_DBM_OPEN() \ 
    46         if(mpDepot == 0) \ 
     48        if(mpContext == 0) \ 
    4749        { \ 
    4850                THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ 
     
    5153 
    5254#define ASSERT_DBM_CLOSED() \ 
    53         if(mpDepot != 0) \ 
     55        if(mpContext != 0) \ 
    5456        { \ 
    5557                THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ 
     
    6870        : mReadOnly(true), 
    6971          mEmpty(false), 
    70           mpDepot(0) 
     72          mpContext(NULL) 
    7173{ 
    7274} 
     
    8284BackupClientInodeToIDMap::~BackupClientInodeToIDMap() 
    8385{ 
    84         if(mpDepot != 0) 
     86        if(mpContext != NULL) 
    8587        { 
    8688                Close(); 
     
    109111         
    110112        // Open the database file 
    111         int mode = ReadOnly ? DP_OREADER : DP_OWRITER; 
     113        int mode = ReadOnly ? O_RDONLY : O_RDWR; 
    112114        if(CreateNew) 
    113115        { 
    114                 mode |= DP_OCREAT; 
    115         } 
    116          
    117         mpDepot = dpopen(Filename, mode, 0); 
    118          
    119         ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename, 
     116                mode |= O_CREAT; 
     117        } 
     118         
     119        mpContext = tdb_open(Filename, 0, 0, mode, 0700); 
     120         
     121        ASSERT_DBM(mpContext != NULL, "Failed to open inode database", 
    120122                BackupStoreException, BerkelyDBFailure); 
    121123         
     
    138140{ 
    139141        ASSERT_DBM_CLOSED(); 
    140         ASSERT(mpDepot == 0); 
     142        ASSERT(mpContext == NULL); 
    141143        mEmpty = true; 
    142144        mReadOnly = true; 
     
    154156{ 
    155157        ASSERT_DBM_OPEN(); 
    156         ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", 
    157                 mFilename, BackupStoreException, BerkelyDBFailure); 
    158         mpDepot = 0; 
    159 } 
     158        ASSERT_DBM(tdb_close(mpContext) == 0, "Failed to close inode database", 
     159                BackupStoreException, BerkelyDBFailure); 
     160        mpContext = NULL; 
     161} 
     162 
     163static TDB_DATA GetDatum(void* dptr, size_t dsize) 
     164{ 
     165        TDB_DATA datum; 
     166        datum.dptr = (unsigned char *)dptr; 
     167        datum.dsize = dsize; 
     168        return datum; 
     169} 
     170 
     171#define GET_STRUCT_DATUM(structure) \ 
     172        GetDatum(&structure, sizeof(structure)) 
    160173 
    161174// -------------------------------------------------------------------------- 
     
    177190        } 
    178191 
    179         if(mpDepot == 0) 
     192        if(mpContext == 0) 
    180193        { 
    181194                THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); 
     
    189202        rec.mInDirectory = InDirectory; 
    190203 
    191         ASSERT_DBM_OK(dpput(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), 
    192                 (const char *)&rec, sizeof(rec), DP_DOVER), 
    193                 "Failed to add record to inode database", mFilename, 
     204        ASSERT_DBM(tdb_store(mpContext, GET_STRUCT_DATUM(InodeRef), 
     205                GET_STRUCT_DATUM(rec), 0) == 0, 
     206                "Failed to add record to inode database", 
    194207                BackupStoreException, BerkelyDBFailure); 
    195208} 
     
    215228        } 
    216229 
    217         if(mpDepot == 0) 
     230        if(mpContext == 0) 
    218231        { 
    219232                THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); 
     
    222235        ASSERT_DBM_OPEN(); 
    223236 
    224         IDBRecord rec; 
    225          
    226         if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), 
    227                 0, sizeof(IDBRecord), (char *)&rec) == -1) 
     237        TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef)); 
     238        if(datum.dptr == NULL) 
    228239        { 
    229240                // key not in file 
    230241                return false; 
    231242        } 
     243 
     244        IDBRecord rec; 
     245        if(datum.dsize != sizeof(rec)) 
     246        { 
     247                THROW_EXCEPTION_MESSAGE(CommonException, Internal, 
     248                        "Failed to get inode database entry: " 
     249                        "record has wrong size: expected " << 
     250                        sizeof(rec) << " but was " << datum.dsize << 
     251                        " in " << mFilename); 
     252        } 
    232253                 
     254        rec = *(IDBRecord *)datum.dptr; 
     255        free(datum.dptr); 
     256         
    233257        // Return data 
    234258        rObjectIDOut = rec.mObjectID; 
Note: See TracChangeset for help on using the changeset viewer.