Commit f21b6a69 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6a8f9f71
......@@ -6,6 +6,8 @@ import (
"encoding/binary"
"reflect"
"sort"
"./zodb"
)
// packets marshalling
......@@ -595,8 +597,8 @@ func (p *AnswerRecovery) NEODecode(data []byte) (int, error) {
goto overflow
}
p.PTid = PTid(binary.BigEndian.Uint64(data[0:]))
p.BackupTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.TruncateTID = Tid(binary.BigEndian.Uint64(data[16:]))
p.BackupTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.TruncateTID = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
return 24, nil
overflow:
......@@ -631,8 +633,8 @@ func (p *AnswerLastIDs) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.LastOID = Oid(binary.BigEndian.Uint64(data[0:]))
p.LastTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.LastOID = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.LastTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -930,7 +932,7 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.MaxTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -938,10 +940,10 @@ func (p *AnswerUnfinishedTransactions) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.TidList = make([]struct{ UnfinishedTID Tid }, l)
p.TidList = make([]struct{ UnfinishedTID zodb.Tid }, l)
for i := 0; uint32(i) < l; i++ {
a := &p.TidList[i]
(*a).UnfinishedTID = Tid(binary.BigEndian.Uint64(data[0:]))
(*a).UnfinishedTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -975,7 +977,7 @@ func (p *AnswerLockedTransactions) NEOEncode(data []byte) {
l := uint32(len(p.TidDict))
binary.BigEndian.PutUint32(data[0:], l)
data = data[4:]
keyv := make([]Tid, 0, l)
keyv := make([]zodb.Tid, 0, l)
for key := range p.TidDict {
keyv = append(keyv, key)
}
......@@ -1000,11 +1002,11 @@ func (p *AnswerLockedTransactions) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 16
p.TidDict = make(map[Tid]Tid, l)
p.TidDict = make(map[zodb.Tid]zodb.Tid, l)
m := p.TidDict
for i := 0; uint32(i) < l; i++ {
key := Tid(binary.BigEndian.Uint64(data[0:]))
m[key] = Tid(binary.BigEndian.Uint64(data[8:]))
key := zodb.Tid(binary.BigEndian.Uint64(data[0:]))
m[key] = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
data = data[16:]
}
}
......@@ -1028,7 +1030,7 @@ func (p *FinalTID) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.TTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.TTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1049,7 +1051,7 @@ func (p *AnswerFinalTID) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1071,8 +1073,8 @@ func (p *ValidateTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.TTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
p.TTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -1093,7 +1095,7 @@ func (p *BeginTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1114,7 +1116,7 @@ func (p *AnswerBeginTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1156,7 +1158,7 @@ func (p *FinishTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -1164,10 +1166,10 @@ func (p *FinishTransaction) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += 4 + l*8
p.OIDList = make([]Oid, l)
p.OIDList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OIDList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1178,10 +1180,10 @@ func (p *FinishTransaction) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.CheckedList = make([]Oid, l)
p.CheckedList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.CheckedList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1206,8 +1208,8 @@ func (p *AnswerFinishTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.TTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
p.TTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -1229,8 +1231,8 @@ func (p *NotifyTransactionFinished) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.TTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.TTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -1252,8 +1254,8 @@ func (p *LockInformation) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.Ttid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
p.Ttid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -1274,7 +1276,7 @@ func (p *AnswerLockInformation) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Ttid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Ttid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1306,7 +1308,7 @@ func (p *InvalidateObjects) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -1314,10 +1316,10 @@ func (p *InvalidateObjects) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.OidList = make([]Oid, l)
p.OidList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1341,7 +1343,7 @@ func (p *UnlockInformation) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.TTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.TTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1400,10 +1402,10 @@ func (p *AnswerGenerateOIDs) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.OidList = make([]Oid, l)
p.OidList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1441,8 +1443,8 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 41 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.Serial = Tid(binary.BigEndian.Uint64(data[8:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.Compression = byte2bool((data[16:])[0])
copy(p.Checksum[:], data[17:37])
{
......@@ -1456,8 +1458,8 @@ func (p *StoreObject) NEODecode(data []byte) (int, error) {
copy(p.Data, data[:l])
data = data[l:]
}
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[8:]))
p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.Unlock = byte2bool((data[16:])[0])
return 41 + int(nread), nil
......@@ -1482,8 +1484,8 @@ func (p *AnswerStoreObject) NEODecode(data []byte) (int, error) {
goto overflow
}
p.Conflicting = byte2bool((data[0:])[0])
p.Oid = Oid(binary.BigEndian.Uint64(data[1:]))
p.Serial = Tid(binary.BigEndian.Uint64(data[9:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[1:]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[9:]))
return 17, nil
overflow:
......@@ -1504,7 +1506,7 @@ func (p *AbortTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1557,7 +1559,7 @@ func (p *StoreTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -1595,10 +1597,10 @@ func (p *StoreTransaction) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.OidList = make([]Oid, l)
p.OidList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1622,7 +1624,7 @@ func (p *VoteTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1645,9 +1647,9 @@ func (p *GetObject) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 24 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.Serial = Tid(binary.BigEndian.Uint64(data[8:]))
p.Tid = Tid(binary.BigEndian.Uint64(data[16:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
return 24, nil
overflow:
......@@ -1681,9 +1683,9 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 49 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.SerialStart = Tid(binary.BigEndian.Uint64(data[8:]))
p.SerialEnd = Tid(binary.BigEndian.Uint64(data[16:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.SerialStart = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.SerialEnd = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
p.Compression = byte2bool((data[24:])[0])
copy(p.Checksum[:], data[25:45])
{
......@@ -1697,7 +1699,7 @@ func (p *AnswerGetObject) NEODecode(data []byte) (int, error) {
copy(p.Data, data[:l])
data = data[l:]
}
p.DataSerial = Tid(binary.BigEndian.Uint64(data[0:]))
p.DataSerial = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 49 + int(nread), nil
overflow:
......@@ -1760,10 +1762,10 @@ func (p *AnswerTIDList) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.TIDList = make([]Tid, l)
p.TIDList = make([]zodb.Tid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.TIDList[i]
(*a) = Tid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1790,8 +1792,8 @@ func (p *TIDListFrom) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 24 {
goto overflow
}
p.MinTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.MinTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.Length = binary.BigEndian.Uint32(data[16:])
p.Partition = binary.BigEndian.Uint32(data[20:])
return 24, nil
......@@ -1831,10 +1833,10 @@ func (p *AnswerTIDListFrom) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.TidList = make([]Tid, l)
p.TidList = make([]zodb.Tid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.TidList[i]
(*a) = Tid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1858,7 +1860,7 @@ func (p *TransactionInformation) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -1912,7 +1914,7 @@ func (p *AnswerTransactionInformation) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -1951,10 +1953,10 @@ func (p *AnswerTransactionInformation) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.OidList = make([]Oid, l)
p.OidList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -1980,7 +1982,7 @@ func (p *ObjectHistory) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 24 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.First = binary.BigEndian.Uint64(data[8:])
p.Last = binary.BigEndian.Uint64(data[16:])
return 24, nil
......@@ -2015,7 +2017,7 @@ func (p *AnswerObjectHistory) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
{
l := binary.BigEndian.Uint32(data[8:])
data = data[12:]
......@@ -2024,12 +2026,12 @@ func (p *AnswerObjectHistory) NEODecode(data []byte) (int, error) {
}
nread += l * 12
p.HistoryList = make([]struct {
Serial Tid
Serial zodb.Tid
Size uint32
}, l)
for i := 0; uint32(i) < l; i++ {
a := &p.HistoryList[i]
(*a).Serial = Tid(binary.BigEndian.Uint64(data[0:]))
(*a).Serial = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
(*a).Size = binary.BigEndian.Uint32(data[8:])
data = data[12:]
}
......@@ -2612,9 +2614,9 @@ func (p *ObjectUndoSerial) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 28 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.LTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.UndoneTID = Tid(binary.BigEndian.Uint64(data[16:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.LTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.UndoneTID = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
{
l := binary.BigEndian.Uint32(data[24:])
data = data[28:]
......@@ -2622,10 +2624,10 @@ func (p *ObjectUndoSerial) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 8
p.OidList = make([]Oid, l)
p.OidList = make([]zodb.Oid, l)
for i := 0; uint32(i) < l; i++ {
a := &p.OidList[i]
(*a) = Oid(binary.BigEndian.Uint64(data[0:]))
(*a) = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
data = data[8:]
}
}
......@@ -2646,7 +2648,7 @@ func (p *AnswerObjectUndoSerial) NEOEncode(data []byte) {
l := uint32(len(p.ObjectTIDDict))
binary.BigEndian.PutUint32(data[0:], l)
data = data[4:]
keyv := make([]Oid, 0, l)
keyv := make([]zodb.Oid, 0, l)
for key := range p.ObjectTIDDict {
keyv = append(keyv, key)
}
......@@ -2673,21 +2675,21 @@ func (p *AnswerObjectUndoSerial) NEODecode(data []byte) (int, error) {
goto overflow
}
nread += l * 25
p.ObjectTIDDict = make(map[Oid]struct {
CurrentSerial Tid
UndoSerial Tid
p.ObjectTIDDict = make(map[zodb.Oid]struct {
CurrentSerial zodb.Tid
UndoSerial zodb.Tid
IsCurrent bool
}, l)
m := p.ObjectTIDDict
for i := 0; uint32(i) < l; i++ {
key := Oid(binary.BigEndian.Uint64(data[0:]))
key := zodb.Oid(binary.BigEndian.Uint64(data[0:]))
var v struct {
CurrentSerial Tid
UndoSerial Tid
CurrentSerial zodb.Tid
UndoSerial zodb.Tid
IsCurrent bool
}
v.CurrentSerial = Tid(binary.BigEndian.Uint64(data[8:]))
v.UndoSerial = Tid(binary.BigEndian.Uint64(data[16:]))
v.CurrentSerial = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
v.UndoSerial = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
v.IsCurrent = byte2bool((data[24:])[0])
m[key] = v
data = data[25:]
......@@ -2714,8 +2716,8 @@ func (p *HasLock) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 16 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Oid = Oid(binary.BigEndian.Uint64(data[8:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[8:]))
return 16, nil
overflow:
......@@ -2737,7 +2739,7 @@ func (p *AnswerHasLock) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 12 {
goto overflow
}
p.Oid = Oid(binary.BigEndian.Uint64(data[0:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[0:]))
p.LockState = LockState(int32(binary.BigEndian.Uint32(data[8:])))
return 12, nil
......@@ -2761,9 +2763,9 @@ func (p *CheckCurrentSerial) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 24 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Serial = Tid(binary.BigEndian.Uint64(data[8:]))
p.Oid = Oid(binary.BigEndian.Uint64(data[16:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[16:]))
return 24, nil
overflow:
......@@ -2787,8 +2789,8 @@ func (p *AnswerCheckCurrentSerial) NEODecode(data []byte) (int, error) {
goto overflow
}
p.Conflicting = byte2bool((data[0:])[0])
p.Oid = Oid(binary.BigEndian.Uint64(data[1:]))
p.Serial = Tid(binary.BigEndian.Uint64(data[9:]))
p.Oid = zodb.Oid(binary.BigEndian.Uint64(data[1:]))
p.Serial = zodb.Tid(binary.BigEndian.Uint64(data[9:]))
return 17, nil
overflow:
......@@ -2809,7 +2811,7 @@ func (p *Pack) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......@@ -2883,8 +2885,8 @@ func (p *CheckReplicas) NEODecode(data []byte) (int, error) {
data = data[8:]
}
}
p.MinTID = Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.MinTID = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
return 4 + int(nread), nil
overflow:
......@@ -2945,8 +2947,8 @@ func (p *CheckPartition) NEODecode(data []byte) (int, error) {
data = data[l:]
}
p.Source.Address.Port = binary.BigEndian.Uint16(data[0:])
p.MinTID = Tid(binary.BigEndian.Uint64(data[2:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[10:]))
p.MinTID = zodb.Tid(binary.BigEndian.Uint64(data[2:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[10:]))
return 8 + int(nread), nil
overflow:
......@@ -2972,8 +2974,8 @@ func (p *CheckTIDRange) NEODecode(data []byte) (int, error) {
}
p.Partition = binary.BigEndian.Uint32(data[0:])
p.Length = binary.BigEndian.Uint32(data[4:])
p.MinTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[16:]))
p.MinTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
return 24, nil
overflow:
......@@ -2998,7 +3000,7 @@ func (p *AnswerCheckTIDRange) NEODecode(data []byte) (int, error) {
}
p.Count = binary.BigEndian.Uint32(data[0:])
copy(p.Checksum[:], data[4:24])
p.MaxTID = Tid(binary.BigEndian.Uint64(data[24:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[24:]))
return 32, nil
overflow:
......@@ -3025,9 +3027,9 @@ func (p *CheckSerialRange) NEODecode(data []byte) (int, error) {
}
p.Partition = binary.BigEndian.Uint32(data[0:])
p.Length = binary.BigEndian.Uint32(data[4:])
p.MinTID = Tid(binary.BigEndian.Uint64(data[8:]))
p.MaxTID = Tid(binary.BigEndian.Uint64(data[16:]))
p.MinOID = Oid(binary.BigEndian.Uint64(data[24:]))
p.MinTID = zodb.Tid(binary.BigEndian.Uint64(data[8:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[16:]))
p.MinOID = zodb.Oid(binary.BigEndian.Uint64(data[24:]))
return 32, nil
overflow:
......@@ -3054,9 +3056,9 @@ func (p *AnswerCheckSerialRange) NEODecode(data []byte) (int, error) {
}
p.Count = binary.BigEndian.Uint32(data[0:])
copy(p.TidChecksum[:], data[4:24])
p.MaxTID = Tid(binary.BigEndian.Uint64(data[24:]))
p.MaxTID = zodb.Tid(binary.BigEndian.Uint64(data[24:]))
copy(p.OidChecksum[:], data[32:52])
p.MaxOID = Oid(binary.BigEndian.Uint64(data[52:]))
p.MaxOID = zodb.Oid(binary.BigEndian.Uint64(data[52:]))
return 60, nil
overflow:
......@@ -3136,7 +3138,7 @@ func (p *AnswerLastTransaction) NEODecode(data []byte) (int, error) {
if uint32(len(data)) < 8 {
goto overflow
}
p.Tid = Tid(binary.BigEndian.Uint64(data[0:]))
p.Tid = zodb.Tid(binary.BigEndian.Uint64(data[0:]))
return 8, nil
overflow:
......
......@@ -4,97 +4,24 @@
// TODO text
package neo
// ZODB types
// XXX naming -> TID, OID ?
type Tid uint64 // transaction identifier TODO encode as BE
type Oid uint64 // object identifier TODO encode as BE
/*
// XXX "extended" oid - oid + serial, completely specifying object revision
type Xid struct {
Tid
Oid
}
*/
import (
"./zodb"
)
const (
//INVALID_UUID UUID = 0
INVALID_TID Tid = 1<<64 - 1 // 0xffffffffffffffff
INVALID_OID Oid = 1<<64 - 1
ZERO_TID Tid = 0 // XXX or simply TID{} ?
TID0 Tid = ZERO_TID // XXX ^^^ choose 1
INVALID_TID zodb.Tid = 1<<64 - 1 // 0xffffffffffffffff
INVALID_OID zodb.Oid = 1<<64 - 1
// XXX vvv move to ZODB ?
ZERO_TID zodb.Tid = 0 // XXX or simply TID{} ?
TID0 zodb.Tid = ZERO_TID // XXX ^^^ choose 1
ZERO_OID Oid = 0 // XXX or simply OID{} ? // XXX -> OID0
ZERO_OID zodb.Oid = 0 // XXX or simply OID{} ? // XXX -> OID0
// OID_LEN = 8
// TID_LEN = 8
MAX_TID Tid = 1<<63 - 1 // 0x7fffffffffffffff
MAX_TID zodb.Tid = 1<<63 - 1 // 0x7fffffffffffffff
// SQLite does not accept numbers above 2^63-1
// ZODB also defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016)
TIDMAX Tid = MAX_TID // XXX ^^^ choose 1
TIDMAX zodb.Tid = MAX_TID // XXX ^^^ choose 1
)
// ----------------------------------------
type TxnStatus byte
// TODO Tid.String(), Oid.String() +verbose, scanning (?)
// Information about single storage transaction
// XXX -> storage.ITransactionInformation
//type IStorageTransactionInformation interface {
type StorageTransactionInformation struct {
Tid Tid
Status TxnStatus
User []byte
Description []byte
Extension []byte
// TODO iter -> IStorageRecordInformation
Iter IStorageRecordIterator
}
// Information about single storage record
type StorageRecordInformation struct {
Oid Oid
Tid Tid
Data []byte
// XXX .version ?
// XXX .data_txn (The previous transaction id)
}
type IStorage interface {
Close() error
// TODO:
// Name()
// History(oid, size=1)
// LastTid()
// LoadBefore(oid Oid, beforeTid Tid) (data []bytes, tid Tid, err error)
// LoadSerial(oid Oid, serial Tid) (data []bytes, err error)
// PrefetchBefore(oidv []Oid, beforeTid Tid) error (?)
// Store(oid Oid, serial Tid, data []byte, txn ITransaction) error
// XXX Restore ?
// CheckCurrentSerialInTransaction(oid Oid, serial Tid, txn ITransaction) // XXX naming
// tpc_begin(txn)
// tpc_vote(txn)
// tpc_finish(txn, callback) XXX clarify about callback
// tpc_abort(txn)
Iterate(start, stop Tid) IStorageIterator // XXX -> Iter() ?
}
type IStorageIterator interface {
Next() (*StorageTransactionInformation, error) // XXX -> NextTxn() ?
}
type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
Next() (*StorageRecordInformation, error) // XXX vs ptr & nil ?
// XXX -> NextTxnObject() ?
}
......@@ -6,6 +6,8 @@ package neo
// XXX move imports out of here
import (
"./zodb"
"encoding/binary"
"errors"
"math"
......@@ -281,8 +283,8 @@ type Recovery struct {
type AnswerRecovery struct {
PTid
BackupTID Tid
TruncateTID Tid
BackupTID zodb.Tid
TruncateTID zodb.Tid
}
// Ask the last OID/TID so that a master can initialize its TransactionManager.
......@@ -291,8 +293,8 @@ type LastIDs struct {
}
type AnswerLastIDs struct {
LastOID Oid
LastTID Tid
LastOID zodb.Oid
LastTID zodb.Tid
}
// Ask the full partition table. PM -> S.
......@@ -343,9 +345,9 @@ type UnfinishedTransactions struct {
}
type AnswerUnfinishedTransactions struct {
MaxTID Tid
MaxTID zodb.Tid
TidList []struct{
UnfinishedTID Tid
UnfinishedTID zodb.Tid
}
}
......@@ -355,77 +357,77 @@ type LockedTransactions struct {
}
type AnswerLockedTransactions struct {
TidDict map[Tid]Tid // ttid -> tid
TidDict map[zodb.Tid]zodb.Tid // ttid -> tid
}
// Return final tid if ttid has been committed. * -> S. C -> PM.
type FinalTID struct {
TTID Tid
TTID zodb.Tid
}
type AnswerFinalTID struct {
Tid Tid
Tid zodb.Tid
}
// Commit a transaction. PM -> S.
type ValidateTransaction struct {
TTID Tid
Tid Tid
TTID zodb.Tid
Tid zodb.Tid
}
// Ask to begin a new transaction. C -> PM.
// Answer when a transaction begin, give a TID if necessary. PM -> C.
type BeginTransaction struct {
Tid Tid
Tid zodb.Tid
}
type AnswerBeginTransaction struct {
Tid Tid
Tid zodb.Tid
}
// Finish a transaction. C -> PM.
// Answer when a transaction is finished. PM -> C.
type FinishTransaction struct {
Tid Tid
OIDList []Oid
CheckedList []Oid
Tid zodb.Tid
OIDList []zodb.Oid
CheckedList []zodb.Oid
}
type AnswerFinishTransaction struct {
TTID Tid
Tid Tid
TTID zodb.Tid
Tid zodb.Tid
}
// Notify that a transaction blocking a replication is now finished
// M -> S
type NotifyTransactionFinished struct {
TTID Tid
MaxTID Tid
TTID zodb.Tid
MaxTID zodb.Tid
}
// Lock information on a transaction. PM -> S.
// Notify information on a transaction locked. S -> PM.
type LockInformation struct {
Ttid Tid
Tid Tid
Ttid zodb.Tid
Tid zodb.Tid
}
// XXX AnswerInformationLocked ?
type AnswerLockInformation struct {
Ttid Tid
Ttid zodb.Tid
}
// Invalidate objects. PM -> C.
// XXX ask_finish_transaction ?
type InvalidateObjects struct {
Tid Tid
OidList []Oid
Tid zodb.Tid
OidList []zodb.Oid
}
// Unlock information on a transaction. PM -> S.
type UnlockInformation struct {
TTID Tid
TTID zodb.Tid
}
// Ask new object IDs. C -> PM.
......@@ -436,7 +438,7 @@ type GenerateOIDs struct {
// XXX answer_new_oids ?
type AnswerGenerateOIDs struct {
OidList []Oid
OidList []zodb.Oid
}
......@@ -447,42 +449,42 @@ type AnswerGenerateOIDs struct {
// if this serial is newer than the current transaction ID, a client
// node must not try to resolve the conflict. S -> C.
type StoreObject struct {
Oid Oid
Serial Tid
Oid zodb.Oid
Serial zodb.Tid
Compression bool
Checksum Checksum
Data []byte // TODO separately (for writev)
DataSerial Tid
Tid Tid
DataSerial zodb.Tid
Tid zodb.Tid
Unlock bool
}
type AnswerStoreObject struct {
Conflicting bool
Oid Oid
Serial Tid
Oid zodb.Oid
Serial zodb.Tid
}
// Abort a transaction. C -> S, PM.
type AbortTransaction struct {
Tid Tid
Tid zodb.Tid
}
// Ask to store a transaction. C -> S.
// Answer if transaction has been stored. S -> C.
type StoreTransaction struct {
Tid Tid
Tid zodb.Tid
User string
Description string
Extension string
OidList []Oid
OidList []zodb.Oid
// TODO _answer = PFEmpty
}
// Ask to store a transaction. C -> S.
// Answer if transaction has been stored. S -> C.
type VoteTransaction struct {
Tid Tid
Tid zodb.Tid
// TODO _answer = PFEmpty
}
......@@ -491,20 +493,20 @@ type VoteTransaction struct {
// a TID is specified, an object right before the TID will be returned. C -> S.
// Answer the requested object. S -> C.
type GetObject struct {
Oid Oid
Serial Tid
Tid Tid
Oid zodb.Oid
Serial zodb.Tid
Tid zodb.Tid
}
// XXX answer_object ?
type AnswerGetObject struct {
Oid Oid
SerialStart Tid
SerialEnd Tid
Oid zodb.Oid
SerialStart zodb.Tid
SerialEnd zodb.Tid
Compression bool
Checksum Checksum
Data []byte // TODO separately (for writev)
DataSerial Tid
DataSerial zodb.Tid
}
// Ask for TIDs between a range of offsets. The order of TIDs is descending,
......@@ -518,52 +520,52 @@ type TIDList struct {
// XXX answer_tids ?
type AnswerTIDList struct {
TIDList []Tid
TIDList []zodb.Tid
}
// Ask for length TIDs starting at min_tid. The order of TIDs is ascending.
// C -> S.
// Answer the requested TIDs. S -> C
type TIDListFrom struct {
MinTID Tid
MaxTID Tid
MinTID zodb.Tid
MaxTID zodb.Tid
Length uint32 // PNumber
Partition uint32 // PNumber
}
// XXX answer_tids ?
type AnswerTIDListFrom struct {
TidList []Tid
TidList []zodb.Tid
}
// Ask information about a transaction. Any -> S.
// Answer information (user, description) about a transaction. S -> Any.
type TransactionInformation struct {
Tid Tid
Tid zodb.Tid
}
type AnswerTransactionInformation struct {
Tid Tid
Tid zodb.Tid
User string
Description string
Extension string
Packed bool
OidList []Oid
OidList []zodb.Oid
}
// Ask history information for a given object. The order of serials is
// descending, and the range is [first, last]. C -> S.
// Answer history information (serial, size) for an object. S -> C.
type ObjectHistory struct {
Oid Oid
Oid zodb.Oid
First uint64 // PIndex XXX this is actually TID
Last uint64 // PIndex ----//----
}
type AnswerObjectHistory struct {
Oid Oid
Oid zodb.Oid
HistoryList []struct {
Serial Tid
Serial zodb.Tid
Size uint32 // PNumber
}
}
......@@ -677,17 +679,17 @@ type X_ClusterState struct { // XXX conflicts with ClusterState enum
// If current_serial's data is current on storage.
// S -> C
type ObjectUndoSerial struct {
Tid Tid
LTID Tid
UndoneTID Tid
OidList []Oid
Tid zodb.Tid
LTID zodb.Tid
UndoneTID zodb.Tid
OidList []zodb.Oid
}
// XXX answer_undo_transaction ?
type AnswerObjectUndoSerial struct {
ObjectTIDDict map[Oid]struct {
CurrentSerial Tid
UndoSerial Tid
ObjectTIDDict map[zodb.Oid]struct {
CurrentSerial zodb.Tid
UndoSerial zodb.Tid
IsCurrent bool
}
}
......@@ -696,12 +698,12 @@ type AnswerObjectUndoSerial struct {
// C -> S
// Answer whether a transaction holds the write lock for requested object.
type HasLock struct {
Tid Tid
Oid Oid
Tid zodb.Tid
Oid zodb.Oid
}
type AnswerHasLock struct {
Oid Oid
Oid zodb.Oid
LockState LockState
}
......@@ -713,16 +715,16 @@ type AnswerHasLock struct {
// Same structure as AnswerStoreObject, to handle the same way, except there
// is nothing to invalidate in any client's cache.
type CheckCurrentSerial struct {
Tid Tid
Serial Tid
Oid Oid
Tid zodb.Tid
Serial zodb.Tid
Oid zodb.Oid
}
// XXX answer_store_object ?
type AnswerCheckCurrentSerial struct {
Conflicting bool
Oid Oid
Serial Tid
Oid zodb.Oid
Serial zodb.Tid
}
// Request a pack at given TID.
......@@ -732,7 +734,7 @@ type AnswerCheckCurrentSerial struct {
// S -> M
// M -> C
type Pack struct {
Tid Tid
Tid zodb.Tid
}
type AnswerPack struct {
......@@ -744,8 +746,8 @@ type AnswerPack struct {
// A -> M
type CheckReplicas struct {
PartitionDict map[uint32]UUID // partition -> source (PNumber)
MinTID Tid
MaxTID Tid
MinTID zodb.Tid
MaxTID zodb.Tid
// XXX _answer = Error
}
......@@ -757,8 +759,8 @@ type CheckPartition struct {
UpstreamName string
Address Address
}
MinTID Tid
MaxTID Tid
MinTID zodb.Tid
MaxTID zodb.Tid
}
......@@ -773,14 +775,14 @@ type CheckPartition struct {
type CheckTIDRange struct {
Partition uint32 // PNumber
Length uint32 // PNumber
MinTID Tid
MaxTID Tid
MinTID zodb.Tid
MaxTID zodb.Tid
}
type AnswerCheckTIDRange struct {
Count uint32 // PNumber
Checksum Checksum
MaxTID Tid
MaxTID zodb.Tid
}
// Ask some stats about a range of object history.
......@@ -794,17 +796,17 @@ type AnswerCheckTIDRange struct {
type CheckSerialRange struct {
Partition uint32 // PNumber
Length uint32 // PNumber
MinTID Tid
MaxTID Tid
MinOID Oid
MinTID zodb.Tid
MaxTID zodb.Tid
MinOID zodb.Oid
}
type AnswerCheckSerialRange struct {
Count uint32 // PNumber
TidChecksum Checksum
MaxTID Tid
MaxTID zodb.Tid
OidChecksum Checksum
MaxOID Oid
MaxOID zodb.Oid
}
// S -> M
......@@ -822,7 +824,7 @@ type LastTransaction struct {
}
type AnswerLastTransaction struct {
Tid Tid
Tid zodb.Tid
}
......
......@@ -71,7 +71,9 @@ import (
// parsed & typechecked input
var fset = token.NewFileSet()
var info = &types.Info{
var fileMap = map[string]*ast.File{} // fileName -> AST
var pkgMap = map[string]*types.Package{} // pkgName -> Package
var typeInfo = &types.Info{
Types: make(map[ast.Expr]types.TypeAndValue),
Defs: make(map[*ast.Ident]types.Object),
}
......@@ -97,33 +99,59 @@ func (b *Buffer) emit(format string, a ...interface{}) {
}
func main() {
var err error
// importer that takes into account our already-loaded packages
type localImporter struct {
types.Importer
}
log.SetFlags(0)
func (li *localImporter) Import(path string) (*types.Package, error) {
xpath := strings.TrimPrefix(path, "./") // ./zodb -> zodb
pkg := pkgMap[xpath]
if pkg != nil {
return pkg, nil
}
// go through proto.go and AST'ify & typecheck it
var fv []*ast.File
for _, src := range []string{"proto.go", "neo.go"} {
return li.Importer.Import(path)
}
func loadPkg(pkgName string, sources ...string) *types.Package {
var filev []*ast.File
// parse
for _, src := range sources {
f, err := parser.ParseFile(fset, src, nil, 0)
if err != nil {
log.Fatalf("parse: %v", err)
}
fv = append(fv, f)
fileMap[src] = f
filev = append(filev, f)
}
//ast.Print(fset, fv[0])
//return
conf := types.Config{Importer: importer.Default()}
neoPkg, err := conf.Check("neo", fset, fv, info)
// typecheck
conf := types.Config{Importer: &localImporter{importer.Default()}}
pkg, err := conf.Check(pkgName, fset, filev, typeInfo)
if err != nil {
log.Fatalf("typecheck: %v", err)
}
neoQualifier = types.RelativeTo(neoPkg)
pkgMap[pkgName] = pkg
return pkg
}
func main() {
var err error
log.SetFlags(0)
// go through proto.go and AST'ify & typecheck it
loadPkg("zodb", "zodb/zodb.go")
loadPkg("neo", "proto.go", "neo.go")
neoQualifier = types.RelativeTo(pkgMap["neo"])
// prologue
f := fv[0] // proto.go comes first
f := fileMap["proto.go"]
buf := Buffer{}
buf.emit(`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
......@@ -132,6 +160,8 @@ import (
"encoding/binary"
"reflect"
"sort"
"./zodb"
)`)
pktTypeRegistry := map[int]string{} // pktCode -> typename
......@@ -964,8 +994,8 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
// generate size/encode/decode functions for a type declaration typespec
func generateCodecCode(typespec *ast.TypeSpec, codegen CodeGenerator) string {
// type & object which refers to this type
typ := info.Types[typespec.Type].Type
obj := info.Defs[typespec.Name]
typ := typeInfo.Types[typespec.Type].Type
obj := typeInfo.Defs[typespec.Name]
codegen.setFunc("p", typespec.Name.Name, typ)
codegenType("p", typ, obj, codegen)
......
// TODO copyright / license
// Package zodb defines types and interfaces used in ZODB databases
package zodb
// ZODB types
type Tid uint64 // transaction identifier
type Oid uint64 // object identifier
/*
// XXX "extended" oid - oid + serial, completely specifying object revision
type Xid struct {
Tid
Oid
}
*/
// ----------------------------------------
type TxnStatus byte
// TODO Tid.String(), Oid.String() +verbose, scanning (?)
// Information about single storage transaction
// XXX -> storage.ITransactionInformation
//type IStorageTransactionInformation interface {
type StorageTransactionInformation struct {
Tid Tid
Status TxnStatus
User []byte
Description []byte
Extension []byte
// TODO iter -> IStorageRecordInformation
Iter IStorageRecordIterator
}
// Information about single storage record
type StorageRecordInformation struct {
Oid Oid
Tid Tid
Data []byte
// XXX .version ?
// XXX .data_txn (The previous transaction id)
}
type IStorage interface {
Close() error
// TODO:
// Name()
// History(oid, size=1)
// LastTid()
// LoadBefore(oid Oid, beforeTid Tid) (data []bytes, tid Tid, err error)
// LoadSerial(oid Oid, serial Tid) (data []bytes, err error)
// PrefetchBefore(oidv []Oid, beforeTid Tid) error (?)
// Store(oid Oid, serial Tid, data []byte, txn ITransaction) error
// XXX Restore ?
// CheckCurrentSerialInTransaction(oid Oid, serial Tid, txn ITransaction) // XXX naming
// tpc_begin(txn)
// tpc_vote(txn)
// tpc_finish(txn, callback) XXX clarify about callback
// tpc_abort(txn)
Iterate(start, stop Tid) IStorageIterator // XXX -> Iter() ?
}
type IStorageIterator interface {
Next() (*StorageTransactionInformation, error) // XXX -> NextTxn() ?
}
type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
Next() (*StorageRecordInformation, error) // XXX vs ptr & nil ?
// XXX -> NextTxnObject() ?
}
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