<commit_before>// Copyright 2010-2012 RethinkDB, all rights reserved.
#include "serializer/log/lba/disk_extent.hpp"

#include "arch/arch.hpp"

lba_disk_extent_t::lba_disk_extent_t(extent_manager_t *_em, file_t *file, file_account_t *io_account)
    : em(_em), data(new extent_t(em, file)), count(0) {
    em->assert_thread();

    // Make sure that the size of the header is a multiple of the size of one entry, so that the
    // header doesn't prevent the entries from aligning with DEVICE_BLOCK_SIZE.
    rassert(divides(sizeof(lba_entry_t), offsetof(lba_extent_t, entries[0])));
    CT_ASSERT(offsetof(lba_extent_t, entries[0]) == sizeof(lba_extent_t::header_t));

    lba_extent_t::header_t header;
    bzero(&header, sizeof(header));
    memcpy(header.magic, lba_magic, LBA_MAGIC_SIZE);
    data->append(&header, sizeof(header), io_account);
}

lba_disk_extent_t::lba_disk_extent_t(extent_manager_t *_em, file_t *file, int64_t _offset, int _count)
    : em(_em), data(new extent_t(em, file, _offset, offsetof(lba_extent_t, entries[0]) + sizeof(lba_entry_t) * _count)), count(_count) {
    em->assert_thread();
}


void lba_disk_extent_t::add_entry(lba_entry_t entry, file_account_t *io_account) {
    em->assert_thread();
    // Make sure that entries will align with DEVICE_BLOCK_SIZE

    // Make sure that there is room
    rassert(data->amount_filled + sizeof(lba_entry_t) <= em->extent_size);

    data->append(&entry, sizeof(lba_entry_t), io_account);
    count++;
}

void lba_disk_extent_t::sync(file_account_t *io_account, extent_t::sync_callback_t *cb) {
    em->assert_thread();
    while (data->amount_filled % DEVICE_BLOCK_SIZE != 0) {
        add_entry(lba_entry_t::make_padding_entry(), io_account);
    }

    data->sync(cb);
}

void lba_disk_extent_t::read_step_1(read_info_t *info_out, extent_t::read_callback_t *cb) {
    em->assert_thread();
    info_out->buffer = malloc_aligned(em->extent_size, DEVICE_BLOCK_SIZE);
    info_out->count = count;
    data->read(0, sizeof(lba_extent_t) + sizeof(lba_entry_t) * count, info_out->buffer, cb);
}

void lba_disk_extent_t::read_step_2(read_info_t *info, in_memory_index_t *index) {
    em->assert_thread();
    lba_extent_t *extent = reinterpret_cast<lba_extent_t *>(info->buffer);
    guarantee(memcmp(extent->header.magic, lba_magic, LBA_MAGIC_SIZE) == 0);

    for (int i = 0; i < info->count; i++) {
        lba_entry_t *e = &extent->entries[i];
        if (!lba_entry_t::is_padding(e)) {
            // RSI: Actually read the block size from the entry.
            index->set_block_info(e->block_id, e->recency, e->offset,
                                  em->default_ser_block_size);
        }
    }

    free(info->buffer);
}
<commit_msg>Made us actually read the block size from entry.<commit_after>// Copyright 2010-2012 RethinkDB, all rights reserved.
#include "serializer/log/lba/disk_extent.hpp"

#include "arch/arch.hpp"

lba_disk_extent_t::lba_disk_extent_t(extent_manager_t *_em, file_t *file, file_account_t *io_account)
    : em(_em), data(new extent_t(em, file)), count(0) {
    em->assert_thread();

    // Make sure that the size of the header is a multiple of the size of one entry, so that the
    // header doesn't prevent the entries from aligning with DEVICE_BLOCK_SIZE.
    rassert(divides(sizeof(lba_entry_t), offsetof(lba_extent_t, entries[0])));
    CT_ASSERT(offsetof(lba_extent_t, entries[0]) == sizeof(lba_extent_t::header_t));

    lba_extent_t::header_t header;
    bzero(&header, sizeof(header));
    memcpy(header.magic, lba_magic, LBA_MAGIC_SIZE);
    data->append(&header, sizeof(header), io_account);
}

lba_disk_extent_t::lba_disk_extent_t(extent_manager_t *_em, file_t *file, int64_t _offset, int _count)
    : em(_em), data(new extent_t(em, file, _offset, offsetof(lba_extent_t, entries[0]) + sizeof(lba_entry_t) * _count)), count(_count) {
    em->assert_thread();
}


void lba_disk_extent_t::add_entry(lba_entry_t entry, file_account_t *io_account) {
    em->assert_thread();
    // Make sure that entries will align with DEVICE_BLOCK_SIZE

    // Make sure that there is room
    rassert(data->amount_filled + sizeof(lba_entry_t) <= em->extent_size);

    data->append(&entry, sizeof(lba_entry_t), io_account);
    count++;
}

void lba_disk_extent_t::sync(file_account_t *io_account, extent_t::sync_callback_t *cb) {
    em->assert_thread();
    while (data->amount_filled % DEVICE_BLOCK_SIZE != 0) {
        add_entry(lba_entry_t::make_padding_entry(), io_account);
    }

    data->sync(cb);
}

void lba_disk_extent_t::read_step_1(read_info_t *info_out, extent_t::read_callback_t *cb) {
    em->assert_thread();
    info_out->buffer = malloc_aligned(em->extent_size, DEVICE_BLOCK_SIZE);
    info_out->count = count;
    data->read(0, sizeof(lba_extent_t) + sizeof(lba_entry_t) * count, info_out->buffer, cb);
}

void lba_disk_extent_t::read_step_2(read_info_t *info, in_memory_index_t *index) {
    em->assert_thread();
    lba_extent_t *extent = reinterpret_cast<lba_extent_t *>(info->buffer);
    guarantee(memcmp(extent->header.magic, lba_magic, LBA_MAGIC_SIZE) == 0);

    for (int i = 0; i < info->count; i++) {
        lba_entry_t *e = &extent->entries[i];
        if (!lba_entry_t::is_padding(e)) {
            index->set_block_info(e->block_id, e->recency, e->offset,
                                  e->ser_block_size);
        }
    }

    free(info->buffer);
}

{'fraction_non_alphanumeric': 0.13379105585451848, 'fraction_numerical': 0.007422527370569679, 'mean_word_length': 4.373878364905284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '234136', 'n_tokens_mistral': 2061, 'n_tokens_neox': 2007, 'n_words': 367}