Changeset 11369

Show
Ignore:
Timestamp:
2008-09-05 10:57:26 (3 months ago)
Author:
richard
Message:

include/xapian/database.h,api/omdatabase.cc: Add
Database.get_uuid() which returns a unique identifier for the
database.
tests/api_anydb.cc: Add test uuid1 to test basic get_uuid()
behaviour.
common/database.h: Extend documentation comment for get_uuid() a
bit.
backends/remote/remote-database.cc,common/remote-database.h,
net/remoteserver.cc: Add support for get_uuid() to remote
databases.

Location:
trunk/xapian-core
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/xapian-core/ChangeLog

    r11368 r11369  
     1Fri Sep 05 09:38:35 GMT 2008  Richard Boulton <richard@lemurconsulting.com> 
     2 
     3        * include/xapian/database.h,api/omdatabase.cc: Add 
     4          Database.get_uuid() which returns a unique identifier for the 
     5          database. 
     6        * tests/api_anydb.cc: Add test uuid1 to test basic get_uuid() 
     7          behaviour. 
     8        * common/database.h: Extend documentation comment for get_uuid() a 
     9          bit. 
     10        * backends/remote/remote-database.cc,common/remote-database.h, 
     11          net/remoteserver.cc: Add support for get_uuid() to remote 
     12          databases. 
     13 
    114Thu Sep 04 11:37:54 GMT 2008  Richard Boulton <richard@lemurconsulting.com> 
    215 
  • trunk/xapian-core/api/omdatabase.cc

    r11118 r11369  
    556556} 
    557557 
     558std::string 
     559Database::get_uuid() const 
     560{ 
     561    DEBUGAPICALL(std::string, "Database::get_uuid", ""); 
     562    if (internal.size() != 1) { 
     563        if (internal.size() == 0) { 
     564            throw InvalidOperationError( 
     565                "UUIDs not supported for uninitialised databases"); 
     566        } 
     567 
     568        // FIXME - we could probably make a uuid for each multidatabase 
     569        // combination by hashing together the uuids for the subdatabases. 
     570        throw UnimplementedError( 
     571            "UUIDs not supported for multiple databases"); 
     572    } 
     573    RETURN(internal[0]->get_uuid()); 
     574} 
     575 
    558576/////////////////////////////////////////////////////////////////////////// 
    559577 
  • trunk/xapian-core/backends/remote/remote-database.cc

    r10725 r11369  
    110110    has_positional_info = (*p++ == '1'); 
    111111    avlength = unserialise_double(&p, p_end); 
     112    size_t len = decode_length(&p, p_end, true); 
     113    uuid = string(p, len); 
     114    p += len; 
    112115    if (p != p_end || avlength < 0) { 
    113116        throw Xapian::NetworkError("Bad greeting message received (double)", context); 
     
    315318    has_positional_info = (*p++ == '1'); 
    316319    avlength = unserialise_double(&p, p_end); 
     320    size_t len = decode_length(&p, p_end, true); 
     321    uuid = string(p, len); 
     322    p += len; 
    317323    if (p != p_end || avlength < 0) { 
    318324        throw Xapian::NetworkError("Bad REPLY_UPDATE message received", context); 
     
    647653    return decode_length(&p, p_end, false); 
    648654} 
     655 
     656string 
     657RemoteDatabase::get_uuid() const 
     658{ 
     659    if (uuid.empty()) 
     660        throw Xapian::UnimplementedError( 
     661            "UUIDs not supported for this database"); 
     662    return uuid; 
     663} 
  • trunk/xapian-core/common/database.h

    r11039 r11369  
    473473        /** Get a UUID for the database. 
    474474         * 
     475         *  The UUID will persist for the lifetime of the database. 
     476         * 
    475477         *  Replicas (eg, made with the replication protocol, or by copying all 
    476478         *  the database files) will have the same UUID.  However, copies (made 
    477479         *  with copydatabase, or xapian-compact) will have different UUIDs. 
     480         * 
     481         *  If the backend does not support UUIDs, or this database has 
     482         *  multiple sub-databases, an exception will be raised. 
    478483         */ 
    479484        virtual string get_uuid() const; 
  • trunk/xapian-core/common/remote-database.h

    r10675 r11369  
    6565    /// Has positional information? 
    6666    mutable bool has_positional_info; 
     67 
     68    /// The UUID of the remote database. 
     69    mutable string uuid; 
    6770 
    6871    /// The context to return with any error messages 
     
    218221    Xapian::docid replace_document(const std::string & unique_term, 
    219222                                   const Xapian::Document & document); 
     223 
     224    std::string get_uuid() const; 
    220225}; 
    221226 
  • trunk/xapian-core/include/xapian/database.h

    r10675 r11369  
    363363            return Xapian::TermIterator(NULL); 
    364364        } 
     365 
     366        /** Get a UUID for the database. 
     367         * 
     368         *  The UUID will persist for the lifetime of the database. 
     369         * 
     370         *  Replicas (eg, made with the replication protocol, or by copying all 
     371         *  the database files) will have the same UUID.  However, copies (made 
     372         *  with copydatabase, or xapian-compact) will have different UUIDs. 
     373         * 
     374         *  If the backend does not support UUIDs, or this database has 
     375         *  multiple sub-databases, an exception will be raised. 
     376         */ 
     377        std::string get_uuid() const; 
    365378}; 
    366379 
  • trunk/xapian-core/net/remoteserver.cc

    r10726 r11369  
    9797    message += (db->has_positions() ? '1' : '0'); 
    9898    message += serialise_double(db->get_avlength()); 
     99    string uuid; 
     100    try { 
     101        uuid = db->get_uuid(); 
     102    } catch (const Xapian::UnimplementedError &err) { 
     103        // Leave the uuid empty. 
     104    } 
     105    message += encode_length(uuid.size()); 
     106    message += uuid; 
    99107    send_message(REPLY_GREETING, message); 
    100108 
     
    338346    message += (db->has_positions() ? '1' : '0'); 
    339347    message += serialise_double(db->get_avlength()); 
     348    string uuid; 
     349    try { 
     350        uuid = db->get_uuid(); 
     351    } catch (const Xapian::UnimplementedError &err) { 
     352        // Leave the uuid empty. 
     353    } 
     354    message += encode_length(uuid.size()); 
     355    message += uuid; 
    340356    send_message(REPLY_UPDATE, message); 
    341357} 
  • trunk/xapian-core/tests/api_anydb.cc

    r10889 r11369  
    22482248    return true; 
    22492249} 
     2250 
     2251// Feature test for get_uuid. 
     2252DEFINE_TESTCASE(uuid1, backend && !multi) { 
     2253    SKIP_TEST_FOR_BACKEND("inmemory"); 
     2254    Xapian::Database db = get_database("apitest_simpledata"); 
     2255    std::string uuid1 = db.get_uuid(); 
     2256 
     2257    Xapian::Database db2; 
     2258    TEST_EXCEPTION(Xapian::InvalidOperationError, db2.get_uuid()); 
     2259 
     2260    db2.add_database(db); 
     2261    TEST_EQUAL(uuid1, db2.get_uuid()); 
     2262 
     2263    db2.add_database(db); 
     2264    TEST_EXCEPTION(Xapian::UnimplementedError, db2.get_uuid()); 
     2265 
     2266    return true; 
     2267}