GithubHelp home page GithubHelp logo

wangtengchuan / lsm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from whuanle/lsm

0.0 0.0 0.0 53 KB

使用 Go 实现一个 LSM Tree 数据库

Home Page: https://www.cnblogs.com/whuanle/p/16297025.html

Go 100.00%

lsm's Introduction

使用方法

下载依赖包:

go get -u github.com/whuanle/lsm@v1.0.0

配置启动程序:

import (
"github.com/whuanle/lsm"
"github.com/whuanle/lsm/config"
)

	lsm.Start(config.Config{
		DataDir:    `E:\项目\lsm数据测试目录`,
		Level0Size: 10,
		PartSize:   4,
		Threshold:  1000,
		CheckInterval: 3, // 压缩时间间隔
	})
	

Level0Size:第 0 层的 SSTable 表总大小超过这样阈值时,进行文件合并;
PartSize:每层 SSTable 文件数量超过这个值,进行文件合并;
Threshold:内存表元素数量阈值,超过这个值,将会被压缩到 SSTable;
CheckInetrval:后台独立线程指向间隔时间,独立线程会检查内存表和所有层的 SSTable ,确定是否需要执行压缩;

完整增删查改代码如下:

package main

import (
	"fmt"
	"github.com/whuanle/lsm"
	"github.com/whuanle/lsm/config"
)

type TestValue struct {
	A int64
	B int64
	C int64
	D string
}

func main() {
	lsm.Start(config.Config{
		DataDir:    `E:\项目\lsm数据测试目录`,
		Level0Size: 1,
		PartSize:   4,
		Threshold:  500,
	})
	// 64 个字节
	testV := TestValue{
		A: 1,
		B: 1,
		C: 3,
		D: "00000000000000000000000000000000000000",
	}

	lsm.Set("aaa", testV)

	value, success := lsm.Get[TestValue]("aaa")
	if success {
		fmt.Println(value)
	}

	lsm.Delete("aaa")
}

lsm's People

Contributors

whuanle avatar simfg 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.