Git Product home page Git Product logo

Comments (3)

akiradeveloper avatar akiradeveloper commented on August 23, 2024

I think setting bytes to prost_build::Config will use Bytes as proto bytes.

I am ready. #134

from lolraft.

akiradeveloper avatar akiradeveloper commented on August 23, 2024

Here is a code-base explanation.

As of 0.6.3 (with prost 0.6), AppendStreamEntry has Vec<u8> payload

#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AppendStreamEntry {
    #[prost(uint64, tag = "1")]
    pub term: u64,
    #[prost(uint64, tag = "2")]
    pub index: u64,
    #[prost(bytes = "vec", tag = "3")]
    pub command: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AppendEntryReq {
    #[prost(oneof = "append_entry_req::Elem", tags = "1, 2")]
    pub elem: ::core::option::Option<append_entry_req::Elem>,
}

and

struct LogStreamElem {
    term: Term,
    index: Index,
    command: Bytes,
}

fn into_out_stream(
    x: LogStream
) -> impl futures::stream::Stream<Item = crate::proto_compiled::AppendEntryReq> {
    use crate::proto_compiled::{append_entry_req::Elem, AppendStreamHeader, AppendStreamEntry};
    let header_stream = vec![Elem::Header(AppendStreamHeader {
        sender_id: x.sender_id,
        prev_log_index: x.prev_log_index,
        prev_log_term: x.prev_log_term,
    })];
    let header_stream = futures::stream::iter(header_stream);
    let chunk_stream = x.entries.map(|e| {
        Elem::Entry(AppendStreamEntry {
            term: e.term,
            index: e.index,
            command: e.command.as_ref().into(), // HERE
        })
    });
    header_stream.chain(chunk_stream).map(|e| crate::proto_compiled::AppendEntryReq {
        elem: Some(e)
    })
}

LogStream which is the corresponding internal structure with Bytes payload is copied into the Vec<u8> payload.

If the external (inter-nodes) stream uses Bytes as the payload type, we will eliminate copies.

from lolraft.

akiradeveloper avatar akiradeveloper commented on August 23, 2024

done.

from lolraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.