Commit 4cc99c49 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6436e1dc
...@@ -276,7 +276,7 @@ func (obj *Persistent) PDeactivate() { ...@@ -276,7 +276,7 @@ func (obj *Persistent) PDeactivate() {
return return
} }
// TODO cp & PCacheNonTemporal -> drop unconditionally; otherwise -> LRU // TODO cp & PCacheDropState | PCacheDropObject -> drop unconditionally; otherwise -> LRU
obj.serial = InvalidTid obj.serial = InvalidTid
obj.istate().DropState() obj.istate().DropState()
......
...@@ -727,16 +727,20 @@ func TestLiveCache(t0 *testing.T) { ...@@ -727,16 +727,20 @@ func TestLiveCache(t0 *testing.T) {
tdb.Add(101, "мир") tdb.Add(101, "мир")
tdb.Add(102, "труд") tdb.Add(102, "труд")
tdb.Add(103, "май") tdb.Add(103, "май")
tdb.Add(104, "весна")
tdb.Commit() tdb.Commit()
at1 := tdb.head at1 := tdb.head
zcc := &zcacheControl{map[Oid]PCachePolicy{ zcc := &zcacheControl{map[Oid]PCachePolicy{
// obj1 - don't pin and don't keep state (default) // obj1 - default (currently: don't pin and don't keep state)
// TODO: it should go into LRU on release, not dropped
101: 0, 101: 0,
// obj2 - pin and keep state // objPK - pin and keep state
102: PCachePinObject | PCacheKeepState, 102: PCachePinObject | PCacheKeepState,
// obj3 - pin, but don't keep state // objPD - pin, but don't keep state
103: PCachePinObject | PCacheNonTemporal, 103: PCachePinObject | PCacheDropState,
// objDD - drop object and state
104: PCacheDropObject | PCacheDropState,
}} }}
t := tdb.Open(&ConnOptions{}) t := tdb.Open(&ConnOptions{})
...@@ -746,58 +750,72 @@ func TestLiveCache(t0 *testing.T) { ...@@ -746,58 +750,72 @@ func TestLiveCache(t0 *testing.T) {
zcache.Unlock() zcache.Unlock()
// get objects // get objects
obj1 := t.Get(101) obj := t.Get(101)
obj2 := t.Get(102) objPK := t.Get(102)
obj3 := t.Get(103) objPD := t.Get(103)
t.checkObj(obj1, 101, InvalidTid, GHOST, 0) objDD := t.Get(104)
t.checkObj(obj2, 102, InvalidTid, GHOST, 0) t.checkObj(obj, 101, InvalidTid, GHOST, 0)
t.checkObj(obj3, 103, InvalidTid, GHOST, 0) t.checkObj(objPK, 102, InvalidTid, GHOST, 0)
t.checkObj(objPD, 103, InvalidTid, GHOST, 0)
t.checkObj(objDD, 104, InvalidTid, GHOST, 0)
// activate * -> uptodate // activate * -> uptodate
t.PActivate(obj1) t.PActivate(obj)
t.PActivate(obj2) t.PActivate(objPK)
t.PActivate(obj3) t.PActivate(objPD)
t.checkObj(obj1, 101, at1, UPTODATE, 1, "мир") t.PActivate(objDD)
t.checkObj(obj2, 102, at1, UPTODATE, 1, "труд") t.checkObj(obj, 101, at1, UPTODATE, 1, "мир")
t.checkObj(obj3, 103, at1, UPTODATE, 1, "май") t.checkObj(objPK, 102, at1, UPTODATE, 1, "труд")
t.checkObj(objPD, 103, at1, UPTODATE, 1, "май")
// deactivate obj{1,3} drop state, obj2 is kept t.checkObj(objDD, 104, at1, UPTODATE, 1, "весна")
obj1.PDeactivate()
obj2.PDeactivate() // deactivate obj{,PD,DD} drop state, objPK is kept
obj3.PDeactivate() obj.PDeactivate()
t.checkObj(obj1, 101, InvalidTid, GHOST, 0) objPK.PDeactivate()
t.checkObj(obj2, 102, at1, UPTODATE, 0, "труд") objPD.PDeactivate()
t.checkObj(obj3, 103, InvalidTid, GHOST, 0) objDD.PDeactivate()
t.checkObj(obj, 101, InvalidTid, GHOST, 0)
t.checkObj(objPK, 102, at1, UPTODATE, 0, "труд")
t.checkObj(objPD, 103, InvalidTid, GHOST, 0)
t.checkObj(objDD, 104, InvalidTid, GHOST, 0)
// live cache should keep pinned object live even if we drop all // live cache should keep pinned object live even if we drop all
// regular pointers to it and do GC. // regular pointers to it and do GC.
obj1._v_cookie = "peace" obj._v_cookie = "peace"
obj2._v_cookie = "labour" objPK._v_cookie = "labour"
obj3._v_cookie = "may" objPD._v_cookie = "may"
obj1 = nil objDD._v_cookie = "spring"
obj2 = nil obj = nil
obj3 = nil objPK = nil
objPD = nil
objDD = nil
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
runtime.GC() // need only 2 runs since cache uses finalizers runtime.GC() // need only 2 runs since cache uses finalizers
} }
xobj1 := zcache.Get(101) xobj := zcache.Get(101)
xobj2 := zcache.Get(102) xobjPK := zcache.Get(102)
xobj3 := zcache.Get(103) xobjPD := zcache.Get(103)
assert.Equal(xobj1, nil) xobjDD := zcache.Get(104)
assert.NotEqual(xobj2, nil) assert.Equal(xobj, nil)
assert.NotEqual(xobj3, nil) assert.NotEqual(xobjPK, nil)
obj2 = xobj2.(*MyObject) assert.NotEqual(xobjPD, nil)
obj3 = xobj3.(*MyObject) assert.Equal(xobjDD, nil)
t.checkObj(obj2, 102, at1, UPTODATE, 0, "труд") objPK = xobjPK.(*MyObject)
t.checkObj(obj3, 103, InvalidTid, GHOST, 0) objPD = xobjPD.(*MyObject)
t.checkObj(objPK, 102, at1, UPTODATE, 0, "труд")
assert.Equal(obj2._v_cookie, "labour") t.checkObj(objPD, 103, InvalidTid, GHOST, 0)
assert.Equal(obj3._v_cookie, "may")
assert.Equal(objPK._v_cookie, "labour")
obj1 = t.Get(101) assert.Equal(objPD._v_cookie, "may")
t.checkObj(obj1, 101, InvalidTid, GHOST, 0)
assert.Equal(obj1._v_cookie, "") obj = t.Get(101)
objDD = t.Get(104)
t.checkObj(obj, 101, InvalidTid, GHOST, 0)
t.checkObj(objDD, 104, InvalidTid, GHOST, 0)
assert.Equal(obj._v_cookie, "")
assert.Equal(objDD._v_cookie, "")
} }
// TODO Map & List tests. // TODO Map & List tests.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment