GithubHelp home page GithubHelp logo

canaldb's Introduction

Canaldb Build Status

A deadly simple time series databese which uses Leveldb as a backend.

Idea & Motivation

Avoid storing a value which is duplicate of the most recent value

To save storage capacity.

e.g.

Timestamp Value Note
1473320409401 foo Store (original value)
1473320409402 foo Not store (duplicated)
1473320409403 bar Store (value chaneged)

Trimmable (truncatable) old value with according to timestamp

To truncate old data, to save storage capacity :)

e.g.

namespace and timestamp Value
ns_1473320409401 foo
ns_1473320409402 bar
ns_1473320409403 buz
ns_1473320409410 qux

Then execute Trim()

db.Trim("ns", int64(1473320409405)) // <= timestamp is between `buz` value and `qux` value

Result:

namespace and timestamp Value Note
ns_1473320409405 buz Truncate and put the latest value on boundary
ns_1473320409410 qux As it is

Example

import "github.com/syndtr/goleveldb/leveldb"

func main() {
	leveldb, _ := leveldb.OpenFile("db", nil)
	defer leveldb.Close()
	db := NewCanalDB(leveldb)

	entry1, _ := db.Put("namespace", "1")
	entry2, _ := db.Put("namespace", "2")
	entry3, _ := db.Put("namespace", "3")

	db.GetCurrent("namespace") // => namespace:3

	db.GetRange("namespace", entry1.Timestamp, entry3.Timestamp, -1, false) // => namespace:1, namespace:2, namespace:3
	db.GetRange("namespace", entry1.Timestamp, entry3.Timestamp, -1, true)  // => namespace:3, namespace:2, namespace:1
	db.GetRange("namespace", entry1.Timestamp, entry3.Timestamp, 1, false)  // => namespace:1
	db.GetRange("namespace", entry2.Timestamp, entry3.Timestamp, -1, false) // => namespace:2, namespace:3

	db.Trim("namespace", entry3.Timestamp) // => Trim db
	db.GetRange("namespace", entry1.Timestamp, entry3.Timestamp, -1, false) // => namespace:3
}

Author

moznion ([email protected])

License

MIT

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.