Ticket #278: max_changesets_post_review.diff
File max_changesets_post_review.diff, 16.6 KB (added by , 14 years ago) |
---|
-
xapian-core/backends/brass/brass_database.cc
diff --git a/xapian-core/backends/brass/brass_database.cc b/xapian-core/backends/brass/brass_database.cc index 56f534e..0f5fe00 100644
a b 7 7 * Copyright 2006,2008 Lemur Consulting Ltd 8 8 * Copyright 2009 Richard Boulton 9 9 * Copyright 2009 Kan-Ru Chen 10 * Copyright 2011 Dan Colish 10 11 * 11 12 * This program is free software; you can redistribute it and/or 12 13 * modify it under the terms of the GNU General Public License as … … BrassDatabase::BrassDatabase(const string &brass_dir, int action, 120 121 return; 121 122 } 122 123 123 const char *p = getenv("XAPIAN_MAX_CHANGESETS");124 if (p)125 max_changesets = atoi(p);126 127 124 if (action != Xapian::DB_OPEN && !database_exists()) { 128 125 // FIXME: if we allow Xapian::DB_OVERWRITE, check it here 129 126 … … BrassDatabase::set_revision_number(brass_revision_number_t new_revision) 400 397 401 398 int changes_fd = -1; 402 399 string changes_name; 400 401 // always check max_changesets for modification since last revision 402 const char *p = getenv("XAPIAN_MAX_CHANGESETS"); 403 if (p) { 404 max_changesets = atoi(p); 405 } 403 406 404 407 if (max_changesets > 0) { 405 408 brass_revision_number_t old_revision = get_revision_number(); … … BrassDatabase::set_revision_number(brass_revision_number_t new_revision) 470 473 471 474 throw; 472 475 } 476 477 // Only remove the oldest_changeset if we successfully write a new changeset and 478 // we have a revision number greater than max_changesets 479 if (changes_fd >= 0 && max_changesets < new_revision) { 480 // use the oldest changeset we know about to begin deleting to the stop_changeset 481 // if nothing went wrong only one file should be deleted, otherwise 482 // attempts will be made to clean up more 483 brass_revision_number_t oldest_changeset = stats.get_oldest_changeset(); 484 brass_revision_number_t stop_changeset = new_revision - max_changesets; 485 while (oldest_changeset < stop_changeset) { 486 if (io_unlink(db_dir + "/changes" + str(oldest_changeset))) { 487 LOGLINE(DB, "Removed changeset " << oldest_changeset); 488 } else { 489 LOGLINE(DB, "Skipping changeset " << oldest_changeset << 490 ", likely removed before"); 491 } 492 stats.set_oldest_changeset(oldest_changeset++); 493 } 494 } 473 495 } 474 496 475 497 void -
xapian-core/backends/brass/brass_database.h
diff --git a/xapian-core/backends/brass/brass_database.h b/xapian-core/backends/brass/brass_database.h index 6f8e928..5e14d72 100644
a b 4 4 * Copyright 2002 Ananova Ltd 5 5 * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010 Olly Betts 6 6 * Copyright 2008 Lemur Consulting Ltd 7 * Copyright 2011 Dan Colish 7 8 * 8 9 * This program is free software; you can redistribute it and/or 9 10 * modify it under the terms of the GNU General Public License as … … class BrassDatabase : public Xapian::Database::Internal { 216 217 void get_changeset_revisions(const string & path, 217 218 brass_revision_number_t * startrev, 218 219 brass_revision_number_t * endrev) const; 220 219 221 public: 220 222 /** Create and open a brass database. 221 223 * -
xapian-core/backends/brass/brass_dbstats.cc
diff --git a/xapian-core/backends/brass/brass_dbstats.cc b/xapian-core/backends/brass/brass_dbstats.cc index d4bff9e..9d5bcec 100644
a b 2 2 * @brief Brass class for database statistics. 3 3 */ 4 4 /* Copyright (C) 2009 Olly Betts 5 * Copyright (C) 2011 Dan Colish 5 6 * 6 7 * This program is free software; you can redistribute it and/or 7 8 * modify it under the terms of the GNU General Public License as … … BrassDatabaseStats::read(BrassPostListTable & postlist_table) 35 36 string data; 36 37 if (!postlist_table.get_exact_entry(DATABASE_STATS_KEY, data)) { 37 38 // If there's no entry yet, then all the values are zero. 38 total_doclen = 0; 39 last_docid = 0; 40 doclen_lbound = 0; 41 doclen_ubound = 0; 42 wdf_ubound = 0; 39 zero(); 43 40 return; 44 41 } 45 42 … … BrassDatabaseStats::read(BrassPostListTable & postlist_table) 50 47 unpack_uint(&p, end, &doclen_lbound) && 51 48 unpack_uint(&p, end, &wdf_ubound) && 52 49 unpack_uint(&p, end, &doclen_ubound) && 50 unpack_uint(&p, end, &oldest_changeset) && 53 51 unpack_uint_last(&p, end, &total_doclen)) { 54 52 // doclen_ubound should always be >= wdf_ubound, so we store the 55 53 // difference as it may encode smaller. wdf_ubound is likely to … … BrassDatabaseStats::write(BrassPostListTable & postlist_table) const 75 73 // difference as it may encode smaller. wdf_ubound is likely to 76 74 // be larger than doclen_lbound. 77 75 pack_uint(data, doclen_ubound - wdf_ubound); 76 pack_uint(data, oldest_changeset); 78 77 // Micro-optimisation: total_doclen is likely to be the largest value, so 79 78 // store it last as pack_uint_last() uses a slightly more compact encoding 80 79 // - this could save us a few bytes! -
xapian-core/backends/brass/brass_dbstats.h
diff --git a/xapian-core/backends/brass/brass_dbstats.h b/xapian-core/backends/brass/brass_dbstats.h index d3a281e..131afd8 100644
a b 2 2 * @brief Brass class for database statistics. 3 3 */ 4 4 /* Copyright (C) 2009 Olly Betts 5 * Copyright (C) 2011 Dan Colish 5 6 * 6 7 * This program is free software; you can redistribute it and/or 7 8 * modify it under the terms of the GNU General Public License as … … class BrassDatabaseStats { 51 52 /// An upper bound on the greatest wdf in this database. 52 53 Xapian::termcount wdf_ubound; 53 54 55 /// Oldest changeset removed when max_changesets is set 56 brass_revision_number_t oldest_changeset; 57 54 58 public: 55 59 BrassDatabaseStats() 56 60 : total_doclen(0), last_docid(0), doclen_lbound(0), doclen_ubound(0), 57 wdf_ubound(0) { }61 wdf_ubound(0), oldest_changeset(0) { } 58 62 59 63 totlen_t get_total_doclen() const { return total_doclen; } 60 64 … … class BrassDatabaseStats { 70 74 71 75 Xapian::termcount get_wdf_upper_bound() const { return wdf_ubound; } 72 76 77 brass_revision_number_t get_oldest_changeset() const { return oldest_changeset; } 78 73 79 void zero() { 74 80 total_doclen = 0; 75 81 last_docid = 0; 76 82 doclen_lbound = 0; 77 83 doclen_ubound = 0; 78 84 wdf_ubound = 0; 85 oldest_changeset = 0; 79 86 } 80 87 81 88 void read(BrassPostListTable & postlist_table); 82 89 83 90 void set_last_docid(Xapian::docid did) { last_docid = did; } 84 91 92 void set_oldest_changeset(brass_revision_number_t changeset) { oldest_changeset = changeset; } 93 85 94 void add_document(Xapian::termcount doclen) { 86 95 if (total_doclen == 0 || (doclen && doclen < doclen_lbound)) 87 96 doclen_lbound = doclen; -
xapian-core/backends/brass/brass_version.cc
diff --git a/xapian-core/backends/brass/brass_version.cc b/xapian-core/backends/brass/brass_version.cc index b54fb4b..b0190a9 100644
a b 2 2 * @brief BrassVersion class 3 3 */ 4 4 /* Copyright (C) 2006,2007,2008,2009,2010 Olly Betts 5 * Copyright (C) 2011 Dan Colish 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify 7 8 * it under the terms of the GNU General Public License as published by … … 43 44 using namespace std; 44 45 45 46 // YYYYMMDDX where X allows multiple format revisions in a day 46 #define BRASS_VERSION 200912150 47 #define BRASS_VERSION 201103110 48 // 201103110 1.2.5? Bump for new max changesets dbstats 47 49 // 200912150 1.1.4 Brass debuts. 48 50 49 51 #define MAGIC_STRING "IAmBrass" -
xapian-core/backends/chert/chert_database.cc
diff --git a/xapian-core/backends/chert/chert_database.cc b/xapian-core/backends/chert/chert_database.cc index 3cc6b56..7ebb9dc 100644
a b 7 7 * Copyright 2006,2008 Lemur Consulting Ltd 8 8 * Copyright 2009,2010 Richard Boulton 9 9 * Copyright 2009 Kan-Ru Chen 10 * Copyright 2011 Dan Colish 10 11 * 11 12 * This program is free software; you can redistribute it and/or 12 13 * modify it under the terms of the GNU General Public License as … … ChertDatabase::ChertDatabase(const string &chert_dir, int action, 123 124 return; 124 125 } 125 126 126 const char *p = getenv("XAPIAN_MAX_CHANGESETS");127 if (p)128 max_changesets = atoi(p);129 130 127 if (action != Xapian::DB_OPEN && !database_exists()) { 131 128 // FIXME: if we allow Xapian::DB_OVERWRITE, check it here 132 129 … … ChertDatabase::set_revision_number(chert_revision_number_t new_revision) 404 401 int changes_fd = -1; 405 402 string changes_name; 406 403 404 const char *p = getenv("XAPIAN_MAX_CHANGESETS"); 405 if (p) 406 max_changesets = atoi(p); 407 407 408 if (max_changesets > 0) { 408 409 chert_revision_number_t old_revision = get_revision_number(); 409 410 if (old_revision) { … … ChertDatabase::set_revision_number(chert_revision_number_t new_revision) 465 466 466 467 throw; 467 468 } 469 470 if (changes_fd >= 0 && max_changesets < new_revision) { 471 // While change sets less than N - max_changesets exist, delete them 472 // 1 must be subtracted so we don't delete the changeset we just wrote 473 // when max_changesets = 1 474 unsigned rev = new_revision - max_changesets - 1; 475 while (io_unlink(db_dir + "/changes" + str(rev--))) { } 476 } 468 477 } 469 478 470 479 void -
xapian-core/backends/flint/flint_database.cc
diff --git a/xapian-core/backends/flint/flint_database.cc b/xapian-core/backends/flint/flint_database.cc index d5eb8a1..297530c 100644
a b 7 7 * Copyright 2006,2008 Lemur Consulting Ltd 8 8 * Copyright 2009,2010 Richard Boulton 9 9 * Copyright 2009 Kan-Ru Chen 10 * Copyright 2011 Dan Colish 10 11 * 11 12 * This program is free software; you can redistribute it and/or 12 13 * modify it under the terms of the GNU General Public License as … … FlintDatabase::FlintDatabase(const string &flint_dir, int action, 121 122 return; 122 123 } 123 124 124 const char *p = getenv("XAPIAN_MAX_CHANGESETS");125 if (p)126 max_changesets = atoi(p);127 128 125 if (action != Xapian::DB_OPEN && !database_exists()) { 129 126 // FIXME: if we allow Xapian::DB_OVERWRITE, check it here 130 127 … … FlintDatabase::set_revision_number(flint_revision_number_t new_revision) 434 431 int changes_fd = -1; 435 432 string changes_name; 436 433 434 const char *p = getenv("XAPIAN_MAX_CHANGESETS"); 435 if (p) 436 max_changesets = atoi(p); 437 437 438 if (max_changesets > 0) { 438 439 flint_revision_number_t old_revision = get_revision_number(); 439 440 if (old_revision) { … … FlintDatabase::set_revision_number(flint_revision_number_t new_revision) 497 498 498 499 throw; 499 500 } 501 502 if (changes_fd >= 0 && max_changesets < new_revision) { 503 // while change sets less than N - max_changesets exist, delete them 504 // 1 must be subtracted so we don't delete the changset we just wrote 505 // when max_changesets = 1 506 unsigned rev = new_revision - max_changesets - 1; 507 while (io_unlink(db_dir + "/changes" + str(rev--))) { } 508 } 500 509 } 501 510 502 511 void -
xapian-core/tests/api_replicate.cc
diff --git a/xapian-core/tests/api_replicate.cc b/xapian-core/tests/api_replicate.cc index fdd18f8..cd24fdd 100644
a b 3 3 * Copyright 2008 Lemur Consulting Ltd 4 4 * Copyright 2009,2010 Olly Betts 5 5 * Copyright 2010 Richard Boulton 6 * Copyright 2011 Dan Colish 6 7 * 7 8 * This program is free software; you can redistribute it and/or 8 9 * modify it under the terms of the GNU General Public License as … … DEFINE_TESTCASE(replicate3, replicas) { 512 513 return true; 513 514 } 514 515 515 // Basic test of replication functionality.516 // Tests for max_changesets 516 517 DEFINE_TESTCASE(replicate4, replicas) { 517 518 string tempdir = ".replicatmp"; 518 519 mktmpdir(tempdir); 519 520 string masterpath = get_named_writable_database_path("master"); 520 521 521 set_max_changesets(10); 522 set_max_changesets(1); 523 524 Xapian::WritableDatabase orig(get_named_writable_database("master")); 525 Xapian::DatabaseMaster master(masterpath); 526 string replicapath = tempdir + "/replica"; 527 Xapian::DatabaseReplica replica(replicapath); 528 529 // Add a document with no positions to the original database. 530 Xapian::Document doc1; 531 doc1.set_data(string("doc1")); 532 doc1.add_term("nopos"); 533 orig.add_document(doc1); 534 orig.commit(); 535 536 // Apply the replication - we don't have changesets stored, so this should 537 // just do a database copy, and return a count of 1. 538 int count = replicate(master, replica, tempdir, 0, 1, 1); 539 TEST_EQUAL(count, 1); 540 { 541 Xapian::Database dbcopy(replicapath); 542 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 543 } 544 545 // Add a document with positional information to the original database. 546 doc1.add_posting("pos", 1); 547 orig.add_document(doc1); 548 orig.commit(); 549 550 // Replicate, and check that we have the positional information. 551 count = replicate(master, replica, tempdir, 1, 0, 1); 552 TEST_EQUAL(count, 2); 553 { 554 Xapian::Database dbcopy(replicapath); 555 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 556 } 557 check_equal_dbs(masterpath, replicapath); 558 559 // Add a document with no positions to the original database. 560 Xapian::Document doc2; 561 doc2.set_data(string("doc2")); 562 doc2.add_term("nopos"); 563 orig.add_document(doc2); 564 orig.commit(); 565 566 // Replicate, and check that we have the positional information. 567 count = replicate(master, replica, tempdir, 1, 0, 1); 568 TEST_EQUAL(count, 2); 569 { 570 Xapian::Database dbcopy(replicapath); 571 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 572 } 573 check_equal_dbs(masterpath, replicapath); 574 TEST(!file_exists(masterpath + "/changes1")); 575 576 // Need to close the replica before we remove the temporary directory on 577 // Windows. 578 replica.close(); 579 rmtmpdir(tempdir); 580 return true; 581 } 582 583 584 // Tests for max_changesets 585 DEFINE_TESTCASE(replicate5, replicas) { 586 SKIP_TEST_FOR_BACKEND("chert"); 587 SKIP_TEST_FOR_BACKEND("flint"); 588 string tempdir = ".replicatmp"; 589 mktmpdir(tempdir); 590 string masterpath = get_named_writable_database_path("master"); 591 592 set_max_changesets(2); 522 593 523 594 Xapian::WritableDatabase orig(get_named_writable_database("master")); 524 595 Xapian::DatabaseMaster master(masterpath); … … DEFINE_TESTCASE(replicate4, replicas) { 555 626 } 556 627 check_equal_dbs(masterpath, replicapath); 557 628 629 // Add a document with no positions to the original database. 630 Xapian::Document doc2; 631 doc2.set_data(string("doc2")); 632 doc2.add_term("nopos"); 633 orig.add_document(doc2); 634 orig.commit(); 635 636 // Replicate, and check that we have the positional information. 637 count = replicate(master, replica, tempdir, 1, 0, 1); 638 TEST_EQUAL(count, 2); 639 { 640 Xapian::Database dbcopy(replicapath); 641 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 642 } 643 check_equal_dbs(masterpath, replicapath); 644 645 // Add a document with no positions to the original database. 646 Xapian::Document doc3; 647 doc3.set_data(string("doc3")); 648 doc3.add_term("nonopos"); 649 orig.add_document(doc3); 650 orig.commit(); 651 652 // Replicate, and check that we have the positional information. 653 count = replicate(master, replica, tempdir, 1, 0, 1); 654 TEST_EQUAL(count, 2); 655 { 656 Xapian::Database dbcopy(replicapath); 657 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 658 } 659 check_equal_dbs(masterpath, replicapath); 660 661 // Ensure that only these changesets exists 662 TEST(!file_exists(masterpath + "/changes1")); 663 TEST(file_exists(masterpath + "/changes2")); 664 TEST(file_exists(masterpath + "/changes3")); 665 666 set_max_changesets(3); 667 masterpath = get_named_writable_database_path("master"); 668 669 // Add a document with no positions to the original database. 670 Xapian::Document doc4; 671 doc4.set_data(string("doc4")); 672 doc4.add_term("nononopos"); 673 orig.add_document(doc4); 674 orig.commit(); 675 676 // Replicate, and check that we have the positional information. 677 count = replicate(master, replica, tempdir, 1, 0, 1); 678 TEST_EQUAL(count, 2); 679 { 680 Xapian::Database dbcopy(replicapath); 681 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 682 } 683 check_equal_dbs(masterpath, replicapath); 684 685 // Add a document with no positions to the original database. 686 Xapian::Document doc5; 687 doc5.set_data(string("doc5")); 688 doc5.add_term("nonononopos"); 689 orig.add_document(doc5); 690 orig.commit(); 691 692 // Replicate, and check that we have the positional information. 693 count = replicate(master, replica, tempdir, 1, 0, 1); 694 TEST_EQUAL(count, 2); 695 { 696 Xapian::Database dbcopy(replicapath); 697 TEST_EQUAL(orig.get_uuid(), dbcopy.get_uuid()); 698 } 699 check_equal_dbs(masterpath, replicapath); 700 701 TEST(!file_exists(masterpath + "/changes2")); 702 TEST(file_exists(masterpath + "/changes3")); 703 TEST(file_exists(masterpath + "/changes4")); 704 TEST(file_exists(masterpath + "/changes5")); 705 558 706 // Need to close the replica before we remove the temporary directory on 559 707 // Windows. 560 708 replica.close();