项目作者: kezhuw

项目描述 :
Cache path sensitive hierarchical data storage system
高级语言: Go
项目地址: git://github.com/kezhuw/treedb.git
创建时间: 2016-03-31T15:13:18Z
项目社区:https://github.com/kezhuw/treedb

开源协议:MIT License

下载


TreeDB

TreeDB is a cache path sensitive hierarchical data store, used as NoSQL database.

TreeDB is in early stage of development, none parts should be considered as stable. Use it with your own caution!

Why another database ?

Database is a facility that provides both memory cache and disk storage, I concludes to this after
years development in game server scenarios. What hit me often is memory cache.

The primary reason to use memory cache is performance. Today, performance promotion benefits from
scenario insensitive cache used in disk oriented databases is far behind requirement. Memory cache
systems are adopted to alleviate database load. Hence boilerplates exists in many projects to handle
the similar situations: cache missings, cache loadings, cache consistence, and data writebacks.
Full memory databases, such as Redis, suffers from other problems: costs and capacities.

Things complicates things. The origin problem is that cache policy used by disk oriented databases
results in little performance promotion. Why not give some hits to cache facility? This leads me to
create TreeDB.

First look

Data stored in TreeDB are structed as hierachical tree structure. Data are accessed through path, similar
to the filesystem one. Here is the demonstration using treedb Go package.

  1. // Open database, if missing, clone it from database "template0".
  2. db, err := treedb.Open("tcp://:3456", "test", &treedb.Options{TemplateDB: "template0", CreateIfMissing: true})
  3. // Set cache pattern for all keys under tree "/game/users/".
  4. // You can set cache patterns in template database.
  5. db.Cache("/game/users/*", time.Minute * 30)
  6. // Match previous cache pattern, the path "/game/users/10023" will be cached in memory
  7. // as a whole for about 30 minutes.
  8. userData, err := db.Get("/game/users/10023", treedb.FieldTree)
  9. // No cache pattern matched, the path "/game/modules/arena" may not cached in memory based on other configs.
  10. db.Get("/game/modules/arena", treedb.FieldBinary)
  11. // Modify data.
  12. db.Set("/game/users/10023/items/20003", binaryData)
  13. db.Delete("/game/users/100034/items/20345")
  14. // Update path's last access timestamp if in memory.
  15. db.Touch("/game/users/10023")
  16. // Delete the whole path, whether it is binary or tree.
  17. db.Delete("/game/users/10023")
  18. // Create whole tree at path.
  19. var userData map[string]interface{}
  20. db.Set("/game/users/10234", userData)

Repository layout

The layout of this repository is divided to four parts:

  • Server daemon treedbd locates in cmd/treedbd directory.
  • Command line tool treedb locates in cmd/treedb directory.
  • Client-Server protocol locates in protocol directory, demonstrated as Go package.
  • Go package as client interface to server is located in the top directory.

TODO

  • Customized leveldb to collect orphan tree in merging time
  • Replication
    • Customized leveldb to store WAL for synchronization

License

The MIT License (MIT). See LICENSE for the full license text.

Contribution

Issues and pull requests are welcome.