Git Product home page Git Product logo

Comments (2)

akiradeveloper avatar akiradeveloper commented on August 23, 2024

My initial consideration as to this problem is to solve by TTL map (moka can be used).

Let's consider a request (request_id=K) that will yield a response B. Then it should work like this.

  1. Initially, there is no entry in the map.
  2. When the app sees the request first time, it stores (K, B, ttl=T1) in the map.
  3. When the app sees the completion for command with request_id=K, it completes to client and then append CompleteRequest entry. Now the entry is (K, empty, ttl=T2)
  4. When app sees a request with request_id=K, it ignores execution because they is an entry for K. Since there is a trace of K has been completed, then drop the completion if exists.
  5. When the entry reaches (K, empty, ttl=0), it will be evicted from the map.

from lolraft.

akiradeveloper avatar akiradeveloper commented on August 23, 2024

Done.

pub struct ResponseCache {
    responses: spin::Mutex<HashMap<String, Bytes>>,
    completes: TTLSet,
}

ResponseCache keeps the binding of request_id and the response data and request_id for only 5 seconds after completion to the client.

Let's consider this log with 3 entries.

[Exec][Exec (completion)][Exec]

This could happen in this scenario:

  1. Send 1st to node A
  2. node A down
  3. Send 2nd to the node B
  4. Retry 3rd to the node B

In this case, the request is executed at 1st and complete at 2nd but 3rd does nothing because responses still has the binding.

After 2nd, new entry [Complete] is queued and replicated. In executing this entry, the node moves the binding to responses to completes to prevent further execution of the requests in same request_id.

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.