diff --git a/database.go b/database.go index a1c7243..c59f12a 100644 --- a/database.go +++ b/database.go @@ -62,18 +62,23 @@ func (db *Database) Start() { } func (db *Database) WALStatus() (ws WALStatus) { - ws.MaxID = db.kv.WALMaxSeqNum() - ws.MaxAppliedID = db.kv.MaxSeqNum() + ws.MaxSeqNumKV = db.kv.WALMaxSeqNum() + ws.MaxSeqNumWAL = db.kv.MaxSeqNum() return } func (db *Database) Close() { - db.kv.Close() - db.lock.Close() + if db.kv != nil { + db.kv.Close() + db.kv = nil + } + if db.lock != nil { + db.lock.Close() + db.lock = nil + } } -// ----------------- - db.kv = kvstore.NewSecondary(root)----------------------------------------------------------- +// ---------------------------------------------------------------------------- func (db *Database) onStore(collection string, id uint64, data []byte) { c, ok := db.collections[collection] diff --git a/database_test.go b/database_test.go index 6c8376d..5a828bc 100644 --- a/database_test.go +++ b/database_test.go @@ -5,7 +5,7 @@ import "time" func (db *Database) waitForWAL() { for { status := db.WALStatus() - if status.MaxAppliedID == status.MaxID { + if status.MaxSeqNumWAL == status.MaxSeqNumKV { return } time.Sleep(100 * time.Millisecond) diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..0002bea --- /dev/null +++ b/main_test.go @@ -0,0 +1,13 @@ +package mdb + +import ( + "math/rand" + "os" + "testing" + "time" +) + +func TestMain(m *testing.M) { + rand.Seed(time.Now().UnixNano()) + os.Exit(m.Run()) +} diff --git a/types.go b/types.go index 3600684..9baa3eb 100644 --- a/types.go +++ b/types.go @@ -1,8 +1,8 @@ package mdb type WALStatus struct { - MaxID uint64 // TODO: WALMaxSeqNum - MaxAppliedID uint64 // TODO: KVMaxSeqNum + MaxSeqNumKV uint64 + MaxSeqNumWAL uint64 } type itemIndex[T any] interface {