Changeset 11369
- Timestamp:
- 2008-09-05 10:57:26 (3 months ago)
- Location:
- trunk/xapian-core
- Files:
-
- 8 modified
-
ChangeLog (modified) (1 diff)
-
api/omdatabase.cc (modified) (1 diff)
-
backends/remote/remote-database.cc (modified) (3 diffs)
-
common/database.h (modified) (1 diff)
-
common/remote-database.h (modified) (2 diffs)
-
include/xapian/database.h (modified) (1 diff)
-
net/remoteserver.cc (modified) (2 diffs)
-
tests/api_anydb.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xapian-core/ChangeLog
r11368 r11369 1 Fri 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 1 14 Thu Sep 04 11:37:54 GMT 2008 Richard Boulton <richard@lemurconsulting.com> 2 15 -
trunk/xapian-core/api/omdatabase.cc
r11118 r11369 556 556 } 557 557 558 std::string 559 Database::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 558 576 /////////////////////////////////////////////////////////////////////////// 559 577 -
trunk/xapian-core/backends/remote/remote-database.cc
r10725 r11369 110 110 has_positional_info = (*p++ == '1'); 111 111 avlength = unserialise_double(&p, p_end); 112 size_t len = decode_length(&p, p_end, true); 113 uuid = string(p, len); 114 p += len; 112 115 if (p != p_end || avlength < 0) { 113 116 throw Xapian::NetworkError("Bad greeting message received (double)", context); … … 315 318 has_positional_info = (*p++ == '1'); 316 319 avlength = unserialise_double(&p, p_end); 320 size_t len = decode_length(&p, p_end, true); 321 uuid = string(p, len); 322 p += len; 317 323 if (p != p_end || avlength < 0) { 318 324 throw Xapian::NetworkError("Bad REPLY_UPDATE message received", context); … … 647 653 return decode_length(&p, p_end, false); 648 654 } 655 656 string 657 RemoteDatabase::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 473 473 /** Get a UUID for the database. 474 474 * 475 * The UUID will persist for the lifetime of the database. 476 * 475 477 * Replicas (eg, made with the replication protocol, or by copying all 476 478 * the database files) will have the same UUID. However, copies (made 477 479 * 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. 478 483 */ 479 484 virtual string get_uuid() const; -
trunk/xapian-core/common/remote-database.h
r10675 r11369 65 65 /// Has positional information? 66 66 mutable bool has_positional_info; 67 68 /// The UUID of the remote database. 69 mutable string uuid; 67 70 68 71 /// The context to return with any error messages … … 218 221 Xapian::docid replace_document(const std::string & unique_term, 219 222 const Xapian::Document & document); 223 224 std::string get_uuid() const; 220 225 }; 221 226 -
trunk/xapian-core/include/xapian/database.h
r10675 r11369 363 363 return Xapian::TermIterator(NULL); 364 364 } 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; 365 378 }; 366 379 -
trunk/xapian-core/net/remoteserver.cc
r10726 r11369 97 97 message += (db->has_positions() ? '1' : '0'); 98 98 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; 99 107 send_message(REPLY_GREETING, message); 100 108 … … 338 346 message += (db->has_positions() ? '1' : '0'); 339 347 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; 340 356 send_message(REPLY_UPDATE, message); 341 357 } -
trunk/xapian-core/tests/api_anydb.cc
r10889 r11369 2248 2248 return true; 2249 2249 } 2250 2251 // Feature test for get_uuid. 2252 DEFINE_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 }
