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

X zodb: Polish a bit

parent 5540b6ad
......@@ -88,7 +88,6 @@ EOF
. 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/kirr/zodburi.git@master
pip install zodbtools
mkdir -p src/lab.nexedi.com/kirr
......
......@@ -22,24 +22,11 @@
from ZODB.tests import testSerialize
from ZODB import serialize
# 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) + '"'
from zodbtools.util import escapeqq
def main():
# 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):
print >>f, v
emit("// Code generated by %s; DO NOT EDIT." % __file__)
......
......@@ -19,7 +19,7 @@
package zodb
//go:generate ./py/pyserialize-gen-testdata
//go:generate ./py/pydata-gen-testdata
import (
"testing"
......
......@@ -28,6 +28,7 @@ from ZODB import DB
from ZODB.POSException import UndoError
from persistent import Persistent
import transaction
from zodbtools.util import escapeqq
import struct
import time
......@@ -44,20 +45,6 @@ def unpack64(packed):
def hex64(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
_xtime = time.mktime(time.strptime("04 Jan 1979", "%d %b %Y"))
def xtime():
......
......@@ -30,22 +30,20 @@ import (
)
func (tid Tid) String() string {
// XXX also print "tid:" prefix ?
//return fmt.Sprintf("%016x", uint64(tid))
return string(tid.XFmtString(nil))
}
func (oid Oid) String() string {
// XXX also print "oid:" prefix ?
//return fmt.Sprintf("%016x", uint64(oid))
return string(oid.XFmtString(nil))
}
func (tid Tid) XFmtString(b []byte) []byte {
// XXX also print "tid:" prefix ?
return xfmt.AppendHex016(b, uint64(tid))
}
func (oid Oid) XFmtString(b []byte) []byte {
// XXX also print "oid:" prefix ?
return xfmt.AppendHex016(b, uint64(oid))
}
......@@ -79,9 +77,9 @@ func (xid Xid) XFmtString(b xfmt.Buffer) xfmt.Buffer {
*/
// parseHex64 decode 16-character-wide hex-encoded string into uint64
// XXX -> xfmt ?
// parseHex64 decodes 16-character-wide hex-encoded string into uint64
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
var b[8]byte
if len(s) != 16 {
......@@ -154,9 +152,10 @@ Error:
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 ?
func ParseTidRange(s string) (tidMin, tidMax Tid, err error) {
s1, s2, err := xstrings.Split2(s, "..")
......@@ -186,13 +185,3 @@ func ParseTidRange(s string) (tidMin, tidMax Tid, err error) {
Error:
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 {
}
// Time converts tid to time
func (tid Tid) Time() TimeStamp {
// the same as _parseRaw in TimeStamp/py
......
......@@ -18,7 +18,6 @@
// See https://www.nexedi.com/licensing for rationale and options.
package zodb
// TODO what it is
import "testing"
......
......@@ -36,10 +36,13 @@ import (
//
// In ZODB transaction identifiers are unique 64-bit integer connected to time
// when corresponding transaction was created.
//
// See also: XTid.
type Tid uint64
// ZODB/py defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016)
// (XXX in neo: SQLite does not accept numbers above 2^63-1)
// ZODB/py defines maxtid to be max signed int64 since Jun 7 2016:
// 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
......@@ -54,14 +57,14 @@ const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff
type Oid uint64
// TxnInfo is metadata information about one transaction.
//
// XXX naming -> TxnMeta?
// XXX +TxnInfo = TxnMeta + []DataInfo ?
type TxnInfo struct {
Tid Tid
Status TxnStatus
User []byte
Description []byte
// additional information about transaction. ZODB/py usually puts py
// dict here but it can be arbitrary raw bytes.
Extension []byte
}
......@@ -130,7 +133,7 @@ func (e *ErrXidMissing) Error() string {
// IStorage is the interface provided by ZODB storages
type IStorage interface {
// XXX add invalidation channel
// TODO add invalidation channel
// StorageName returns storage name
StorageName() string
......@@ -138,11 +141,9 @@ type IStorage interface {
// Close closes storage
Close() error
// History(ctx, oid, size=1)
// 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)
// LastOid returns highest object id of objects committed to storage.
......@@ -169,11 +170,14 @@ type IStorage interface {
// XXX Restore ?
// CheckCurrentSerialInTransaction(oid Oid, serial Tid, txn ITransaction) // XXX naming
// TODO:
// tpc_begin(txn)
// tpc_vote(txn)
// tpc_finish(txn, callback) XXX clarify about callback
// tpc_abort(txn)
// TODO: History(ctx, oid, size=1)
// Iterate creates iterator to iterate storage in [tidMin, tidMax] range.
//
// XXX allow iteration both ways (forward & backward)
......@@ -202,8 +206,7 @@ type IDataIterator interface {
// Valid returns whether tid is in valid transaction identifiers range
func (tid Tid) Valid() bool {
// XXX if Tid becomes signed also check wrt 0
if tid <= TidMax {
if 0 <= tid && tid <= TidMax {
return true
} else {
return false
......
......@@ -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)
func Catobj(ctx context.Context, w io.Writer, stor zodb.IStorage, xid zodb.Xid) error {
buf, _, err := stor.Load(ctx, xid)
......@@ -111,7 +112,7 @@ func catobjMain(argv []string) {
for _, arg := range argv[1:] {
xid, err := zodb.ParseXid(arg)
if err != nil {
prog.Fatal(err) // XXX recheck
prog.Fatal(err)
}
xidv = append(xidv, xid)
......
......@@ -244,7 +244,7 @@ func dumpMain(argv []string) {
tidMin, tidMax, err := zodb.ParseTidRange(tidRange)
if err != nil {
prog.Fatal(err) // XXX recheck
prog.Fatal(err)
}
stor, err := zodb.OpenStorageURL(context.Background(), storUrl) // TODO read-only
......
......@@ -45,7 +45,7 @@ func diff(a, b string) string {
}
// 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 {
dump, err := ioutil.ReadFile(path)
if err != nil {
......
......@@ -58,8 +58,12 @@ const helpXid =
`
// TODO dump format
const helpZDump =
`TODO describe zodb dump format
`
var helpTopics = prog.HelpRegistry{
{"zurl", "specifying database URL", helpZURL},
{"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
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