Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module wildcat_c

go 1.25

require github.com/wildcatdb/wildcat/v2 v2.4.1
require github.com/wildcatdb/wildcat/v2 v2.4.2

require (
go.mongodb.org/mongo-driver v1.17.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions c/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/wildcatdb/wildcat/v2 v2.4.1 h1:jYx8jtRuj1/BbVta3VayRneU9wdft4EWZLv1mDJaNMg=
github.com/wildcatdb/wildcat/v2 v2.4.1/go.mod h1:MhT0iAaj4C6cpzKvSA/Pmm5M59jFuSxDi+E0vixOXM4=
github.com/wildcatdb/wildcat/v2 v2.4.2 h1:qTWgX81/b/C7VjCAaR+cViceHJmuYnBffZ6KNP1RYU4=
github.com/wildcatdb/wildcat/v2 v2.4.2/go.mod h1:MN8GlHCJjYD8SQvNC6iEreIpkqT22CN3PfCEjYUrqA4=
go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeHxQ=
go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
Expand Down
10 changes: 5 additions & 5 deletions flusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func newFlusher(db *DB) *Flusher {

// queueMemtable queues the current active memtable for flushing to disk.
func (flusher *Flusher) queueMemtable() error {
currentMemtable := flusher.db.memtable.Load().(*Memtable)

if atomic.LoadInt64(&flusher.lastQueuedId) == flusher.db.memtable.Load().(*Memtable).id {
if atomic.LoadInt64(&flusher.lastQueuedId) == currentMemtable.id {
return nil // Already queued
}

Expand All @@ -54,17 +55,16 @@ func (flusher *Flusher) queueMemtable() error {

// Add the new WAL to the LRU cache
flusher.db.lru.Put(newMemtable.wal.path, walBm, func(key string, value interface{}) {

// Close the block manager when evicted from LRU
if bm, ok := value.(*blockmanager.BlockManager); ok {
_ = bm.Close()
}
})

lastMemt := flusher.db.memtable.Load().(*Memtable)

// Push the current memtable to the immutable queue
flusher.immutable.Enqueue(lastMemt)
atomic.StoreInt64(&flusher.lastQueuedId, lastMemt.id)
flusher.immutable.Enqueue(currentMemtable)
atomic.StoreInt64(&flusher.lastQueuedId, currentMemtable.id)

flusher.db.log(fmt.Sprintf("Flusher: new active memtable created with WAL %s", newMemtable.wal.path))

Expand Down
22 changes: 5 additions & 17 deletions sstable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestSSTable_ConcurrentAccess(t *testing.T) {
}
}

forceManyWrites(t, db, 100)
testForceManyWrites(t, db, 100)
time.Sleep(500 * time.Millisecond) // Allow background flush to complete

// Number of concurrent readers and operations per reader
Expand Down Expand Up @@ -297,9 +297,10 @@ func TestSSTable_ConcurrentAccess(t *testing.T) {
}
}

// Helper function to force a flush to SSTable by writing many keys
func forceManyWrites(t *testing.T, db *DB, count int) {
// Write enough data to trigger memtable flush
// forceManyWrites Helper function to force a flush to SSTable by writing many keys
func testForceManyWrites(t *testing.T, db *DB, count int) {

// Write enough data to trigger memtable flush(es) for testing
for i := 0; i < count; i++ {
key := fmt.Sprintf("flush_key%d", i)
value := fmt.Sprintf("flush_value%d", i)
Expand All @@ -313,19 +314,6 @@ func forceManyWrites(t *testing.T, db *DB, count int) {
}
}

// Helper function to check if a byte slice starts with a prefix
func startsWith(data, prefix []byte) bool {
if len(data) < len(prefix) {
return false
}
for i := 0; i < len(prefix); i++ {
if data[i] != prefix[i] {
return false
}
}
return true
}

func TestSSTable_MVCCWithMultipleVersions(t *testing.T) {
dir, err := os.MkdirTemp("", "db_sstable_mvcc_multiple_versions_test")
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
func extractIDFromFilename(filename string) int64 {
parts := strings.Split(filename, ".")

// WAL file names in wildcat are <id>.<ext>
if len(parts) != 2 {
return 0
}
Expand All @@ -21,3 +20,16 @@ func extractIDFromFilename(filename string) int64 {

return ts
}

// startsWith Helper function to check if a byte slice starts with a prefix
func startsWith(data, prefix []byte) bool {
if len(data) < len(prefix) {
return false
}
for i := 0; i < len(prefix); i++ {
if data[i] != prefix[i] {
return false
}
}
return true
}