GithubHelp home page GithubHelp logo

a3y3 / pegasusdb Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 87 KB

Distributed and fault tolerant database

Go 100.00%
key-value key-value-database key-value-store pdos raft raft-consensus-algorithm

pegasusdb's Introduction

Hi there ๐Ÿ‘‹

My name is Soham Dongargaonkar and I'm a software engineer at Visa.

pegasusdb's People

Contributors

a3y3 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pegasusdb's Issues

Fix a bug that can deadlock a newly elected leader

When the old leader is partitioned off (or crashes), the newly elected leader can have values surfaced on applyCh - but this can cause a problem since no RPC is waiting to consume them (the old leader's RPC already did that).
Thus, every leader also needs to verify if someone is even expecting that value before going into a wait.

Use condition variables to provide strong linearizability

  • For each leader RPC (get/putappend), wait on cond.
  • When a value appears on applyCh, if server is leader (or maybe even if it isn't?), set kv.appliedIndex and kv.appliedId values, then broadcast.
  • When a thread awakens from wait, check if kv.appliedIndex is the same as the value returned from Start(). If it's the same, check kv.appliedid. If it's the same, all went well. Else if it's less, wait. else, something went wrong, and the command wasn't applied (and will never be applied), so we must retry.
  • Broadcast only when at least one thread is waiting (producer/consumer problem)

When a duplicate request is received, ignore it

Once each request is identified uniquely, the kv server needs to reject a request that it has seen already.
This can be done by a simple hashmap if we also track each clerk by a client_id:

  • for each clerk, store the last id it sent.
  • once a clerk sends a new id, we can safely delete the old id (since this implies the client saw the response for the previous request)
  • if the clerk sends the same request twice, we want to respond on THIS thread. So we can simply skip the insert, and go straight to waiting for this id to be posted on this index.
  • Nope - since the producer thread only sends a message ONE time, the old thread is the one that gets that message. Hence, we should store the result in the Request thread itself, so if the duplicate request is seen again, we just return the stored result directly.

Fix log entries from previous terms never being committed

If a leader replicates a non committed log entry from a previous term, it can't commit it until there is a newer log entry in the current term. However, a client that's waiting on that entry to be committed is never going to submit a new command (to ensure linearizability).

This can be fixed if a thread in the Clerk continuously sends an idempotent command (aka GET) to the leader. Doing this will ensure that there is always at least one entry in the current term in the current leader, which will force an entry (if any) from the previous term to be committed and sent back to the clerk.

Parallelize loop in updateLeader()

The loop in updateLeader() needs to be parallelized so that it's faster (and also because if it's not, the main thread could get hung up calling a crashed/partitioned leader)

When an old leader detects a new one, ask the Clerk to resend the req to the new leader

When partitions heal, the old leader will get a HB from the new leader and revert to the follower state. However, the old leader may still have RPC threads waiting for an entry to come on applyCh.
An easy solution for this would be to have the threads check if the server they're running on is still the leader once they awaken. If they find out they aren't, they can easily return an error to the clerk. However, for this, they should awaken in the first place - hence, all follower KV servers should still consumer.cond.Broadcast() in case they were a leader at some time and had RPC threads waiting.

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.