Skip to content

Commit

Permalink
fix Update bug from lm2log (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetam authored Jun 28, 2017
1 parent beec538 commit 6127274
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ func (c *Collection) Update(wb *WriteBatch) (int64, error) {
atomic.StoreUint32(&c.internalState, 1)
return 0, err
}
if rec.Key != key {
continue
}
rec.lock.Lock()
rec.Deleted = currentOffset
rec.lock.Unlock()
Expand Down
45 changes: 45 additions & 0 deletions lm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,3 +748,48 @@ func TestSimple(t *testing.T) {
}
t.Logf("%+v", c.Stats())
}

func TestLm2Log(t *testing.T) {
expected := [][2]string{
{"committed", "0"},
}

c, err := NewCollection("/tmp/test_lm2log.lm2", 100)
if err != nil {
t.Fatal(err)
}
defer c.Destroy()

wb := NewWriteBatch()
wb.Set("committed", "0")
wb.Delete("prepared")
_, err = c.Update(wb)
if err != nil {
t.Fatal(err)
}

verifyOrder(t, c)

cur, err := c.NewCursor()
if err != nil {
t.Fatal(err)
}

i := 0
for cur.Next() {
if i == len(expected) {
t.Fatal("unexpected key", cur.Key())
}
if cur.Key() != expected[i][0] || cur.Value() != expected[i][1] {
t.Errorf("expected %v => %v, got %v => %v",
expected[i][0], expected[i][1], cur.Key(), cur.Value())
} else {
t.Logf("got %v => %v", cur.Key(), cur.Value())
}
i++
}
if err = cur.Err(); err != nil {
t.Fatal(err)
}
t.Logf("%+v", c.Stats())
}

0 comments on commit 6127274

Please sign in to comment.