Ticket #326: small_doclen_chunks.patch

File small_doclen_chunks.patch, 4.8 KB (added by Richard Boulton, 15 years ago)

Patch to make doclen chunks smaller.

  • chert_postlist.h

     
    8181
    8282        Xapian::docid get_chunk(const string &tname,
    8383                Xapian::docid did, bool adding,
    84                 PostlistChunkReader ** from, PostlistChunkWriter **to);
     84                PostlistChunkReader ** from, PostlistChunkWriter **to,
     85                unsigned int chunksize);
    8586
    8687        /// Compose a key from a termname and docid.
    8788        static string make_key(const string & term, Xapian::docid did) {
  • chert_postlist.cc

     
    7676// maximise how well blocks are used.  Or performance.
    7777// Or indexing speed.  Or something...
    7878const unsigned int CHUNKSIZE = 2000;
     79const unsigned int DOCLEN_CHUNKSIZE = 70;
    7980
    8081/** PostlistChunkWriter is a wrapper which acts roughly as an
    8182 *  output iterator on a postlist chunk, taking care of the
     
    8889        PostlistChunkWriter(const string &orig_key_,
    8990                            bool is_first_chunk_,
    9091                            const string &tname_,
    91                             bool is_last_chunk_);
     92                            bool is_last_chunk_,
     93                            unsigned int chunksize_);
    9294
    9395        /// Append an entry to this chunk.
    9496        void append(ChertTable * table, Xapian::docid did,
     
    118120        bool is_first_chunk;
    119121        bool is_last_chunk;
    120122        bool started;
     123        unsigned int chunksize;
    121124
    122125        Xapian::docid first_did;
    123126        Xapian::docid current_did;
     
    302305PostlistChunkWriter::PostlistChunkWriter(const string &orig_key_,
    303306                                         bool is_first_chunk_,
    304307                                         const string &tname_,
    305                                          bool is_last_chunk_)
     308                                         bool is_last_chunk_,
     309                                         unsigned int chunksize_)
    306310        : orig_key(orig_key_),
    307311          tname(tname_), is_first_chunk(is_first_chunk_),
    308312          is_last_chunk(is_last_chunk_),
    309           started(false)
     313          started(false),
     314          chunksize(chunksize_)
    310315{
    311316    DEBUGCALL(DB, void, "PostlistChunkWriter::PostlistChunkWriter",
    312317              orig_key_ << ", " << is_first_chunk_ << ", " << tname_ << ", " <<
    313               is_last_chunk_);
     318              is_last_chunk_ << ", " << chunksize_);
    314319}
    315320
    316321void
     
    323328    } else {
    324329        Assert(did > current_did);
    325330        // Start a new chunk if this one has grown to the threshold.
    326         if (chunk.size() >= CHUNKSIZE) {
     331        if (chunk.size() >= chunksize) {
    327332            bool save_is_last_chunk = is_last_chunk;
    328333            is_last_chunk = false;
    329334            flush(table);
     
    961966Xapian::docid
    962967ChertPostListTable::get_chunk(const string &tname,
    963968          Xapian::docid did, bool adding,
    964           PostlistChunkReader ** from, PostlistChunkWriter **to)
     969          PostlistChunkReader ** from, PostlistChunkWriter **to,
     970          unsigned int chunksize)
    965971{
    966     DEBUGCALL(DB, Xapian::docid, "ChertPostListTable::get_chunk", tname << ", " << did << ", " << adding << ", [from], [to]");
     972    DEBUGCALL(DB, Xapian::docid, "ChertPostListTable::get_chunk", tname << ", " << did << ", " << adding << ", [from], [to], " << chunksize);
    967973    // Get chunk containing entry
    968974    string key = make_key(tname, did);
    969975
     
    982988            throw Xapian::DatabaseCorruptError("Attempted to delete or modify an entry in a non-existent posting list for " + tname);
    983989
    984990        *from = NULL;
    985         *to = new PostlistChunkWriter(string(), true, tname, true);
     991        *to = new PostlistChunkWriter(string(), true, tname, true, chunksize);
    986992        RETURN(Xapian::docid(-1));
    987993    }
    988994
     
    10071013    Xapian::docid last_did_in_chunk;
    10081014    last_did_in_chunk = read_start_of_chunk(&pos, end, first_did_in_chunk, &is_last_chunk);
    10091015    *to = new PostlistChunkWriter(cursor->current_key, is_first_chunk, tname,
    1010                                   is_last_chunk);
     1016                                  is_last_chunk, chunksize);
    10111017    if (did > last_did_in_chunk) {
    10121018        // This is the shortcut.  Not very pretty, but I'll leave refactoring
    10131019        // until I've a clearer picture of everything which needs to be done.
     
    10651071        Xapian::docid max_did;
    10661072        PostlistChunkReader *from;
    10671073        PostlistChunkWriter *to;
    1068         max_did = get_chunk(string(), j->first, true, &from, &to);
     1074        max_did = get_chunk(string(), j->first, true, &from, &to, DOCLEN_CHUNKSIZE);
    10691075        LOGVALUE(DB, max_did);
    10701076        for ( ; j != doclens.end(); ++j) {
    10711077            Xapian::docid did = j->first;
     
    10851091                delete from;
    10861092                to->flush(this);
    10871093                delete to;
    1088                 max_did = get_chunk(string(), did, false, &from, &to);
     1094                max_did = get_chunk(string(), did, false, &from, &to, DOCLEN_CHUNKSIZE);
    10891095                goto next_doclen_chunk;
    10901096            }
    10911097
     
    11801186        PostlistChunkReader *from;
    11811187        PostlistChunkWriter *to;
    11821188        max_did = get_chunk(tname, j->first, j->second.first == 'A',
    1183                             &from, &to);
     1189                            &from, &to, CHUNKSIZE);
    11841190        for ( ; j != i->second.end(); ++j) {
    11851191            Xapian::docid did = j->first;
    11861192
     
    12021208                delete from;
    12031209                to->flush(this);
    12041210                delete to;
    1205                 max_did = get_chunk(tname, did, false, &from, &to);
     1211                max_did = get_chunk(tname, did, false, &from, &to, CHUNKSIZE);
    12061212                goto next_chunk;
    12071213            }
    12081214