master
jdl 2022-07-26 14:01:52 +02:00
parent 6e8a6e491c
commit 3e6902cfcd
16 changed files with 4 additions and 27 deletions

View File

@ -4,12 +4,7 @@ An in-process, in-memory database for Go.
## TO DO
* [ ] wal: delete old entries
* [ ] wal: shipping_test: secondary too far behind
* [ ] wal: writer_test: call RecvWAL twice
* [ ] wal: writer_test double start / stop
* [ ] kvstore: tests
* [ ] wal: writer lock via flock?
## Structure

View File

@ -4,12 +4,10 @@ import (
"database/sql"
"fmt"
"net"
"os"
"sync"
"time"
"git.crumpington.com/private/mdb/wal"
"golang.org/x/sys/unix"
"git.crumpington.com/private/mdb/kvstore/wal"
_ "github.com/mattn/go-sqlite3"
)
@ -20,10 +18,9 @@ type KV struct {
dataPath string
walPath string
w *wal.Writer
f *wal.Follower
lock *os.File
db *sql.DB
w *wal.Writer
f *wal.Follower
db *sql.DB
stop chan struct{}
done sync.WaitGroup
@ -36,13 +33,6 @@ type KV struct {
}
func (kv *KV) init() {
// Acquire the lock.
lock, err := os.OpenFile(kv.lockPath, os.O_RDWR|os.O_CREATE, 0600)
must(err)
must(unix.Flock(int(lock.Fd()), unix.LOCK_EX))
kv.lock = lock
opts := `?_journal=WAL`
db, err := sql.Open("sqlite3", kv.dataPath+opts)
must(err)
@ -71,7 +61,6 @@ func (kv *KV) start() {
func NewPrimary(dir string) *KV {
kv := &KV{
primary: true,
lockPath: lockPath(dir),
dataPath: dataPath(dir),
walPath: walPath(dir),
}
@ -87,7 +76,6 @@ func NewSecondary(
) *KV {
kv := &KV{
primary: false,
lockPath: lockPath(dir),
dataPath: dataPath(dir),
walPath: walPath(dir),
}
@ -145,12 +133,10 @@ func (kv *KV) Close() {
kv.w.Close()
kv.f.Close()
kv.db.Close()
kv.lock.Close()
kv.w = nil
kv.f = nil
kv.db = nil
kv.lock = nil
}
func (kv *KV) Store(collection string, id uint64, data []byte) {

View File

@ -24,7 +24,3 @@ func dataPath(dir string) string {
func walPath(dir string) string {
return filepath.Join(dir, "wal")
}
func lockPath(dir string) string {
return filepath.Join(dir, "lock")
}