Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Set Uninitialized #19

Merged
merged 3 commits into from
Aug 21, 2021
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 column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ func TestForString(t *testing.T) {
})

data := []string{"a", "b", "c", "d"}

for i, d := range data {
coll.Insert(map[string]interface{}{"id": i, "data": d})
}

coll.Query(func(tx *Txn) error {
tx.With("one").Select(func(v Selector) {
assert.Equal(t, "b", v.StringAt("data"))
Expand Down
5 changes: 5 additions & 0 deletions txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ func (txn *Txn) commit() {
})
}

// Set upper bound to max(inserts, fill)
if m := uint32(len(txn.index) << 6); m > max {
max = m
}

// Commit chunk by chunk to reduce lock contentions
var typ commit.Type
txn.rangeWrite(func(chunk uint32, fill bitmap.Bitmap) {
Expand Down
33 changes: 33 additions & 0 deletions txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,36 @@ func TestCountTwice(t *testing.T) {
return nil
})
}

// Details: https://github.com/kelindar/column/issues/15
func TestUninitializedSet(t *testing.T) {
c := NewCollection()
c.CreateColumn("col1", ForString())
c.CreateColumn("col2", ForFloat64())
c.CreateColumn("col3", ForString())
someMap := map[string][]interface{}{
"1": {"A", 1.0},
"2": {"B", 2.0},
}

assert.NoError(t, c.Query(func(txn *Txn) error {
for i := 0; i < 20000; i++ {
txn.Insert(map[string]interface{}{
"col1": fmt.Sprint(i % 3),
})
}
return nil
}))

assert.NoError(t, c.Query(func(txn *Txn) error {
assert.NoError(t, txn.Range("col2", func(v Cursor) {
v.SetFloat64(0)
}))
return txn.Range("col1", func(v Cursor) {
if a, h := someMap[v.String()]; h {
v.SetFloat64At("col2", a[1].(float64))
v.SetStringAt("col3", a[0].(string))
}
})
}))
}