Giter VIP home page Giter VIP logo

bitcask-go's Introduction

实现bitcask

大体思路

MemTable(内存表)

  • Put(插入):插入数据
  • Get(查询):查询数据
  • Delete(删除):删除数据(为了简化删除操作,将 value 设为 nil 标记删除)

Wal(预写日志)

  • Writer(写入器)
    • Encode:对数据进行编码(格式为 crc+keySize+valueSize+key+value),并返回对应的 pos 信息(包括 file idoffsetlength
  • Reader(读取器)
    • Db Open 时:读取数据,根据 pos 信息进行直接读取

Db(数据库)

  • Put(插入)
    • 通过 wal 写入数据,得到 pos
    • 使用 memtable 存储 keypos 的映射关系
  • Delete(删除)
    • value 设为 nil,通过 wal 写入数据
    • memtable 中的 key 进行删除
  • Get(查询)
    • 通过 memtable 读取数据,不存在则根据 pos 信息读取
  • Open(打开)
    • 读取 Options 中的 dirPath 路径
    • 对于文件使用 Read 读取
  • CloseAndMerge(关闭和合并)
    • Merge(合并)
      • 重新写入到新的数据文件中
      • 删除旧的数据文件
    • Close(关闭)
      • 关闭打开的数据项
      • 关闭 MemTable 中的信息

实现了单线程服务器版本(仅供学习使用)

后续可能会完善吧

思维导图

思维导图

bitcask-go's People

Contributors

xia-sang avatar

Watchers

 avatar

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.