Exemplo n.º 1
0
bool InnerNode::load_all_msgbuf(BlockReader& reader)
{
    Slice buffer;
    if (tree_->compressor_) {
        size_t buffer_length = first_msgbuf_uncompressed_length_;
        for (size_t i = 0; i < pivots_.size(); i++) {
            if (buffer_length < pivots_[i].uncompressed_length) {
                buffer_length = pivots_[i].uncompressed_length;
            }
        }

        buffer = Slice::alloc(buffer_length);
    }

    if (first_msgbuf_ == NULL) {
        reader.seek(first_msgbuf_offset_);
        first_msgbuf_ = new MsgBuf(tree_->options_.comparator);
        if (!read_msgbuf(reader, first_msgbuf_length_,
                         first_msgbuf_uncompressed_length_, 
                         first_msgbuf_, buffer)) {
            if (buffer.size()) {
                buffer.destroy();
            }
            return false;
        }
        msgcnt_ += first_msgbuf_->count();
        msgbufsz_ += first_msgbuf_->size();
    }

    for (size_t i = 0; i < pivots_.size(); i++) {
        if (pivots_[i].msgbuf == NULL) {
            reader.seek(pivots_[i].offset);
            pivots_[i].msgbuf = new MsgBuf(tree_->options_.comparator);
            if (!read_msgbuf(reader, pivots_[i].length,
                             pivots_[i].uncompressed_length,
                             pivots_[i].msgbuf, buffer)) {
                if (buffer.size()) {
                    buffer.destroy();
                }
                return false;
            }
            msgcnt_ += pivots_[i].msgbuf->count();
            msgbufsz_ += pivots_[i].msgbuf->size();
        }
    }

    if (buffer.size()) {
        buffer.destroy();
    }

    status_ = kFullLoaded;
    return true;
}
Exemplo n.º 2
0
bool LeafNode::load_all_buckets(BlockReader& reader)
{
    Slice buffer;
    if (tree_->compressor_) {
        size_t buffer_length = 0;
        for (size_t i = 0; i < buckets_info_.size(); i++ ) {
            if (buffer_length < buckets_info_[i].uncompressed_length) {
                buffer_length = buckets_info_[i].uncompressed_length;
            }
        }
        buffer = Slice::alloc(buffer_length);
    }

    bool ret = true;
    for (size_t i = 0; i < buckets_info_.size(); i++) {
        reader.seek(buckets_info_[i].offset);

        RecordBucket *bucket = new RecordBucket();
        if (bucket == NULL) {
            ret = false;
            break;
        }

        if (!read_bucket(reader, buckets_info_[i].length, 
                         buckets_info_[i].uncompressed_length,
                         bucket, buffer)) {
            ret = false;
            delete bucket;
            break;
        }

        records_.set_bucket(i, bucket);
    }

    if (buffer.size()) {
        buffer.destroy();
    }

    status_ = kFullLoaded;
    return ret;
}