Commit f37de13c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9e0450d4
...@@ -23,6 +23,7 @@ package main ...@@ -23,6 +23,7 @@ package main
import ( import (
//"context" //"context"
"reflect"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/btree" "lab.nexedi.com/kirr/neo/go/zodb/btree"
...@@ -36,16 +37,18 @@ const zwendelin = "wendelin.bigfile.file_zodb" ...@@ -36,16 +37,18 @@ const zwendelin = "wendelin.bigfile.file_zodb"
// ZBlk0 mimics ZBlk0 from python. // ZBlk0 mimics ZBlk0 from python.
type ZBlk0 struct { type ZBlk0 struct {
*zodb.PyPersistent zodb.Persistent
blkdata string blkdata string
} }
func (zb *ZBlk0) DropState() { type zBlk0State ZBlk0 // hide state methods from public API
func (zb *zBlk0State) DropState() {
zb.blkdata = "" zb.blkdata = ""
} }
func (zb *ZBlk0) PySetState(pystate interface{}) error { func (zb *zBlk0State) PySetState(pystate interface{}) error {
blkdata, ok := pystate.(string) blkdata, ok := pystate.(string)
if !ok { if !ok {
// XXX // XXX
...@@ -59,16 +62,18 @@ func (zb *ZBlk0) PySetState(pystate interface{}) error { ...@@ -59,16 +62,18 @@ func (zb *ZBlk0) PySetState(pystate interface{}) error {
// ZData mimics ZData from python. // ZData mimics ZData from python.
type ZData struct { type ZData struct {
*zodb.PyPersistent zodb.Persistent
data string data string
} }
func (zd *ZData) DropState() { type zDataState ZData // hide state methods from public API
func (zd *zDataState) DropState() {
zd.data = "" zd.data = ""
} }
func (zd *ZData) PySetState(pystate interface{}) error { func (zd *zDataState) PySetState(pystate interface{}) error {
data, ok := pystate.(string) data, ok := pystate.(string)
if !ok { if !ok {
// XXX // XXX
...@@ -80,16 +85,18 @@ func (zd *ZData) PySetState(pystate interface{}) error { ...@@ -80,16 +85,18 @@ func (zd *ZData) PySetState(pystate interface{}) error {
// ZBlk1 mimics ZBlk1 from python. // ZBlk1 mimics ZBlk1 from python.
type ZBlk1 struct { type ZBlk1 struct {
*zodb.PyPersistent zodb.Persistent
chunktab *btree.BTree // {} offset -> ZData(chunk) chunktab *btree.BTree // {} offset -> ZData(chunk)
} }
func (zb *ZBlk1) DropState() { type zBlk1State ZBlk1 // hide state methods from public API
func (zb *zBlk1State) DropState() {
zb.chunktab = nil zb.chunktab = nil
} }
func (zb *ZBlk1) PySetState(pystate interface{}) error { func (zb *zBlk1State) PySetState(pystate interface{}) error {
chunktab, ok := pystate.(*btree.BTree) chunktab, ok := pystate.(*btree.BTree)
if !ok { if !ok {
// XXX // XXX
...@@ -104,21 +111,23 @@ func (zb *ZBlk1) PySetState(pystate interface{}) error { ...@@ -104,21 +111,23 @@ func (zb *ZBlk1) PySetState(pystate interface{}) error {
// ZBigFile mimics ZBigFile from python. // ZBigFile mimics ZBigFile from python.
type ZBigFile struct { type ZBigFile struct {
*zodb.PyPersistent zodb.Persistent
blksize int64 blksize int64
blktab *btree.BTree // LOBtree{} blk -> ZBlk*(blkdata) blktab *btree.BTree // LOBtree{} blk -> ZBlk*(blkdata)
} }
type zBigFileState ZBigFile // hide state methods from public API
// DropState implements Stateful. // DropState implements Stateful.
func (bf *ZBigFile) DropState() { func (bf *zBigFileState) DropState() {
bf.blksize = -1 bf.blksize = -1
bf.blktab = nil bf.blktab = nil
} }
// PySetState implements PyStateful. // PySetState implements PyStateful.
func (bf *ZBigFile) PySetState(pystate interface{}) (err error) { func (bf *zBigFileState) PySetState(pystate interface{}) (err error) {
// ZBigFile // ZBigFile
// .blksize xint // .blksize xint
// .blktab LOBtree{} blk -> ZBlk*(blkdata) // .blktab LOBtree{} blk -> ZBlk*(blkdata)
...@@ -148,15 +157,11 @@ func (bf *ZBigFile) PySetState(pystate interface{}) (err error) { ...@@ -148,15 +157,11 @@ func (bf *ZBigFile) PySetState(pystate interface{}) (err error) {
// ---------------------------------------- // ----------------------------------------
func zblk0New(base *zodb.PyPersistent) zodb.IPyPersistent { return &ZBlk0{PyPersistent: base} }
func zblk1New(base *zodb.PyPersistent) zodb.IPyPersistent { return &ZBlk1{PyPersistent: base} }
func zdataNew(base *zodb.PyPersistent) zodb.IPyPersistent { return &ZData{PyPersistent: base} }
func zbigfileNew(pyobj *zodb.PyPersistent) zodb.IPyPersistent { return &ZBigFile{PyPersistent: pyobj} }
func init() { func init() {
zodb.PyRegisterClass(zwendelin + ".ZBlk", zblk0New) t := reflect.TypeOf
zodb.PyRegisterClass(zwendelin + ".ZBlk0", zblk0New) zodb.RegisterClass(zwendelin + ".ZBlk", t(ZBlk0{}), t(zBlk0State{}))
zodb.PyRegisterClass(zwendelin + ".ZBlk1", zblk1New) zodb.RegisterClass(zwendelin + ".ZBlk0", t(ZBlk0{}), t(zBlk0State{}))
zodb.PyRegisterClass(zwendelin + ".ZData", zdataNew) zodb.RegisterClass(zwendelin + ".ZBlk1", t(ZBlk1{}), t(zBlk1State{}))
zodb.PyRegisterClass(zwendelin + ".ZBigFile", zbigfileNew) zodb.RegisterClass(zwendelin + ".ZData", t(ZData{}), t(zDataState{}))
zodb.RegisterClass(zwendelin + ".ZBigFile", t(ZBigFile{}), t(zBigFileState{}))
} }
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// 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
// TODO
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