Skip to content

Commit

Permalink
make dbcheck support new doclen format
Browse files Browse the repository at this point in the history
write a simple test for the change in dbcheck
  • Loading branch information
ShangtongZhang committed Jun 18, 2014
1 parent fe4a2a4 commit b115803
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 18 deletions.
111 changes: 93 additions & 18 deletions xapian-core/backends/brass/brass_dbcheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,100 @@ check_brass_table(const char * tablename, string filename,
}
lastdid += did;
bool bad = false;


bool is_in_block = false;
unsigned len_info = 0;
unsigned bytes_info = 0;

while (true) {
Xapian::termcount doclen;
if (!unpack_uint(&pos, end, &doclen)) {
if (out)
*out << "Failed to unpack doclen" << endl;
++errors;
bad = true;
break;
}

Xapian::termcount doclen = 0;
if ( is_in_block && len_info )
{
did++;
len_info--;
if ( len_info == 0 )
{
is_in_block = false;
}
if( !unpack_uint_in_bytes( &pos, bytes_info, &doclen ) )
{
if (out)
*out << "Failed to unpack doclen" << endl;
++errors;
bad = true;
break;
}
}
else
{
Xapian::docid incre_did = 0;
if( !unpack_uint( &pos, end, &incre_did ) )
{
if (out)
*out << "Failed to unpack docid increase" << endl;
++errors;
bad = true;
break;
}
if ( incre_did != (Xapian::docid)-1 )
{
is_in_block = false;
did += incre_did;
if( !unpack_uint_in_bytes( &pos, bytes_info, &doclen ) )
{
if (out)
*out << "Failed to unpack doclen" << endl;
++errors;
bad = true;
break;
}
}
else
{
is_in_block = true;
if( !unpack_uint( &pos, end, &incre_did ) )
{
if (out)
*out << "Failed to unpack docid increase" << endl;
++errors;
bad = true;
break;
}
if( !unpack_uint_in_bytes( &pos, 2, &len_info ) )
{
if (out)
*out << "Failed to unpack length info of fixed width doclen chunk" << endl;
++errors;
bad = true;
break;
}
if( !unpack_uint_in_bytes( &pos, 1, &bytes_info ) )
{
if (out)
*out << "Failed to unpack bytes info of fixed width doclen chunk" << endl;
++errors;
bad = true;
break;
}
did += incre_did;
if( !unpack_uint_in_bytes( &pos, bytes_info, &doclen ) )
{
if (out)
*out << "Failed to unpack doclen" << endl;
++errors;
bad = true;
break;
}
len_info--;
if ( len_info == 0 )
{
is_in_block = false;
}
}

}

if (did > db_last_docid) {
if (out)
Expand Down Expand Up @@ -252,16 +337,6 @@ check_brass_table(const char * tablename, string filename,

if (pos == end) break;

Xapian::docid inc;
if (!unpack_uint(&pos, end, &inc)) {
if (out)
*out << "Failed to unpack docid increase" << endl;
++errors;
bad = true;
break;
}
++inc;
did += inc;
if (did > lastdid) {
if (out)
*out << "docid " << did << " > last docid "
Expand Down
27 changes: 27 additions & 0 deletions xapian-core/tests/api_wrdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,33 @@ DEFINE_TESTCASE(cursordelbug1, brass || chert) {
return Xapian::Database::check(db_path) == 0;
}

/*A test for brass_dbcheck.cc modified for fixed width brass doclen chunk.
*It just use the database for cursordelbug1*/
DEFINE_TESTCASE(fixedwidthdoclenchunk, brass )
{
static const int terms[] = { 219, 221, 222, 223, 224, 225, 226 };
static const int copies[] = { 74, 116, 199, 21, 45, 155, 189 };

Xapian::WritableDatabase db;
db = get_named_writable_database("cursordelbug1", string());

for (size_t i = 0; i < sizeof(terms) / sizeof(terms[0]); ++i) {
Xapian::Document doc;
doc.add_term("XC" + str(terms[i]));
doc.add_term("XTabc");
doc.add_term("XAdef");
doc.add_term("XRghi");
doc.add_term("XYabc");
size_t c = copies[i];
while (c--) db.add_document(doc);
}

db.commit();

const string & db_path = get_named_writable_database_path("cursordelbug1");
return Xapian::Database::check(db_path) == 0;
}

/** Helper function for modifyvalues1.
*
* Check that the values stored in the database match */
Expand Down

0 comments on commit b115803

Please sign in to comment.