MCPcopy Index your code
hub / github.com/aneshas/gocask

github.com/aneshas/gocask @v0.0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.5 ↗ · + Follow
325 symbols 1,004 edges 24 files 108 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GoCask

Go Test Coverage Status Go Report Card Go Reference

Go implementation of Bitcask - A Log-Structured Hash Table for Fast Key / Value Data as defined per this paper and with help from this repo.

A learning venture into database development. Special thanks go to the amazing Ben Johnson for pointing me in the right direction and being as helpful as he was.

Features (as defined by the paper+)

  • Low latency per item read or written
  • High throughput, especially when writing an incoming stream of random items
  • Ability to handle datasets much larger than RAM w/o degradation
  • Crash friendliness, both in terms of fast recovery and not losing data
  • Ease of backup and restore
  • A relatively simple, understandable (and thus supportable) code structure and data format
  • Predictable behavior under heavy access load or large volume
  • Data files are rotated based on the user defined data file size (2GB default)
  • A license that allowed for easy use
  • Data corruption crc check

Important notes

  • GoCask does not implement any buffer cache in-memory. Instead, it depends on the filesystem’s cache. Adjusting the caching characteristics of your filesystem can impact performance.
  • GoCask stores all keys in memory which means that your system needs to have enough RAM to store all of your keyspace

How to Use/Run

There are two ways to use gocask

Using gocask as a library (embedded db) in your own app

GoCask can be used similarly to bolt or badger as an embedded db.

go get github.com/aneshas/gocask/cmd/gocask and use the api. See the docs

Running as a standalone process

If you have go installed: - go install github.com/aneshas/gocask/cmd/gocask@latest - go install github.com/aneshas/gocask/cmd/gccli@latest

Run db server

Then run gocask which will run the db engine itself, open default db and start grpc (twirp) server on localhost:8888 (Run gocask -help to see config options and the defaults)

Interact with server via cli

While the server is running you can interact with it via gccli binary: - gccli keys - list stored keys - gccli put somekey someval - stores the key value pair - gccli get somekey - retrieves the value stored under the key - gccli del somekey - deletes the value stored under the key

gccli is just meant as a simple probing tool, and you can generate your own client you can use the .proto definition included (or use the pre generated go client.

If you don't have go installed, you can go to releases download latest release and go through the same process as above.

Still to come

Since the primary motivation for this repo was learning more about how db engines work and although it could already be used, it's far from production ready. With that being said, I do plan to maintain and extend it in the future.

Some things that are on my mind: - Support for multiple processes and write locking - Current key deletion is a soft delete (implement merging and hint files) - Fold over keys - Double down on tests (fuzz?) - Add benchmarks - Make it distributed - An eventstore spin off (use gocask instead of sqlite)

Extension points exported contracts — how you extend this code

File (Interface)
File represents a single fs data file [5 implementers]
pkg/cask/db.go
GoCask (Interface)
================ GoCask Interface ================ [4 implementers]
rpc/gocask.twirp.go
Option (FuncType)
Option represents gocask configuration option
db.go
FS (Interface)
FS represents a file system interface [4 implementers]
pkg/cask/db.go
TwirpServer (Interface)
TwirpServer is the interface generated server structs will support: they're HTTP handlers with additional methods for ac [1 …
rpc/gocask.twirp.go
Time (Interface)
Time represents time provider [2 implementers]
pkg/cask/db.go
HTTPClient (Interface)
===== Utils ===== HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/
rpc/gocask.twirp.go

Core symbols most depended-on inside this repo

writeError
called by 48
rpc/gocask.twirp.go
Get
called by 40
rpc/gocask.twirp.go
wrapInternal
called by 26
rpc/gocask.twirp.go
NewDB
called by 22
pkg/cask/db.go
Error
called by 20
rpc/gocask.twirp.go
Put
called by 16
pkg/cask/db.go
Get
called by 14
pkg/cask/db.go
Name
called by 12
pkg/cask/db.go

Shape

Method 179
Function 103
Struct 32
Interface 9
FuncType 1
TypeAlias 1

Languages

Go100%

Modules by API surface

rpc/gocask.twirp.go93 symbols
rpc/gocask.pb.go47 symbols
pkg/cask/db_test.go26 symbols
pkg/cask/db.go24 symbols
pkg/cask/testutil/fs.go19 symbols
pkg/cask/testutil/memory.go13 symbols
internal/fs/memory.go12 symbols
internal/fs/disk.go12 symbols
pkg/cask/testutil/mocks/file.go9 symbols
pkg/cask/keydir.go9 symbols
db_test.go9 symbols
pkg/cask/testutil/mocks/fs.go8 symbols

For agents

$ claude mcp add gocask \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page