Commit 83c43285 authored by jan.koester's avatar jan.koester
Browse files

test

parent 2cee9ddd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -70,6 +70,11 @@ public:
    // Retrieve with automatic size detection (reads 8-byte length header)
    std::vector<uint8_t> retrieve(uint64_t group_id);

    // Retrieve a byte range from stored data (fetches only needed stripes)
    // offset/length are in terms of the original data (before framing header)
    std::vector<uint8_t> retrieve_range(uint64_t group_id,
                                         uint64_t offset, uint64_t length);

    // Delete all blocks for a group from all nodes
    void remove(uint64_t group_id);

+36 −0
Original line number Diff line number Diff line
@@ -860,6 +860,42 @@ std::vector<uint8_t> client::retrieve(uint64_t group_id) {
    return std::vector<uint8_t>(result.begin() + 8, result.begin() + 8 + total_len);
}

std::vector<uint8_t> client::retrieve_range(uint64_t group_id,
                                              uint64_t offset, uint64_t length) {
    if (length == 0) return {};

    // The stored framed data is: [8-byte length header][raw data]
    // User offset 0 = byte 8 in framed stream.
    uint64_t framed_start = offset + 8;
    uint64_t framed_end = framed_start + length;

    // Compute which stripes we need
    uint32_t first_stripe = static_cast<uint32_t>(framed_start / STRIPE_SIZE);
    uint32_t last_stripe = static_cast<uint32_t>((framed_end - 1) / STRIPE_SIZE);

    // Fetch only the needed stripes
    std::vector<uint8_t> buf;
    buf.reserve(static_cast<size_t>((last_stripe - first_stripe + 1)) * STRIPE_SIZE);

    for (uint32_t s = first_stripe; s <= last_stripe; ++s) {
        std::vector<uint8_t> stripe;
        if (!retrieve_stripe(group_id, s, stripe)) {
            throw std::runtime_error("retrieve_range: stripe " + std::to_string(s) + " not found");
        }
        buf.insert(buf.end(), stripe.begin(), stripe.end());
    }

    // Slice out the requested range within fetched stripes
    uint64_t buf_offset = framed_start - static_cast<uint64_t>(first_stripe) * STRIPE_SIZE;
    if (buf_offset + length > buf.size()) {
        // Clamp to available data
        length = buf.size() > buf_offset ? buf.size() - buf_offset : 0;
    }
    if (length == 0) return {};
    return std::vector<uint8_t>(buf.begin() + static_cast<std::ptrdiff_t>(buf_offset),
                                 buf.begin() + static_cast<std::ptrdiff_t>(buf_offset + length));
}

void client::remove(uint64_t group_id) {
    std::vector<uint8_t> payload(8);
    protocol::encode_u64(payload.data(), group_id);