Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
f21b6a69
Commit
f21b6a69
authored
Feb 02, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6a8f9f71
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
327 additions
and
285 deletions
+327
-285
t/neo/marshal.go
t/neo/marshal.go
+105
-103
t/neo/neo.go
t/neo/neo.go
+12
-85
t/neo/proto.go
t/neo/proto.go
+85
-83
t/neo/protogen.go
t/neo/protogen.go
+44
-14
t/neo/zodb/zodb.go
t/neo/zodb/zodb.go
+81
-0
No files found.
t/neo/marshal.go
View file @
f21b6a69
This diff is collapsed.
Click to expand it.
t/neo/neo.go
View file @
f21b6a69
...
@@ -4,97 +4,24 @@
...
@@ -4,97 +4,24 @@
// TODO text
// TODO text
package
neo
package
neo
// ZODB types
import
(
// XXX naming -> TID, OID ?
"./zodb"
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
}
*/
const
(
const
(
//INVALID_UUID UUID = 0
//INVALID_UUID UUID = 0
INVALID_TID
Tid
=
1
<<
64
-
1
// 0xffffffffffffffff
INVALID_TID
zodb
.
Tid
=
1
<<
64
-
1
// 0xffffffffffffffff
INVALID_OID
Oid
=
1
<<
64
-
1
INVALID_OID
zodb
.
Oid
=
1
<<
64
-
1
ZERO_TID
Tid
=
0
// XXX or simply TID{} ?
TID0
Tid
=
ZERO_TID
// XXX ^^^ choose 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
// OID_LEN = 8
// TID_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
// SQLite does not accept numbers above 2^63-1
// ZODB also defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016)
// 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() ?
}
t/neo/proto.go
View file @
f21b6a69
...
@@ -6,6 +6,8 @@ package neo
...
@@ -6,6 +6,8 @@ package neo
// XXX move imports out of here
// XXX move imports out of here
import
(
import
(
"./zodb"
"encoding/binary"
"encoding/binary"
"errors"
"errors"
"math"
"math"
...
@@ -281,8 +283,8 @@ type Recovery struct {
...
@@ -281,8 +283,8 @@ type Recovery struct {
type
AnswerRecovery
struct
{
type
AnswerRecovery
struct
{
PTid
PTid
BackupTID
Tid
BackupTID
zodb
.
Tid
TruncateTID
Tid
TruncateTID
zodb
.
Tid
}
}
// Ask the last OID/TID so that a master can initialize its TransactionManager.
// Ask the last OID/TID so that a master can initialize its TransactionManager.
...
@@ -291,8 +293,8 @@ type LastIDs struct {
...
@@ -291,8 +293,8 @@ type LastIDs struct {
}
}
type
AnswerLastIDs
struct
{
type
AnswerLastIDs
struct
{
LastOID
Oid
LastOID
zodb
.
Oid
LastTID
Tid
LastTID
zodb
.
Tid
}
}
// Ask the full partition table. PM -> S.
// Ask the full partition table. PM -> S.
...
@@ -343,9 +345,9 @@ type UnfinishedTransactions struct {
...
@@ -343,9 +345,9 @@ type UnfinishedTransactions struct {
}
}
type
AnswerUnfinishedTransactions
struct
{
type
AnswerUnfinishedTransactions
struct
{
MaxTID
Tid
MaxTID
zodb
.
Tid
TidList
[]
struct
{
TidList
[]
struct
{
UnfinishedTID
Tid
UnfinishedTID
zodb
.
Tid
}
}
}
}
...
@@ -355,77 +357,77 @@ type LockedTransactions struct {
...
@@ -355,77 +357,77 @@ type LockedTransactions struct {
}
}
type
AnswerLockedTransactions
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.
// Return final tid if ttid has been committed. * -> S. C -> PM.
type
FinalTID
struct
{
type
FinalTID
struct
{
TTID
Tid
TTID
zodb
.
Tid
}
}
type
AnswerFinalTID
struct
{
type
AnswerFinalTID
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
// Commit a transaction. PM -> S.
// Commit a transaction. PM -> S.
type
ValidateTransaction
struct
{
type
ValidateTransaction
struct
{
TTID
Tid
TTID
zodb
.
Tid
Tid
Tid
Tid
zodb
.
Tid
}
}
// Ask to begin a new transaction. C -> PM.
// Ask to begin a new transaction. C -> PM.
// Answer when a transaction begin, give a TID if necessary. PM -> C.
// Answer when a transaction begin, give a TID if necessary. PM -> C.
type
BeginTransaction
struct
{
type
BeginTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
type
AnswerBeginTransaction
struct
{
type
AnswerBeginTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
// Finish a transaction. C -> PM.
// Finish a transaction. C -> PM.
// Answer when a transaction is finished. PM -> C.
// Answer when a transaction is finished. PM -> C.
type
FinishTransaction
struct
{
type
FinishTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
OIDList
[]
Oid
OIDList
[]
zodb
.
Oid
CheckedList
[]
Oid
CheckedList
[]
zodb
.
Oid
}
}
type
AnswerFinishTransaction
struct
{
type
AnswerFinishTransaction
struct
{
TTID
Tid
TTID
zodb
.
Tid
Tid
Tid
Tid
zodb
.
Tid
}
}
// Notify that a transaction blocking a replication is now finished
// Notify that a transaction blocking a replication is now finished
// M -> S
// M -> S
type
NotifyTransactionFinished
struct
{
type
NotifyTransactionFinished
struct
{
TTID
Tid
TTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
}
}
// Lock information on a transaction. PM -> S.
// Lock information on a transaction. PM -> S.
// Notify information on a transaction locked. S -> PM.
// Notify information on a transaction locked. S -> PM.
type
LockInformation
struct
{
type
LockInformation
struct
{
Ttid
Tid
Ttid
zodb
.
Tid
Tid
Tid
Tid
zodb
.
Tid
}
}
// XXX AnswerInformationLocked ?
// XXX AnswerInformationLocked ?
type
AnswerLockInformation
struct
{
type
AnswerLockInformation
struct
{
Ttid
Tid
Ttid
zodb
.
Tid
}
}
// Invalidate objects. PM -> C.
// Invalidate objects. PM -> C.
// XXX ask_finish_transaction ?
// XXX ask_finish_transaction ?
type
InvalidateObjects
struct
{
type
InvalidateObjects
struct
{
Tid
Tid
Tid
zodb
.
Tid
OidList
[]
Oid
OidList
[]
zodb
.
Oid
}
}
// Unlock information on a transaction. PM -> S.
// Unlock information on a transaction. PM -> S.
type
UnlockInformation
struct
{
type
UnlockInformation
struct
{
TTID
Tid
TTID
zodb
.
Tid
}
}
// Ask new object IDs. C -> PM.
// Ask new object IDs. C -> PM.
...
@@ -436,7 +438,7 @@ type GenerateOIDs struct {
...
@@ -436,7 +438,7 @@ type GenerateOIDs struct {
// XXX answer_new_oids ?
// XXX answer_new_oids ?
type
AnswerGenerateOIDs
struct
{
type
AnswerGenerateOIDs
struct
{
OidList
[]
Oid
OidList
[]
zodb
.
Oid
}
}
...
@@ -447,42 +449,42 @@ type AnswerGenerateOIDs struct {
...
@@ -447,42 +449,42 @@ type AnswerGenerateOIDs struct {
// if this serial is newer than the current transaction ID, a client
// if this serial is newer than the current transaction ID, a client
// node must not try to resolve the conflict. S -> C.
// node must not try to resolve the conflict. S -> C.
type
StoreObject
struct
{
type
StoreObject
struct
{
Oid
Oid
Oid
zodb
.
Oid
Serial
Tid
Serial
zodb
.
Tid
Compression
bool
Compression
bool
Checksum
Checksum
Checksum
Checksum
Data
[]
byte
// TODO separately (for writev)
Data
[]
byte
// TODO separately (for writev)
DataSerial
Tid
DataSerial
zodb
.
Tid
Tid
Tid
Tid
zodb
.
Tid
Unlock
bool
Unlock
bool
}
}
type
AnswerStoreObject
struct
{
type
AnswerStoreObject
struct
{
Conflicting
bool
Conflicting
bool
Oid
Oid
Oid
zodb
.
Oid
Serial
Tid
Serial
zodb
.
Tid
}
}
// Abort a transaction. C -> S, PM.
// Abort a transaction. C -> S, PM.
type
AbortTransaction
struct
{
type
AbortTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
// Ask to store a transaction. C -> S.
// Ask to store a transaction. C -> S.
// Answer if transaction has been stored. S -> C.
// Answer if transaction has been stored. S -> C.
type
StoreTransaction
struct
{
type
StoreTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
User
string
User
string
Description
string
Description
string
Extension
string
Extension
string
OidList
[]
Oid
OidList
[]
zodb
.
Oid
// TODO _answer = PFEmpty
// TODO _answer = PFEmpty
}
}
// Ask to store a transaction. C -> S.
// Ask to store a transaction. C -> S.
// Answer if transaction has been stored. S -> C.
// Answer if transaction has been stored. S -> C.
type
VoteTransaction
struct
{
type
VoteTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
// TODO _answer = PFEmpty
// TODO _answer = PFEmpty
}
}
...
@@ -491,20 +493,20 @@ type VoteTransaction struct {
...
@@ -491,20 +493,20 @@ type VoteTransaction struct {
// a TID is specified, an object right before the TID will be returned. C -> S.
// a TID is specified, an object right before the TID will be returned. C -> S.
// Answer the requested object. S -> C.
// Answer the requested object. S -> C.
type
GetObject
struct
{
type
GetObject
struct
{
Oid
Oid
Oid
zodb
.
Oid
Serial
Tid
Serial
zodb
.
Tid
Tid
Tid
Tid
zodb
.
Tid
}
}
// XXX answer_object ?
// XXX answer_object ?
type
AnswerGetObject
struct
{
type
AnswerGetObject
struct
{
Oid
Oid
Oid
zodb
.
Oid
SerialStart
Tid
SerialStart
zodb
.
Tid
SerialEnd
Tid
SerialEnd
zodb
.
Tid
Compression
bool
Compression
bool
Checksum
Checksum
Checksum
Checksum
Data
[]
byte
// TODO separately (for writev)
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,
// Ask for TIDs between a range of offsets. The order of TIDs is descending,
...
@@ -518,52 +520,52 @@ type TIDList struct {
...
@@ -518,52 +520,52 @@ type TIDList struct {
// XXX answer_tids ?
// XXX answer_tids ?
type
AnswerTIDList
struct
{
type
AnswerTIDList
struct
{
TIDList
[]
Tid
TIDList
[]
zodb
.
Tid
}
}
// Ask for length TIDs starting at min_tid. The order of TIDs is ascending.
// Ask for length TIDs starting at min_tid. The order of TIDs is ascending.
// C -> S.
// C -> S.
// Answer the requested TIDs. S -> C
// Answer the requested TIDs. S -> C
type
TIDListFrom
struct
{
type
TIDListFrom
struct
{
MinTID
Tid
MinTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
Length
uint32
// PNumber
Length
uint32
// PNumber
Partition
uint32
// PNumber
Partition
uint32
// PNumber
}
}
// XXX answer_tids ?
// XXX answer_tids ?
type
AnswerTIDListFrom
struct
{
type
AnswerTIDListFrom
struct
{
TidList
[]
Tid
TidList
[]
zodb
.
Tid
}
}
// Ask information about a transaction. Any -> S.
// Ask information about a transaction. Any -> S.
// Answer information (user, description) about a transaction. S -> Any.
// Answer information (user, description) about a transaction. S -> Any.
type
TransactionInformation
struct
{
type
TransactionInformation
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
type
AnswerTransactionInformation
struct
{
type
AnswerTransactionInformation
struct
{
Tid
Tid
Tid
zodb
.
Tid
User
string
User
string
Description
string
Description
string
Extension
string
Extension
string
Packed
bool
Packed
bool
OidList
[]
Oid
OidList
[]
zodb
.
Oid
}
}
// Ask history information for a given object. The order of serials is
// Ask history information for a given object. The order of serials is
// descending, and the range is [first, last]. C -> S.
// descending, and the range is [first, last]. C -> S.
// Answer history information (serial, size) for an object. S -> C.
// Answer history information (serial, size) for an object. S -> C.
type
ObjectHistory
struct
{
type
ObjectHistory
struct
{
Oid
Oid
Oid
zodb
.
Oid
First
uint64
// PIndex XXX this is actually TID
First
uint64
// PIndex XXX this is actually TID
Last
uint64
// PIndex ----//----
Last
uint64
// PIndex ----//----
}
}
type
AnswerObjectHistory
struct
{
type
AnswerObjectHistory
struct
{
Oid
Oid
Oid
zodb
.
Oid
HistoryList
[]
struct
{
HistoryList
[]
struct
{
Serial
Tid
Serial
zodb
.
Tid
Size
uint32
// PNumber
Size
uint32
// PNumber
}
}
}
}
...
@@ -677,17 +679,17 @@ type X_ClusterState struct { // XXX conflicts with ClusterState enum
...
@@ -677,17 +679,17 @@ type X_ClusterState struct { // XXX conflicts with ClusterState enum
// If current_serial's data is current on storage.
// If current_serial's data is current on storage.
// S -> C
// S -> C
type
ObjectUndoSerial
struct
{
type
ObjectUndoSerial
struct
{
Tid
Tid
Tid
zodb
.
Tid
LTID
Tid
LTID
zodb
.
Tid
UndoneTID
Tid
UndoneTID
zodb
.
Tid
OidList
[]
Oid
OidList
[]
zodb
.
Oid
}
}
// XXX answer_undo_transaction ?
// XXX answer_undo_transaction ?
type
AnswerObjectUndoSerial
struct
{
type
AnswerObjectUndoSerial
struct
{
ObjectTIDDict
map
[
Oid
]
struct
{
ObjectTIDDict
map
[
zodb
.
Oid
]
struct
{
CurrentSerial
Tid
CurrentSerial
zodb
.
Tid
UndoSerial
Tid
UndoSerial
zodb
.
Tid
IsCurrent
bool
IsCurrent
bool
}
}
}
}
...
@@ -696,12 +698,12 @@ type AnswerObjectUndoSerial struct {
...
@@ -696,12 +698,12 @@ type AnswerObjectUndoSerial struct {
// C -> S
// C -> S
// Answer whether a transaction holds the write lock for requested object.
// Answer whether a transaction holds the write lock for requested object.
type
HasLock
struct
{
type
HasLock
struct
{
Tid
Tid
Tid
zodb
.
Tid
Oid
Oid
Oid
zodb
.
Oid
}
}
type
AnswerHasLock
struct
{
type
AnswerHasLock
struct
{
Oid
Oid
Oid
zodb
.
Oid
LockState
LockState
LockState
LockState
}
}
...
@@ -713,16 +715,16 @@ type AnswerHasLock struct {
...
@@ -713,16 +715,16 @@ type AnswerHasLock struct {
// Same structure as AnswerStoreObject, to handle the same way, except there
// Same structure as AnswerStoreObject, to handle the same way, except there
// is nothing to invalidate in any client's cache.
// is nothing to invalidate in any client's cache.
type
CheckCurrentSerial
struct
{
type
CheckCurrentSerial
struct
{
Tid
Tid
Tid
zodb
.
Tid
Serial
Tid
Serial
zodb
.
Tid
Oid
Oid
Oid
zodb
.
Oid
}
}
// XXX answer_store_object ?
// XXX answer_store_object ?
type
AnswerCheckCurrentSerial
struct
{
type
AnswerCheckCurrentSerial
struct
{
Conflicting
bool
Conflicting
bool
Oid
Oid
Oid
zodb
.
Oid
Serial
Tid
Serial
zodb
.
Tid
}
}
// Request a pack at given TID.
// Request a pack at given TID.
...
@@ -732,7 +734,7 @@ type AnswerCheckCurrentSerial struct {
...
@@ -732,7 +734,7 @@ type AnswerCheckCurrentSerial struct {
// S -> M
// S -> M
// M -> C
// M -> C
type
Pack
struct
{
type
Pack
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
type
AnswerPack
struct
{
type
AnswerPack
struct
{
...
@@ -744,8 +746,8 @@ type AnswerPack struct {
...
@@ -744,8 +746,8 @@ type AnswerPack struct {
// A -> M
// A -> M
type
CheckReplicas
struct
{
type
CheckReplicas
struct
{
PartitionDict
map
[
uint32
]
UUID
// partition -> source (PNumber)
PartitionDict
map
[
uint32
]
UUID
// partition -> source (PNumber)
MinTID
Tid
MinTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
// XXX _answer = Error
// XXX _answer = Error
}
}
...
@@ -757,8 +759,8 @@ type CheckPartition struct {
...
@@ -757,8 +759,8 @@ type CheckPartition struct {
UpstreamName
string
UpstreamName
string
Address
Address
Address
Address
}
}
MinTID
Tid
MinTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
}
}
...
@@ -773,14 +775,14 @@ type CheckPartition struct {
...
@@ -773,14 +775,14 @@ type CheckPartition struct {
type
CheckTIDRange
struct
{
type
CheckTIDRange
struct
{
Partition
uint32
// PNumber
Partition
uint32
// PNumber
Length
uint32
// PNumber
Length
uint32
// PNumber
MinTID
Tid
MinTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
}
}
type
AnswerCheckTIDRange
struct
{
type
AnswerCheckTIDRange
struct
{
Count
uint32
// PNumber
Count
uint32
// PNumber
Checksum
Checksum
Checksum
Checksum
MaxTID
Tid
MaxTID
zodb
.
Tid
}
}
// Ask some stats about a range of object history.
// Ask some stats about a range of object history.
...
@@ -794,17 +796,17 @@ type AnswerCheckTIDRange struct {
...
@@ -794,17 +796,17 @@ type AnswerCheckTIDRange struct {
type
CheckSerialRange
struct
{
type
CheckSerialRange
struct
{
Partition
uint32
// PNumber
Partition
uint32
// PNumber
Length
uint32
// PNumber
Length
uint32
// PNumber
MinTID
Tid
MinTID
zodb
.
Tid
MaxTID
Tid
MaxTID
zodb
.
Tid
MinOID
Oid
MinOID
zodb
.
Oid
}
}
type
AnswerCheckSerialRange
struct
{
type
AnswerCheckSerialRange
struct
{
Count
uint32
// PNumber
Count
uint32
// PNumber
TidChecksum
Checksum
TidChecksum
Checksum
MaxTID
Tid
MaxTID
zodb
.
Tid
OidChecksum
Checksum
OidChecksum
Checksum
MaxOID
Oid
MaxOID
zodb
.
Oid
}
}
// S -> M
// S -> M
...
@@ -822,7 +824,7 @@ type LastTransaction struct {
...
@@ -822,7 +824,7 @@ type LastTransaction struct {
}
}
type
AnswerLastTransaction
struct
{
type
AnswerLastTransaction
struct
{
Tid
Tid
Tid
zodb
.
Tid
}
}
...
...
t/neo/protogen.go
View file @
f21b6a69
...
@@ -71,7 +71,9 @@ import (
...
@@ -71,7 +71,9 @@ import (
// parsed & typechecked input
// parsed & typechecked input
var
fset
=
token
.
NewFileSet
()
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
),
Types
:
make
(
map
[
ast
.
Expr
]
types
.
TypeAndValue
),
Defs
:
make
(
map
[
*
ast
.
Ident
]
types
.
Object
),
Defs
:
make
(
map
[
*
ast
.
Ident
]
types
.
Object
),
}
}
...
@@ -97,33 +99,59 @@ func (b *Buffer) emit(format string, a ...interface{}) {
...
@@ -97,33 +99,59 @@ func (b *Buffer) emit(format string, a ...interface{}) {
}
}
func
main
()
{
// importer that takes into account our already-loaded packages
var
err
error
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
return
li
.
Importer
.
Import
(
path
)
var
fv
[]
*
ast
.
File
}
for
_
,
src
:=
range
[]
string
{
"proto.go"
,
"neo.go"
}
{
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
)
f
,
err
:=
parser
.
ParseFile
(
fset
,
src
,
nil
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"parse: %v"
,
err
)
log
.
Fatalf
(
"parse: %v"
,
err
)
}
}
fv
=
append
(
fv
,
f
)
fileMap
[
src
]
=
f
filev
=
append
(
filev
,
f
)
}
}
//ast.Print(fset, fv[0])
//ast.Print(fset, fv[0])
//return
//return
conf
:=
types
.
Config
{
Importer
:
importer
.
Default
()}
// typecheck
neoPkg
,
err
:=
conf
.
Check
(
"neo"
,
fset
,
fv
,
info
)
conf
:=
types
.
Config
{
Importer
:
&
localImporter
{
importer
.
Default
()}}
pkg
,
err
:=
conf
.
Check
(
pkgName
,
fset
,
filev
,
typeInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"typecheck: %v"
,
err
)
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
// prologue
f
:=
f
v
[
0
]
// proto.go comes first
f
:=
f
ileMap
[
"proto.go"
]
buf
:=
Buffer
{}
buf
:=
Buffer
{}
buf
.
emit
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
buf
.
emit
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
...
@@ -132,6 +160,8 @@ import (
...
@@ -132,6 +160,8 @@ import (
"encoding/binary"
"encoding/binary"
"reflect"
"reflect"
"sort"
"sort"
"./zodb"
)`
)
)`
)
pktTypeRegistry
:=
map
[
int
]
string
{}
// pktCode -> typename
pktTypeRegistry
:=
map
[
int
]
string
{}
// pktCode -> typename
...
@@ -964,8 +994,8 @@ func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGene
...
@@ -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
// generate size/encode/decode functions for a type declaration typespec
func
generateCodecCode
(
typespec
*
ast
.
TypeSpec
,
codegen
CodeGenerator
)
string
{
func
generateCodecCode
(
typespec
*
ast
.
TypeSpec
,
codegen
CodeGenerator
)
string
{
// type & object which refers to this type
// type & object which refers to this type
typ
:=
i
nfo
.
Types
[
typespec
.
Type
]
.
Type
typ
:=
typeI
nfo
.
Types
[
typespec
.
Type
]
.
Type
obj
:=
i
nfo
.
Defs
[
typespec
.
Name
]
obj
:=
typeI
nfo
.
Defs
[
typespec
.
Name
]
codegen
.
setFunc
(
"p"
,
typespec
.
Name
.
Name
,
typ
)
codegen
.
setFunc
(
"p"
,
typespec
.
Name
.
Name
,
typ
)
codegenType
(
"p"
,
typ
,
obj
,
codegen
)
codegenType
(
"p"
,
typ
,
obj
,
codegen
)
...
...
t/neo/zodb/zodb.go
0 → 100644
View file @
f21b6a69
// 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() ?
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment