Commit 245d1005 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d38d1525
...@@ -157,6 +157,9 @@ func (t *ZBTree) PDeactivate() { ...@@ -157,6 +157,9 @@ func (t *ZBTree) PDeactivate() {
t.pyobj.PDeactivate() t.pyobj.PDeactivate()
} }
func (t *ZBTree) PActivate(ctx context.Context) error {
panic("TODO")
}
// XXX ZBucket.MinKey ? // XXX ZBucket.MinKey ?
...@@ -202,7 +205,9 @@ func (b *ZBucket) PActivate(ctx context.Context) error { ...@@ -202,7 +205,9 @@ func (b *ZBucket) PActivate(ctx context.Context) error {
// .next present // .next present
if len(t) == 2 { if len(t) == 2 {
next, ok := t[1].(*ZBucket) next, ok := t[1].(*ZBucket)
// XXX if !ok if !ok {
// XXX
}
b.next = next b.next = next
} }
...@@ -220,7 +225,9 @@ func (b *ZBucket) PActivate(ctx context.Context) error { ...@@ -220,7 +225,9 @@ func (b *ZBucket) PActivate(ctx context.Context) error {
v := t[2*i+1] v := t[2*i+1]
k, ok := xk.(int64) // XXX use KEY k, ok := xk.(int64) // XXX use KEY
// XXX if !ok if !ok {
// XXX
}
b.keys = append(b.keys, KEY(k)) // XXX cast b.keys = append(b.keys, KEY(k)) // XXX cast
b.values = append(b.values, v) b.values = append(b.values, v)
......
...@@ -254,9 +254,9 @@ import ( ...@@ -254,9 +254,9 @@ import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/pkg/errors" //"github.com/pkg/errors"
pickle "github.com/kisielk/og-rek" // XXX should be temp here? //pickle "github.com/kisielk/og-rek" // XXX should be temp here?
) )
// BigFileRoot represents "/bigfile" // BigFileRoot represents "/bigfile"
...@@ -359,7 +359,9 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs ...@@ -359,7 +359,9 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs
br.mu.Unlock() br.mu.Unlock()
ctx := context.Background() // XXX ok? ctx := context.Background() // XXX ok?
/* _ = ctx
return nil, fuse.ENOSYS // XXX temp
/* XXX kill
buf, _, err := br.zstor.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial buf, _, err := br.zstor.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial
if err != nil { if err != nil {
switch errors.Cause(err).(type) { switch errors.Cause(err).(type) {
...@@ -380,6 +382,7 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs ...@@ -380,6 +382,7 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs
} }
*/ */
/* XXX reenable (.zpy not yet here)
pybf, err := br.zpy.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial pybf, err := br.zpy.Load(ctx, zodb.Xid{Oid: oid, At: zodb.TidMax}) // FIXME At, use serial
if err != nil { if err != nil {
switch errors.Cause(err).(type) { switch errors.Cause(err).(type) {
...@@ -422,6 +425,7 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs ...@@ -422,6 +425,7 @@ func (br *BigFileRoot) Mkdir(name string, mode uint32, _ *fuse.Context) (*nodefs
// XXX mkfile(bh, "invalidations", bh.inv) // XXX mkfile(bh, "invalidations", bh.inv)
return bx.Inode(), fuse.OK return bx.Inode(), fuse.OK
*/
} }
// XXX do we need to support rmdir? (probably no) // XXX do we need to support rmdir? (probably no)
......
// XXX copytight = ? // Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// based on: // based on:
// https://groups.google.com/d/msg/golang-nuts/PYWxjT2v6ps/dL71oJk1mXEJ // https://groups.google.com/d/msg/golang-nuts/PYWxjT2v6ps/dL71oJk1mXEJ
// https://play.golang.org/p/f9HY6-z8Pp // https://play.golang.org/p/f9HY6-z8Pp
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package main package main
// weak reference // weak reference
...@@ -20,6 +38,7 @@ type iface struct { ...@@ -20,6 +38,7 @@ type iface struct {
data uintptr // data data uintptr // data
} }
// weakRefState represents current state of an object WeakRef points to.
type weakRefState int32 type weakRefState int32
const ( const (
...@@ -32,6 +51,9 @@ const ( ...@@ -32,6 +51,9 @@ const (
// WeakRef is a weak reference. // WeakRef is a weak reference.
// //
// Create one with NewWeakRef and retrieve referenced object with Get. // Create one with NewWeakRef and retrieve referenced object with Get.
//
// There must be no more than 1 weak references to any object.
// Weak references must not be attached to an object on which runtime.SetFinalizer is also used.
type WeakRef struct { type WeakRef struct {
iface iface
...@@ -40,12 +62,11 @@ type WeakRef struct { ...@@ -40,12 +62,11 @@ type WeakRef struct {
state weakRefState state weakRefState
} }
// XXX // NewWeakRef creates new weak reference pointing to obj.
func NewWeakRef(obj interface{}) *WeakRef { func NewWeakRef(obj interface{}) *WeakRef {
// original code uses ^ for pointers not to cause GC thinking that original // since starting from ~ Go1.4 the GC is precise, we can save interface
// object is still referenced from WeakRef.data. However starting with ~ Go1.4 // pointers to uintptr and that won't prevent GC from garbage
// the GC is precise, so we don't need that trick this days. // collecting the object.
i := (*[2]uintptr)(unsafe.Pointer(&obj))
w := &WeakRef{ w := &WeakRef{
iface: *(*iface)(unsafe.Pointer(&obj)), iface: *(*iface)(unsafe.Pointer(&obj)),
state: objLive, state: objLive,
......
...@@ -19,6 +19,40 @@ ...@@ -19,6 +19,40 @@
package main package main
// sizeof(interface{}) == 2*sizeof(uintptr) import (
"testing"
"unsafe"
)
// v -> weakref -> get -> == v // v -> weakref -> get -> == v
// GC -> get -> alive -> GC get alive -> GC get alive -> GC GC get ø // GC -> get -> alive -> GC get alive -> GC get alive -> GC GC get ø
// verify that interface <-> iface works ok.
func TestIface(t *testing.T) {
var i interface{}
var fi *iface
isize := unsafe.Sizeof(i)
fsize := unsafe.Sizeof(*fi)
if isize != fsize {
t.Fatalf("sizeof(interface{}) (%d) != sizeof(iface) (%d)", isize, fsize)
}
i = 3
var j interface{}
if !(j == nil && i != j) {
t.Fatalf("i == j ? (i: %#v, j: %#v}", i, j)
}
fi = (*iface)(unsafe.Pointer(&i))
fj := (*iface)(unsafe.Pointer(&j))
*fj = *fi
if i != j {
t.Fatalf("i (%#v) != j (%#v)", i, j)
}
}
func TestWeakRef(t *testing.T) {
}
...@@ -22,10 +22,10 @@ package main ...@@ -22,10 +22,10 @@ package main
import ( import (
"context" //"context"
//"lab.nexedi.com/kirr/neo/go/zodb" //"lab.nexedi.com/kirr/neo/go/zodb"
pickle "github.com/kisielk/og-rek" //pickle "github.com/kisielk/og-rek"
) )
...@@ -105,6 +105,7 @@ func (bf *ZBigFile) PDeactivate() { ...@@ -105,6 +105,7 @@ func (bf *ZBigFile) PDeactivate() {
} }
/* XXX reenable (pickletools)
func (bf *ZBigFile) PActivate(ctx context.Context) (err error) { func (bf *ZBigFile) PActivate(ctx context.Context) (err error) {
if bf.blktab != nil { if bf.blktab != nil {
return nil return nil
...@@ -137,7 +138,7 @@ func (bf *ZBigFile) PActivate(ctx context.Context) (err error) { ...@@ -137,7 +138,7 @@ func (bf *ZBigFile) PActivate(ctx context.Context) (err error) {
bf.blktab = blktab bf.blktab = blktab
return nil return nil
} }
*/
// XXX -> newGhost // XXX -> newGhost
......
...@@ -122,12 +122,12 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (*PyObject, error ...@@ -122,12 +122,12 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (*PyObject, error
func (conn *Connection) loadpy(ctx context.Context, oid zodb.Oid) (pyclass pickle.Class, pystate interface{}, serial zodb.Tid, _ error) { func (conn *Connection) loadpy(ctx context.Context, oid zodb.Oid) (pyclass pickle.Class, pystate interface{}, serial zodb.Tid, _ error) {
buf, serial, err := conn.stor.Load(ctx, zodb.Xid{Oid: oid, At: conn.at}) buf, serial, err := conn.stor.Load(ctx, zodb.Xid{Oid: oid, At: conn.at})
if err != nil { if err != nil {
return pickle.Class{}, nil, zodb.InvalidTID, err return pickle.Class{}, nil, 0, err
} }
pyclass, pystate, err = zodb.PyData(buf.Data).Decode() pyclass, pystate, err = zodb.PyData(buf.Data).Decode()
if err != nil { if err != nil {
return pickle.Class{}, nil, zodb.InvalidTID, err // XXX err ctx return pickle.Class{}, nil, 0, err // XXX err ctx
} }
buf.Release() buf.Release()
...@@ -138,7 +138,7 @@ func (conn *Connection) loadpy(ctx context.Context, oid zodb.Oid) (pyclass pickl ...@@ -138,7 +138,7 @@ func (conn *Connection) loadpy(ctx context.Context, oid zodb.Oid) (pyclass pickl
// newGhost creates new ghost object. // newGhost creates new ghost object.
func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) interface{} { func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) interface{} {
pyobj := PyObject{ pyobj := PyObject{
Object: Object{jar: conn, oid: oid, serial: zodb.InvalidTID}, Object: Object{jar: conn, oid: oid, serial: 0},
pyclass: pyclass, pyclass: pyclass,
pystate: nil, pystate: nil,
} }
...@@ -157,7 +157,7 @@ func (pyobj *PyObject) PDeactivate() { ...@@ -157,7 +157,7 @@ func (pyobj *PyObject) PDeactivate() {
// FIXME if state=modified PDeactivate must be noop. // FIXME if state=modified PDeactivate must be noop.
pyobj.pystate = nil pyobj.pystate = nil
pyobj.serial = zodb.InvalidTID pyobj.serial = 0
} }
// PActivate brings object to live state. // PActivate brings object to live state.
......
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