Commit 68e94d09 authored by Kirill Smelkov's avatar Kirill Smelkov

X zodb: Polish a bit

parent 5540b6ad
...@@ -88,7 +88,6 @@ EOF ...@@ -88,7 +88,6 @@ EOF
. env.sh . env.sh
pip install git+https://lab.nexedi.com/nexedi/wendelin.core.git@master # XXX does not show git in ver pip install git+https://lab.nexedi.com/nexedi/wendelin.core.git@master # XXX does not show git in ver
pip install git+https://lab.nexedi.com/kirr/zodburi.git@master
pip install zodbtools pip install zodbtools
mkdir -p src/lab.nexedi.com/kirr mkdir -p src/lab.nexedi.com/kirr
......
...@@ -22,24 +22,11 @@ ...@@ -22,24 +22,11 @@
from ZODB.tests import testSerialize from ZODB.tests import testSerialize
from ZODB import serialize from ZODB import serialize
from zodbtools.util import escapeqq
# escape string into valid "..." string
# XXX dup in fs1/py/pyserialize-gen-testdata
def escapeqq(s):
outv = []
# we don't want ' to be escaped
for _ in s.split("'"):
# this escape almost everything except " character
# NOTE string_escape does not do smartquotes and always uses ' for quoting
# (repr(str) is the same except it does smartquoting picking ' or " automatically)
q = _.encode("string_escape")
q = q.replace('"', r'\"')
outv.append(q)
return '"' + "'".join(outv) + '"'
def main(): def main():
# dump to go what to expect # dump to go what to expect
with open("ztestdata_pyserialize_test.go", "w") as f: with open("ztestdata_pydata_test.go", "w") as f:
def emit(v): def emit(v):
print >>f, v print >>f, v
emit("// Code generated by %s; DO NOT EDIT." % __file__) emit("// Code generated by %s; DO NOT EDIT." % __file__)
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
package zodb package zodb
//go:generate ./py/pyserialize-gen-testdata //go:generate ./py/pydata-gen-testdata
import ( import (
"testing" "testing"
......
...@@ -28,6 +28,7 @@ from ZODB import DB ...@@ -28,6 +28,7 @@ from ZODB import DB
from ZODB.POSException import UndoError from ZODB.POSException import UndoError
from persistent import Persistent from persistent import Persistent
import transaction import transaction
from zodbtools.util import escapeqq
import struct import struct
import time import time
...@@ -44,20 +45,6 @@ def unpack64(packed): ...@@ -44,20 +45,6 @@ def unpack64(packed):
def hex64(packed): def hex64(packed):
return '0x%016x' % unpack64(packed) return '0x%016x' % unpack64(packed)
# escape string into valid "..." string
# XXX dup in zodb/py/pyserialize-gen-testdata
def escapeqq(s):
outv = []
# we don't want ' to be escaped
for _ in s.split("'"):
# this escape almost everything except " character
# NOTE string_escape does not do smartquotes and always uses ' for quoting
# (repr(str) is the same except it does smartquoting picking ' or " automatically)
q = _.encode("string_escape")
q = q.replace('"', r'\"')
outv.append(q)
return '"' + "'".join(outv) + '"'
# make time.time() predictable # make time.time() predictable
_xtime = time.mktime(time.strptime("04 Jan 1979", "%d %b %Y")) _xtime = time.mktime(time.strptime("04 Jan 1979", "%d %b %Y"))
def xtime(): def xtime():
......
...@@ -30,22 +30,20 @@ import ( ...@@ -30,22 +30,20 @@ import (
) )
func (tid Tid) String() string { func (tid Tid) String() string {
// XXX also print "tid:" prefix ?
//return fmt.Sprintf("%016x", uint64(tid))
return string(tid.XFmtString(nil)) return string(tid.XFmtString(nil))
} }
func (oid Oid) String() string { func (oid Oid) String() string {
// XXX also print "oid:" prefix ?
//return fmt.Sprintf("%016x", uint64(oid))
return string(oid.XFmtString(nil)) return string(oid.XFmtString(nil))
} }
func (tid Tid) XFmtString(b []byte) []byte { func (tid Tid) XFmtString(b []byte) []byte {
// XXX also print "tid:" prefix ?
return xfmt.AppendHex016(b, uint64(tid)) return xfmt.AppendHex016(b, uint64(tid))
} }
func (oid Oid) XFmtString(b []byte) []byte { func (oid Oid) XFmtString(b []byte) []byte {
// XXX also print "oid:" prefix ?
return xfmt.AppendHex016(b, uint64(oid)) return xfmt.AppendHex016(b, uint64(oid))
} }
...@@ -79,9 +77,9 @@ func (xid Xid) XFmtString(b xfmt.Buffer) xfmt.Buffer { ...@@ -79,9 +77,9 @@ func (xid Xid) XFmtString(b xfmt.Buffer) xfmt.Buffer {
*/ */
// parseHex64 decode 16-character-wide hex-encoded string into uint64 // parseHex64 decodes 16-character-wide hex-encoded string into uint64
// XXX -> xfmt ?
func parseHex64(subj, s string) (uint64, error) { func parseHex64(subj, s string) (uint64, error) {
// XXX -> xfmt ?
// XXX like scanf("%016x") but scanf implicitly skips spaces without giving control to caller and is slower // XXX like scanf("%016x") but scanf implicitly skips spaces without giving control to caller and is slower
var b[8]byte var b[8]byte
if len(s) != 16 { if len(s) != 16 {
...@@ -154,9 +152,10 @@ Error: ...@@ -154,9 +152,10 @@ Error:
return Xid{}, fmt.Errorf("xid %q invalid", s) return Xid{}, fmt.Errorf("xid %q invalid", s)
} }
// ParseTidRange parses string of form "<tidmin>..<tidmax>" into tidMin, tidMax pair // ParseTidRange parses string of form "<tidmin>..<tidmax>" into tidMin, tidMax pair.
//
// Both <tidmin> and <tidmax> can be empty, in which case defaults 0 and TidMax are used.
// //
// both <tidmin> and <tidmax> can be empty, in which case defaults 0 and TidMax are returned
// XXX also check tidMin < tidMax here? or allow reverse ranges ? // XXX also check tidMin < tidMax here? or allow reverse ranges ?
func ParseTidRange(s string) (tidMin, tidMax Tid, err error) { func ParseTidRange(s string) (tidMin, tidMax Tid, err error) {
s1, s2, err := xstrings.Split2(s, "..") s1, s2, err := xstrings.Split2(s, "..")
...@@ -186,13 +185,3 @@ func ParseTidRange(s string) (tidMin, tidMax Tid, err error) { ...@@ -186,13 +185,3 @@ func ParseTidRange(s string) (tidMin, tidMax Tid, err error) {
Error: Error:
return 0, 0, fmt.Errorf("tid range %q invalid", s) return 0, 0, fmt.Errorf("tid range %q invalid", s)
} }
/*
func (tid Tid) String2() string {
var b [8+16]byte
binary.BigEndian.PutUint64(b[:], uint64(tid))
hex.Encode(b[8:], b[:8])
//return mem.String(b[:8])
return string(b[:8])
}
*/
...@@ -41,7 +41,6 @@ func (t TimeStamp) XFmtString(b []byte) []byte { ...@@ -41,7 +41,6 @@ func (t TimeStamp) XFmtString(b []byte) []byte {
} }
// Time converts tid to time // Time converts tid to time
func (tid Tid) Time() TimeStamp { func (tid Tid) Time() TimeStamp {
// the same as _parseRaw in TimeStamp/py // the same as _parseRaw in TimeStamp/py
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
// See https://www.nexedi.com/licensing for rationale and options. // See https://www.nexedi.com/licensing for rationale and options.
package zodb package zodb
// TODO what it is
import "testing" import "testing"
......
...@@ -36,10 +36,13 @@ import ( ...@@ -36,10 +36,13 @@ import (
// //
// In ZODB transaction identifiers are unique 64-bit integer connected to time // In ZODB transaction identifiers are unique 64-bit integer connected to time
// when corresponding transaction was created. // when corresponding transaction was created.
//
// See also: XTid.
type Tid uint64 type Tid uint64
// ZODB/py defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016) // ZODB/py defines maxtid to be max signed int64 since Jun 7 2016:
// (XXX in neo: SQLite does not accept numbers above 2^63-1) // https://github.com/zopefoundation/ZODB/commit/baee84a6
// (XXX in neo/py: SQLite does not accept numbers above 2^63-1)
const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff
...@@ -54,14 +57,14 @@ const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff ...@@ -54,14 +57,14 @@ const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff
type Oid uint64 type Oid uint64
// TxnInfo is metadata information about one transaction. // TxnInfo is metadata information about one transaction.
//
// XXX naming -> TxnMeta?
// XXX +TxnInfo = TxnMeta + []DataInfo ?
type TxnInfo struct { type TxnInfo struct {
Tid Tid Tid Tid
Status TxnStatus Status TxnStatus
User []byte User []byte
Description []byte Description []byte
// additional information about transaction. ZODB/py usually puts py
// dict here but it can be arbitrary raw bytes.
Extension []byte Extension []byte
} }
...@@ -130,7 +133,7 @@ func (e *ErrXidMissing) Error() string { ...@@ -130,7 +133,7 @@ func (e *ErrXidMissing) Error() string {
// IStorage is the interface provided by ZODB storages // IStorage is the interface provided by ZODB storages
type IStorage interface { type IStorage interface {
// XXX add invalidation channel // TODO add invalidation channel
// StorageName returns storage name // StorageName returns storage name
StorageName() string StorageName() string
...@@ -138,11 +141,9 @@ type IStorage interface { ...@@ -138,11 +141,9 @@ type IStorage interface {
// Close closes storage // Close closes storage
Close() error Close() error
// History(ctx, oid, size=1)
// LastTid returns the id of the last committed transaction. // LastTid returns the id of the last committed transaction.
// //
// if no transactions have been committed yet, LastTid returns Tid zero value // If no transactions have been committed yet, LastTid returns Tid zero value.
LastTid(ctx context.Context) (Tid, error) LastTid(ctx context.Context) (Tid, error)
// LastOid returns highest object id of objects committed to storage. // LastOid returns highest object id of objects committed to storage.
...@@ -169,11 +170,14 @@ type IStorage interface { ...@@ -169,11 +170,14 @@ type IStorage interface {
// XXX Restore ? // XXX Restore ?
// CheckCurrentSerialInTransaction(oid Oid, serial Tid, txn ITransaction) // XXX naming // CheckCurrentSerialInTransaction(oid Oid, serial Tid, txn ITransaction) // XXX naming
// TODO:
// tpc_begin(txn) // tpc_begin(txn)
// tpc_vote(txn) // tpc_vote(txn)
// tpc_finish(txn, callback) XXX clarify about callback // tpc_finish(txn, callback) XXX clarify about callback
// tpc_abort(txn) // tpc_abort(txn)
// TODO: History(ctx, oid, size=1)
// Iterate creates iterator to iterate storage in [tidMin, tidMax] range. // Iterate creates iterator to iterate storage in [tidMin, tidMax] range.
// //
// XXX allow iteration both ways (forward & backward) // XXX allow iteration both ways (forward & backward)
...@@ -202,8 +206,7 @@ type IDataIterator interface { ...@@ -202,8 +206,7 @@ type IDataIterator interface {
// Valid returns whether tid is in valid transaction identifiers range // Valid returns whether tid is in valid transaction identifiers range
func (tid Tid) Valid() bool { func (tid Tid) Valid() bool {
// XXX if Tid becomes signed also check wrt 0 if 0 <= tid && tid <= TidMax {
if tid <= TidMax {
return true return true
} else { } else {
return false return false
......
...@@ -32,7 +32,8 @@ import ( ...@@ -32,7 +32,8 @@ import (
) )
// Catobj dumps content of one ZODB object // Catobj dumps content of one ZODB object.
//
// The object is printed in raw form without any headers (see Dumpobj) // The object is printed in raw form without any headers (see Dumpobj)
func Catobj(ctx context.Context, w io.Writer, stor zodb.IStorage, xid zodb.Xid) error { func Catobj(ctx context.Context, w io.Writer, stor zodb.IStorage, xid zodb.Xid) error {
buf, _, err := stor.Load(ctx, xid) buf, _, err := stor.Load(ctx, xid)
...@@ -111,7 +112,7 @@ func catobjMain(argv []string) { ...@@ -111,7 +112,7 @@ func catobjMain(argv []string) {
for _, arg := range argv[1:] { for _, arg := range argv[1:] {
xid, err := zodb.ParseXid(arg) xid, err := zodb.ParseXid(arg)
if err != nil { if err != nil {
prog.Fatal(err) // XXX recheck prog.Fatal(err)
} }
xidv = append(xidv, xid) xidv = append(xidv, xid)
......
...@@ -244,7 +244,7 @@ func dumpMain(argv []string) { ...@@ -244,7 +244,7 @@ func dumpMain(argv []string) {
tidMin, tidMax, err := zodb.ParseTidRange(tidRange) tidMin, tidMax, err := zodb.ParseTidRange(tidRange)
if err != nil { if err != nil {
prog.Fatal(err) // XXX recheck prog.Fatal(err)
} }
stor, err := zodb.OpenStorageURL(context.Background(), storUrl) // TODO read-only stor, err := zodb.OpenStorageURL(context.Background(), storUrl) // TODO read-only
......
...@@ -45,7 +45,7 @@ func diff(a, b string) string { ...@@ -45,7 +45,7 @@ func diff(a, b string) string {
} }
// loadZdumpPy loads a zdump file and normalizes escaped strings to the way go // loadZdumpPy loads a zdump file and normalizes escaped strings to the way go
// would escape them // would escape them.
func loadZdumpPy(t *testing.T, path string) string { func loadZdumpPy(t *testing.T, path string) string {
dump, err := ioutil.ReadFile(path) dump, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
......
...@@ -58,8 +58,12 @@ const helpXid = ...@@ -58,8 +58,12 @@ const helpXid =
` `
// TODO dump format // TODO dump format
const helpZDump =
`TODO describe zodb dump format
`
var helpTopics = prog.HelpRegistry{ var helpTopics = prog.HelpRegistry{
{"zurl", "specifying database URL", helpZURL}, {"zurl", "specifying database URL", helpZURL},
{"xid", "specifying object address", helpXid}, {"xid", "specifying object address", helpXid},
{"zdump", "description of ZODB dump format", helpZDump},
} }
// Code generated by ./py/pyserialize-gen-testdata; DO NOT EDIT. // Code generated by ./py/pydata-gen-testdata; DO NOT EDIT.
package zodb package zodb
var _PyData_ClassName_Testv = [...]_PyDataClassName_TestEntry{ var _PyData_ClassName_Testv = [...]_PyDataClassName_TestEntry{
......
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