attic-labs / noms

The versioned, forkable, syncable database
Apache License 2.0
7.45k stars 266 forks source link

NBS local stores are usable after close #3219

Open kalman opened 7 years ago

kalman commented 7 years ago

I wrote this test. Should it fail?

func TestUseAfterClose(t *testing.T) {
    assert := assert.New(t)

    dir, err := ioutil.TempDir("", "test")
    assert.NoError(err)
    defer os.RemoveAll(dir)

    cs := nbs.NewLocalStore(dir, 1<<28)
    db := datas.NewDatabase(cs)
    defer db.Close()
    ds := func() datas.Dataset {
        return db.GetDataset("ds")
    }

    // Can correctly commit and read when open.
    _, err = db.CommitValue(ds(), types.Number(1))
    assert.NoError(err)
    assert.True(types.Number(1).Equals(ds().HeadValue()))

    // Close...
    err = db.Close()
    assert.NoError(err)

    // It's closed, so shouldn't this fail?
    _, err = db.CommitValue(ds(), types.Number(2))
    assert.NoError(err)
    assert.True(types.Number(2).Equals(ds().HeadValue()))
}

CC @rafael-atticlabs

ghost commented 7 years ago

Probably

cmasone-attic commented 7 years ago

The question is where we should block this. At the NomsBlockStore layer, Database, or somewhere in between