GithubHelp home page GithubHelp logo

thoainguyen / key-value-store Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 1.84 MB

Key value Database using B Tree

C 98.43% CMake 1.03% Makefile 0.32% Shell 0.22%
b-tree select threadpool nonblocking database reader-writer fsync key-value-store

key-value-store's Introduction

Key Value Store

Key value store sử dụng btree làm cấu trúc dữ liệu cho database engine, xử lý bài toán reader/writer, xây dựng non-blocking I/O server, dùng thread pool, message queue,..

Xây dựng kiến thức

Ghi chú: linux system, networking

Hướng dẫn cài đặt

B0. Theo hướng dẫn kvstore/README.md để chạy thành công

  • Cấu trúc project:
.
├── client
│   ├── client.c
│   └── CMakeLists.txt
├── include
│   ├── bnode.h
│   ├── btree.h
│   ├── kvstore.h
│   ├── kvpair.h
│   ├── server.h
│   ├── thpool.h
│   └── utils.h
├── server
│   ├── CMakeLists.txt
│   └── server.c
└── src
    ├── bnode.c
    ├── btree.c
    ├── kvstore.c
    └── thpool.c
  • btree.h: định nghĩa cấu trúc btree.
  • btree.c : các hàm hiện thực btree.
  • bnode.h : định nghĩa cấu trúc bnode.
  • utils.h : các hàm đọc ghi bnode xuống file, và đọc ghi meta data để build tree.
  • kvpair.h : định nghĩa struct key value.
  • server.c : hiện thực server, socket nonblocking, giao tiếp với btree.
  • client.c : hiện thực client, cung cấp kvstore-cli và autotest.
  • thpool.c : hiện thực threadpool, message queue.
  • kvstore.h : cung cấp interface giao tiếp với kvstore.
  • kvstore.c : hiện thực kết nối server, process các method insert, search, delete.

Dùng kvstore đối với mã nguồn bên thứ ba:

  • B1: Đầu tiên, chạy chương trình kvstore phía server như ở trên, để cung cấp kvstore service.
    • Có hai option -c-l:
      • Dùng -c khi muốn tạo mới dữ liệu
      • Dùng -l khi muốn chạy kvstore trên dữ liệu cũ
kvstore/server/sbuild $ ./server
using `./server -c` for create new or `./server -l` for load%
  • B2: copy hai file kvstore.h, và kvstore.c vào project bên thứ ba.

  • B3: Các API hỗ trợ:

/* giá trị db dùng để truyền vào các method sau này, HOST, PORT là hostname và port của dbserver, nếu db < 0, thì có lỗi xảy ra*/
int db = connect_kvstore(HOST, PORT);
/*hàm này set giá trị key-value trong kvstore, nếu key đã tồn tại thì giá trị được ghi đè, hàm trả về "OK"*/
char *result = kvstore_set(db, key, value);
/* trong đó key (char*) là khóa, value là giá trị trả về, trả về NULL nếu lỗi xảy ra.*/
char *value = kvstore_get(db, key);
/*hàm này xóa cặp key-value trong kvstore, trả về "OK" nếu thành công và "not exist!" nếu key không tồn tại*/
char *result = kvstore_delete(db, key);
/*hàm này dùng để đóng kết nối kvstore*/
void close_kvstore(db);

key-value-store's People

Contributors

thoainguyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hoathienvu8x

key-value-store's Issues

lack connect func, bad documentation, b tree disk base lost data,..

Here are some issue we can resolve

  • Lack connect database utils function, to import from other service
  • B tree implementation has some point is incorrect, lost a little data when reload
  • Documentation is bad, need rewrite
  • Client, server console is bad, can't handle error entry input before processing
  • Performance isn't good, because btree node only exist in disk, not cache in mem, we can combine pointer to child node in mem beside save it to disk after read it
  • Lack benmark for database

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.