Changeset 2794 for box/trunk/bin


Ignore:
Timestamp:
18/10/2010 21:34:25 (19 months ago)
Author:
chris
Message:

Revert [2710] and [2717], remove TDB and replace with QDBM again, to fix
build on Windows and make it easier to merge Charles' work.

Location:
box/trunk/bin/bbackupd
Files:
2 edited

Legend:

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

    r2717 r2794  
    1111 
    1212#include <stdlib.h> 
    13  
    14 #define _PUBLIC_ 
    15 #include "tdb.h" 
     13#include <depot.h> 
    1614 
    1715#define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION 
     
    2927} IDBRecord; 
    3028 
    31 #define BOX_DBM_MESSAGE(stuff) stuff << " (tdb): " << tdb_error(mpContext) 
     29#define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode) 
    3230 
    3331#define BOX_LOG_DBM_ERROR(stuff) \ 
     
    3937                BOX_DBM_MESSAGE(message << ": " << filename)); 
    4038 
    41 #define ASSERT_DBM(success, message, exception, subtype) \ 
    42         if(!(success)) \ 
     39#define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \ 
     40        if(!(operation)) \ 
    4341        { \ 
    44                 THROW_DBM_ERROR(message, mFilename, exception, subtype); \ 
     42                THROW_DBM_ERROR(message, filename, exception, subtype); \ 
    4543        } 
    4644 
    4745#define ASSERT_DBM_OPEN() \ 
    48         if(mpContext == 0) \ 
     46        if(mpDepot == 0) \ 
    4947        { \ 
    5048                THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ 
     
    5351 
    5452#define ASSERT_DBM_CLOSED() \ 
    55         if(mpContext != 0) \ 
     53        if(mpDepot != 0) \ 
    5654        { \ 
    5755                THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ 
     
    7068        : mReadOnly(true), 
    7169          mEmpty(false), 
    72           mpContext(NULL) 
     70          mpDepot(0) 
    7371{ 
    7472} 
     
    8482BackupClientInodeToIDMap::~BackupClientInodeToIDMap() 
    8583{ 
    86         if(mpContext != NULL) 
     84        if(mpDepot != 0) 
    8785        { 
    8886                Close(); 
     
    111109         
    112110        // Open the database file 
    113         int mode = ReadOnly ? O_RDONLY : O_RDWR; 
     111        int mode = ReadOnly ? DP_OREADER : DP_OWRITER; 
    114112        if(CreateNew) 
    115113        { 
    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", 
     114                mode |= DP_OCREAT; 
     115        } 
     116         
     117        mpDepot = dpopen(Filename, mode, 0); 
     118         
     119        ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename, 
    122120                BackupStoreException, BerkelyDBFailure); 
    123121         
     
    140138{ 
    141139        ASSERT_DBM_CLOSED(); 
    142         ASSERT(mpContext == NULL); 
     140        ASSERT(mpDepot == 0); 
    143141        mEmpty = true; 
    144142        mReadOnly = true; 
     
    156154{ 
    157155        ASSERT_DBM_OPEN(); 
    158         ASSERT_DBM(tdb_close(mpContext) == 0, "Failed to close inode database", 
    159                 BackupStoreException, BerkelyDBFailure); 
    160         mpContext = NULL; 
    161 } 
    162  
    163 static 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)) 
     156        ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", 
     157                mFilename, BackupStoreException, BerkelyDBFailure); 
     158        mpDepot = 0; 
     159} 
    173160 
    174161// -------------------------------------------------------------------------- 
     
    190177        } 
    191178 
    192         if(mpContext == 0) 
     179        if(mpDepot == 0) 
    193180        { 
    194181                THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); 
     
    202189        rec.mInDirectory = InDirectory; 
    203190 
    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", 
     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, 
    207194                BackupStoreException, BerkelyDBFailure); 
    208195} 
     
    228215        } 
    229216 
    230         if(mpContext == 0) 
     217        if(mpDepot == 0) 
    231218        { 
    232219                THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); 
     
    235222        ASSERT_DBM_OPEN(); 
    236223 
    237         TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef)); 
    238         if(datum.dptr == NULL) 
     224        IDBRecord rec; 
     225         
     226        if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), 
     227                0, sizeof(IDBRecord), (char *)&rec) == -1) 
    239228        { 
    240229                // key not in file 
    241230                return false; 
    242231        } 
    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         } 
    253232                 
    254         rec = *(IDBRecord *)datum.dptr; 
    255         free(datum.dptr); 
    256          
    257233        // Return data 
    258234        rObjectIDOut = rec.mObjectID; 
  • box/trunk/bin/bbackupd/BackupClientInodeToIDMap.h

    r2717 r2794  
    1818// avoid having to include the DB files when not necessary 
    1919#ifndef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION 
    20         struct TDB_CONTEXT; 
    21         struct TDB_DATUM; 
     20        class DEPOT; 
    2221#endif 
    2322 
     
    5150        bool mEmpty; 
    5251        std::string mFilename; 
    53         TDB_CONTEXT *mpContext; 
     52        DEPOT *mpDepot; 
    5453}; 
    5554 
Note: See TracChangeset for help on using the changeset viewer.