Commit 63875e79 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 69a02de9
package proto package neo
//package proto
/*
import ( import (
. "../" . "../"
) )
*/
const ( const (
PROTOCOL_VERSION = 8 PROTOCOL_VERSION = 8
MIN_PACKET_SIZE = 10 // XXX link this to len(pkthead) ? MIN_PACKET_SIZE = 10 // XXX link this to len(pkthead) ?
PktHeadLen = MIN_PACKET_SIZE // TODO link this to PktHead.Encode/Decode size
MAX_PACKET_SIZE = 0x4000000 MAX_PACKET_SIZE = 0x4000000
RESPONSE_MASK = 0x800 RESPONSE_MASK = 0x800
...@@ -122,8 +126,7 @@ type RowList []struct { ...@@ -122,8 +126,7 @@ type RowList []struct {
// XXX link request <-> answer ? // XXX link request <-> answer ?
// TODO ensure len(encoded packet header) == 10 // TODO ensure len(encoded packet header) == 10
// XXX -> PktHeader ? type PktHead struct {
type Packet struct {
Id uint32 Id uint32
Code uint16 // XXX we don't need this as field - this is already encoded in type Code uint16 // XXX we don't need this as field - this is already encoded in type
Len uint32 // XXX we don't need this as field - only on the wire Len uint32 // XXX we don't need this as field - only on the wire
...@@ -133,7 +136,7 @@ type Packet struct { ...@@ -133,7 +136,7 @@ type Packet struct {
// General purpose notification (remote logging) // General purpose notification (remote logging)
type Notify struct { type Notify struct {
Packet PktHead
Message string Message string
} }
...@@ -141,26 +144,26 @@ type Notify struct { ...@@ -141,26 +144,26 @@ type Notify struct {
// any other message, even if such a message does not expect a reply // any other message, even if such a message does not expect a reply
// usually. Any -> Any. // usually. Any -> Any.
type Error struct { type Error struct {
Packet PktHead
Code uint32 // PNumber Code uint32 // PNumber
Message string Message string
} }
// Check if a peer is still alive. Any -> Any. // Check if a peer is still alive. Any -> Any.
type Ping struct { type Ping struct {
Packet PktHead
// TODO _answer = PFEmpty // TODO _answer = PFEmpty
} }
// Tell peer it can close the connection if it has finished with us. Any -> Any // Tell peer it can close the connection if it has finished with us. Any -> Any
type CloseClient struct { type CloseClient struct {
Packet PktHead
} }
// Request a node identification. This must be the first packet for any // Request a node identification. This must be the first packet for any
// connection. Any -> Any. // connection. Any -> Any.
type RequestIdentification struct { type RequestIdentification struct {
Packet PktHead
ProtocolVersion uint32 // TODO py.PProtocol upon decoding checks for != PROTOCOL_VERSION ProtocolVersion uint32 // TODO py.PProtocol upon decoding checks for != PROTOCOL_VERSION
NodeType NodeType // XXX name NodeType NodeType // XXX name
UUID UUID UUID UUID
...@@ -171,7 +174,7 @@ type RequestIdentification struct { ...@@ -171,7 +174,7 @@ type RequestIdentification struct {
// XXX -> ReplyIdentification? RequestIdentification.Answer somehow ? // XXX -> ReplyIdentification? RequestIdentification.Answer somehow ?
type AcceptIdentification struct { type AcceptIdentification struct {
Packet PktHead
NodeType NodeType // XXX name NodeType NodeType // XXX name
MyUUID UUID MyUUID UUID
NumPartitions uint32 // PNumber NumPartitions uint32 // PNumber
...@@ -186,31 +189,31 @@ type AcceptIdentification struct { ...@@ -186,31 +189,31 @@ type AcceptIdentification struct {
// Ask current primary master's uuid. CTL -> A. // Ask current primary master's uuid. CTL -> A.
type PrimaryMaster struct { type PrimaryMaster struct {
Packet PktHead
} }
type AnswerPrimary struct { type AnswerPrimary struct {
Packet PktHead
PrimaryUUID UUID PrimaryUUID UUID
} }
// Announce a primary master node election. PM -> SM. // Announce a primary master node election. PM -> SM.
type AnnouncePrimary struct { type AnnouncePrimary struct {
Packet PktHead
} }
// Force a re-election of a primary master node. M -> M. // Force a re-election of a primary master node. M -> M.
type ReelectPrimary struct { type ReelectPrimary struct {
Packet PktHead
} }
// Ask all data needed by master to recover. PM -> S, S -> PM. // Ask all data needed by master to recover. PM -> S, S -> PM.
type Recovery struct { type Recovery struct {
Packet PktHead
} }
type AnswerRecovery struct { type AnswerRecovery struct {
Packet PktHead
PTid PTid
BackupTID Tid BackupTID Tid
TruncateTID Tid TruncateTID Tid
...@@ -219,11 +222,11 @@ type AnswerRecovery struct { ...@@ -219,11 +222,11 @@ type AnswerRecovery struct {
// 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.
// PM -> S, S -> PM. // PM -> S, S -> PM.
type LastIDs struct { type LastIDs struct {
Packet PktHead
} }
type AnswerLastIDs struct { type AnswerLastIDs struct {
Packet PktHead
LastOID Oid LastOID Oid
LastTID Tid LastTID Tid
} }
...@@ -231,11 +234,11 @@ type AnswerLastIDs struct { ...@@ -231,11 +234,11 @@ type AnswerLastIDs struct {
// Ask the full partition table. PM -> S. // Ask the full partition table. PM -> S.
// Answer rows in a partition table. S -> PM. // Answer rows in a partition table. S -> PM.
type PartitionTable struct { type PartitionTable struct {
Packet PktHead
} }
type AnswerPartitionTable struct { type AnswerPartitionTable struct {
Packet PktHead
PTid PTid
RowList RowList RowList RowList
} }
...@@ -243,7 +246,7 @@ type AnswerPartitionTable struct { ...@@ -243,7 +246,7 @@ type AnswerPartitionTable struct {
// Send rows in a partition table to update other nodes. PM -> S, C. // Send rows in a partition table to update other nodes. PM -> S, C.
type NotifyPartitionTable struct { type NotifyPartitionTable struct {
Packet PktHead
PTid PTid
RowList RowList RowList RowList
} }
...@@ -251,7 +254,7 @@ type NotifyPartitionTable struct { ...@@ -251,7 +254,7 @@ type NotifyPartitionTable struct {
// Notify a subset of a partition table. This is used to notify changes. // Notify a subset of a partition table. This is used to notify changes.
// PM -> S, C. // PM -> S, C.
type PartitionChanges struct { type PartitionChanges struct {
Packet PktHead
PTid PTid
CellList []struct { CellList []struct {
...@@ -265,7 +268,7 @@ type PartitionChanges struct { ...@@ -265,7 +268,7 @@ type PartitionChanges struct {
// Tell a storage nodes to start an operation. Until a storage node receives // Tell a storage nodes to start an operation. Until a storage node receives
// this message, it must not serve client nodes. PM -> S. // this message, it must not serve client nodes. PM -> S.
type StartOperation struct { type StartOperation struct {
Packet PktHead
// XXX: Is this boolean needed ? Maybe this // XXX: Is this boolean needed ? Maybe this
// can be deduced from cluster state. // can be deduced from cluster state.
Backup bool Backup bool
...@@ -274,17 +277,17 @@ type StartOperation struct { ...@@ -274,17 +277,17 @@ type StartOperation struct {
// Tell a storage node to stop an operation. Once a storage node receives // Tell a storage node to stop an operation. Once a storage node receives
// this message, it must not serve client nodes. PM -> S. // this message, it must not serve client nodes. PM -> S.
type StopOperation struct { type StopOperation struct {
Packet PktHead
} }
// Ask unfinished transactions S -> PM. // Ask unfinished transactions S -> PM.
// Answer unfinished transactions PM -> S. // Answer unfinished transactions PM -> S.
type UnfinishedTransactions struct { type UnfinishedTransactions struct {
Packet PktHead
} }
type AnswerUnfinishedTransactions struct { type AnswerUnfinishedTransactions struct {
Packet PktHead
MaxTID Tid MaxTID Tid
TidList []struct{ TidList []struct{
UnfinishedTID Tid UnfinishedTID Tid
...@@ -294,28 +297,28 @@ type AnswerUnfinishedTransactions struct { ...@@ -294,28 +297,28 @@ type AnswerUnfinishedTransactions struct {
// Ask locked transactions PM -> S. // Ask locked transactions PM -> S.
// Answer locked transactions S -> PM. // Answer locked transactions S -> PM.
type LockedTransactions struct { type LockedTransactions struct {
Packet PktHead
} }
type AnswerLockedTransactions struct { type AnswerLockedTransactions struct {
Packet PktHead
TidDict map[Tid]Tid // ttid -> tid TidDict map[Tid]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 {
Packet PktHead
TTID Tid TTID Tid
} }
type AnswerFinalTID struct { type AnswerFinalTID struct {
Packet PktHead
Tid Tid Tid Tid
} }
// Commit a transaction. PM -> S. // Commit a transaction. PM -> S.
type ValidateTransaction struct { type ValidateTransaction struct {
Packet PktHead
TTID Tid TTID Tid
Tid Tid Tid Tid
} }
...@@ -324,26 +327,26 @@ type ValidateTransaction struct { ...@@ -324,26 +327,26 @@ type ValidateTransaction struct {
// 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 {
Packet PktHead
Tid Tid Tid Tid
} }
type AnswerBeginTransaction struct { type AnswerBeginTransaction struct {
Packet PktHead
Tid Tid Tid 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 {
Packet PktHead
Tid Tid Tid Tid
OIDList []Oid OIDList []Oid
CheckedList []Oid CheckedList []Oid
} }
type AnswerFinishTransaction struct { type AnswerFinishTransaction struct {
Packet PktHead
TTID Tid TTID Tid
Tid Tid Tid Tid
} }
...@@ -351,7 +354,7 @@ type AnswerFinishTransaction struct { ...@@ -351,7 +354,7 @@ type AnswerFinishTransaction struct {
// 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 {
Packet PktHead
TTID Tid TTID Tid
MaxTID Tid MaxTID Tid
} }
...@@ -359,7 +362,7 @@ type NotifyTransactionFinished struct { ...@@ -359,7 +362,7 @@ type NotifyTransactionFinished struct {
// 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 {
Packet PktHead
Ttid Tid Ttid Tid
Tid Tid Tid Tid
} }
...@@ -372,27 +375,27 @@ type AnswerLockInformation struct { ...@@ -372,27 +375,27 @@ type AnswerLockInformation struct {
// Invalidate objects. PM -> C. // Invalidate objects. PM -> C.
// XXX ask_finish_transaction ? // XXX ask_finish_transaction ?
type InvalidateObjects struct { type InvalidateObjects struct {
Packet PktHead
Tid Tid Tid Tid
OidList []Oid OidList []Oid
} }
// Unlock information on a transaction. PM -> S. // Unlock information on a transaction. PM -> S.
type UnlockInformation struct { type UnlockInformation struct {
Packet PktHead
TTID Tid TTID Tid
} }
// Ask new object IDs. C -> PM. // Ask new object IDs. C -> PM.
// Answer new object IDs. PM -> C. // Answer new object IDs. PM -> C.
type GenerateOIDs struct { type GenerateOIDs struct {
Packet PktHead
NumOIDs uint32 // PNumber NumOIDs uint32 // PNumber
} }
// XXX answer_new_oids ? // XXX answer_new_oids ?
type AnswerGenerateOIDs struct { type AnswerGenerateOIDs struct {
Packet PktHead
OidList []Oid OidList []Oid
} }
...@@ -404,7 +407,7 @@ type AnswerGenerateOIDs struct { ...@@ -404,7 +407,7 @@ 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 {
Packet PktHead
Oid Oid Oid Oid
Serial Tid Serial Tid
Compression bool Compression bool
...@@ -416,7 +419,7 @@ type StoreObject struct { ...@@ -416,7 +419,7 @@ type StoreObject struct {
} }
type AnswerStoreObject struct { type AnswerStoreObject struct {
Packet PktHead
Conflicting bool Conflicting bool
Oid Oid Oid Oid
Serial Tid Serial Tid
...@@ -424,14 +427,14 @@ type AnswerStoreObject struct { ...@@ -424,14 +427,14 @@ type AnswerStoreObject struct {
// Abort a transaction. C -> S, PM. // Abort a transaction. C -> S, PM.
type AbortTransaction struct { type AbortTransaction struct {
Packet PktHead
Tid Tid Tid 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 {
Packet PktHead
Tid Tid Tid Tid
User string User string
Description string Description string
...@@ -443,7 +446,7 @@ type StoreTransaction struct { ...@@ -443,7 +446,7 @@ type StoreTransaction struct {
// 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 {
Packet PktHead
Tid Tid Tid Tid
// TODO _answer = PFEmpty // TODO _answer = PFEmpty
} }
...@@ -453,7 +456,7 @@ type VoteTransaction struct { ...@@ -453,7 +456,7 @@ 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 {
Packet PktHead
Oid Oid Oid Oid
Serial Tid Serial Tid
Tid Tid Tid Tid
...@@ -461,7 +464,7 @@ type GetObject struct { ...@@ -461,7 +464,7 @@ type GetObject struct {
// XXX answer_object ? // XXX answer_object ?
type AnswerGetObject struct { type AnswerGetObject struct {
Packet PktHead
Oid Oid Oid Oid
SerialStart Tid SerialStart Tid
SerialEnd Tid SerialEnd Tid
...@@ -475,7 +478,7 @@ type AnswerGetObject struct { ...@@ -475,7 +478,7 @@ type AnswerGetObject struct {
// and the range is [first, last). C -> S. // and the range is [first, last). C -> S.
// Answer the requested TIDs. S -> C. // Answer the requested TIDs. S -> C.
type TIDList struct { type TIDList struct {
Packet PktHead
First uint64 // PIndex XXX this is TID actually ? -> no it is offset in list First uint64 // PIndex XXX this is TID actually ? -> no it is offset in list
Last uint64 // PIndex ----//---- Last uint64 // PIndex ----//----
Partition uint32 // PNumber Partition uint32 // PNumber
...@@ -483,7 +486,7 @@ type TIDList struct { ...@@ -483,7 +486,7 @@ type TIDList struct {
// XXX answer_tids ? // XXX answer_tids ?
type AnswerTIDList struct { type AnswerTIDList struct {
Packet PktHead
TIDList []Tid TIDList []Tid
} }
...@@ -491,7 +494,7 @@ type AnswerTIDList struct { ...@@ -491,7 +494,7 @@ type AnswerTIDList struct {
// C -> S. // C -> S.
// Answer the requested TIDs. S -> C // Answer the requested TIDs. S -> C
type TIDListFrom struct { type TIDListFrom struct {
Packet PktHead
MinTID Tid MinTID Tid
MaxTID Tid MaxTID Tid
Length uint32 // PNumber Length uint32 // PNumber
...@@ -500,19 +503,19 @@ type TIDListFrom struct { ...@@ -500,19 +503,19 @@ type TIDListFrom struct {
// XXX answer_tids ? // XXX answer_tids ?
type AnswerTIDListFrom struct { type AnswerTIDListFrom struct {
Packet PktHead
TidList []Tid TidList []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 {
Packet PktHead
Tid Tid Tid Tid
} }
type AnswerTransactionInformation struct { type AnswerTransactionInformation struct {
Packet PktHead
Tid Tid Tid Tid
User string User string
Description string Description string
...@@ -525,14 +528,14 @@ type AnswerTransactionInformation struct { ...@@ -525,14 +528,14 @@ type AnswerTransactionInformation struct {
// 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 {
Packet PktHead
Oid Oid Oid 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 {
Packet PktHead
Oid Oid Oid Oid
HistoryList []struct { HistoryList []struct {
Serial Tid Serial Tid
...@@ -544,14 +547,14 @@ type AnswerObjectHistory struct { ...@@ -544,14 +547,14 @@ type AnswerObjectHistory struct {
// Ask information about partition // Ask information about partition
// Answer information about partition // Answer information about partition
type PartitionList struct { type PartitionList struct {
Packet PktHead
MinOffset uint32 // PNumber MinOffset uint32 // PNumber
MaxOffset uint32 // PNumber MaxOffset uint32 // PNumber
UUID UUID UUID UUID
} }
type AnswerPartitionList struct { type AnswerPartitionList struct {
Packet PktHead
PTid PTid
RowList RowList RowList RowList
} }
...@@ -559,18 +562,18 @@ type AnswerPartitionList struct { ...@@ -559,18 +562,18 @@ type AnswerPartitionList struct {
// Ask information about nodes // Ask information about nodes
// Answer information about nodes // Answer information about nodes
type X_NodeList struct { type X_NodeList struct {
Packet PktHead
NodeType NodeType
} }
type AnswerNodeList struct { type AnswerNodeList struct {
Packet PktHead
NodeList []NodeInfo NodeList []NodeInfo
} }
// Set the node state // Set the node state
type SetNodeState struct { type SetNodeState struct {
Packet PktHead
UUID UUID
NodeState NodeState
...@@ -579,7 +582,7 @@ type SetNodeState struct { ...@@ -579,7 +582,7 @@ type SetNodeState struct {
// Ask the primary to include some pending node in the partition table // Ask the primary to include some pending node in the partition table
type AddPendingNodes struct { type AddPendingNodes struct {
Packet PktHead
UUIDList []UUID UUIDList []UUID
// XXX _answer = Error // XXX _answer = Error
...@@ -587,7 +590,7 @@ type AddPendingNodes struct { ...@@ -587,7 +590,7 @@ type AddPendingNodes struct {
// Ask the primary to optimize the partition table. A -> PM. // Ask the primary to optimize the partition table. A -> PM.
type TweakPartitionTable struct { type TweakPartitionTable struct {
Packet PktHead
UUIDList []UUID UUIDList []UUID
// XXX _answer = Error // XXX _answer = Error
...@@ -595,19 +598,19 @@ type TweakPartitionTable struct { ...@@ -595,19 +598,19 @@ type TweakPartitionTable struct {
// Notify information about one or more nodes. PM -> Any. // Notify information about one or more nodes. PM -> Any.
type NotifyNodeInformation struct { type NotifyNodeInformation struct {
Packet PktHead
NodeList []NodeInfo NodeList []NodeInfo
} }
// Ask node information // Ask node information
type NodeInformation struct { type NodeInformation struct {
Packet PktHead
// XXX _answer = PFEmpty // XXX _answer = PFEmpty
} }
// Set the cluster state // Set the cluster state
type SetClusterState struct { type SetClusterState struct {
Packet PktHead
State ClusterState State ClusterState
// XXX _answer = Error // XXX _answer = Error
...@@ -615,14 +618,14 @@ type SetClusterState struct { ...@@ -615,14 +618,14 @@ type SetClusterState struct {
// Notify information about the cluster // Notify information about the cluster
type ClusterInformation struct { type ClusterInformation struct {
Packet PktHead
State ClusterState State ClusterState
} }
// Ask state of the cluster // Ask state of the cluster
// Answer state of the cluster // Answer state of the cluster
type X_ClusterState struct { // XXX conflicts with ClusterState enum type X_ClusterState struct { // XXX conflicts with ClusterState enum
Packet PktHead
State ClusterState State ClusterState
} }
...@@ -642,7 +645,7 @@ type X_ClusterState struct { // XXX conflicts with ClusterState enum ...@@ -642,7 +645,7 @@ 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 {
Packet PktHead
Tid Tid Tid Tid
LTID Tid LTID Tid
UndoneTID Tid UndoneTID Tid
...@@ -651,7 +654,7 @@ type ObjectUndoSerial struct { ...@@ -651,7 +654,7 @@ type ObjectUndoSerial struct {
// XXX answer_undo_transaction ? // XXX answer_undo_transaction ?
type AnswerObjectUndoSerial struct { type AnswerObjectUndoSerial struct {
Packet PktHead
ObjectTIDDict map[Oid]struct { ObjectTIDDict map[Oid]struct {
CurrentSerial Tid CurrentSerial Tid
UndoSerial Tid UndoSerial Tid
...@@ -663,13 +666,13 @@ type AnswerObjectUndoSerial struct { ...@@ -663,13 +666,13 @@ 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 {
Packet PktHead
Tid Tid Tid Tid
Oid Oid Oid Oid
} }
type AnswerHasLock struct { type AnswerHasLock struct {
Packet PktHead
Oid Oid Oid Oid
LockState LockState LockState LockState
} }
...@@ -682,7 +685,7 @@ type AnswerHasLock struct { ...@@ -682,7 +685,7 @@ 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 {
Packet PktHead
Tid Tid Tid Tid
Serial Tid Serial Tid
Oid Oid Oid Oid
...@@ -702,12 +705,12 @@ type AnswerCheckCurrentSerial struct { ...@@ -702,12 +705,12 @@ type AnswerCheckCurrentSerial struct {
// S -> M // S -> M
// M -> C // M -> C
type Pack struct { type Pack struct {
Packet PktHead
Tid Tid Tid Tid
} }
type AnswerPack struct { type AnswerPack struct {
Packet PktHead
Status bool Status bool
} }
...@@ -715,7 +718,7 @@ type AnswerPack struct { ...@@ -715,7 +718,7 @@ type AnswerPack struct {
// ctl -> A // ctl -> A
// A -> M // A -> M
type CheckReplicas struct { type CheckReplicas struct {
Packet PktHead
PartitionDict map[uint32/*PNumber*/]UUID // partition -> source PartitionDict map[uint32/*PNumber*/]UUID // partition -> source
MinTID Tid MinTID Tid
MaxTID Tid MaxTID Tid
...@@ -725,7 +728,7 @@ type CheckReplicas struct { ...@@ -725,7 +728,7 @@ type CheckReplicas struct {
// M -> S // M -> S
type CheckPartition struct { type CheckPartition struct {
Packet PktHead
Partition uint32 // PNumber Partition uint32 // PNumber
Source struct { Source struct {
UpstreamName string UpstreamName string
...@@ -745,7 +748,7 @@ type CheckPartition struct { ...@@ -745,7 +748,7 @@ type CheckPartition struct {
// reference node. // reference node.
// S -> S // S -> S
type CheckTIDRange struct { type CheckTIDRange struct {
Packet PktHead
Partition uint32 // PNumber Partition uint32 // PNumber
Length uint32 // PNumber Length uint32 // PNumber
MinTID Tid MinTID Tid
...@@ -753,7 +756,7 @@ type CheckTIDRange struct { ...@@ -753,7 +756,7 @@ type CheckTIDRange struct {
} }
type AnswerCheckTIDRange struct { type AnswerCheckTIDRange struct {
Packet PktHead
Count uint32 // PNumber Count uint32 // PNumber
Checksum Checksum Checksum Checksum
MaxTID Tid MaxTID Tid
...@@ -768,7 +771,7 @@ type AnswerCheckTIDRange struct { ...@@ -768,7 +771,7 @@ type AnswerCheckTIDRange struct {
// reference node. // reference node.
// S -> S // S -> S
type CheckSerialRange struct { type CheckSerialRange struct {
Packet PktHead
Partition uint32 // PNumber Partition uint32 // PNumber
Length uint32 // PNumber Length uint32 // PNumber
MinTID Tid MinTID Tid
...@@ -786,7 +789,7 @@ type AnswerCheckSerialRange struct { ...@@ -786,7 +789,7 @@ type AnswerCheckSerialRange struct {
// S -> M // S -> M
type PartitionCorrupted struct { type PartitionCorrupted struct {
Packet PktHead
Partition uint32 // PNumber Partition uint32 // PNumber
CellList []UUID CellList []UUID
} }
...@@ -797,11 +800,11 @@ type PartitionCorrupted struct { ...@@ -797,11 +800,11 @@ type PartitionCorrupted struct {
// Answer last committed TID. // Answer last committed TID.
// M -> C // M -> C
type LastTransaction struct { type LastTransaction struct {
Packet PktHead
} }
type AnswerLastTransaction struct { type AnswerLastTransaction struct {
Packet PktHead
Tid Tid Tid Tid
} }
...@@ -809,7 +812,7 @@ type AnswerLastTransaction struct { ...@@ -809,7 +812,7 @@ type AnswerLastTransaction struct {
// Notify that node is ready to serve requests. // Notify that node is ready to serve requests.
// S -> M // S -> M
type NotifyReady struct { type NotifyReady struct {
Packet PktHead
} }
// replication // replication
......
...@@ -4,8 +4,12 @@ package neo ...@@ -4,8 +4,12 @@ package neo
import ( import (
"context" "context"
"encoding/binary"
"net" "net"
"fmt" "fmt"
"io"
//"../neo/proto"
) )
// NEO Storage application // NEO Storage application
...@@ -14,46 +18,56 @@ import ( ...@@ -14,46 +18,56 @@ import (
type StorageApplication struct { type StorageApplication struct {
} }
/*
// XXX change to bytes.Buffer if we need to access it as I/O
type Buffer struct {
buf []byte
}
*/
func (stor *StorageApplication) ServeConn(ctx context.Context, conn net.Conn) { func (stor *StorageApplication) ServeConn(ctx context.Context, conn net.Conn) {
fmt.Printf("stor: serving new client %s <-> %s\n", conn.LocalAddr(), conn.RemoteAddr()) fmt.Printf("stor: serving new client %s <-> %s\n", conn.LocalAddr(), conn.RemoteAddr())
//fmt.Fprintf(conn, "Hello up there, you address is %s\n", conn.RemoteAddr()) // XXX err //fmt.Fprintf(conn, "Hello up there, you address is %s\n", conn.RemoteAddr()) // XXX err
//conn.Close() // XXX err //conn.Close() // XXX err
/*
// TODO: use bytes.Buffer{} // TODO: use bytes.Buffer{}
// .Bytes() -> buf -> can grow up again up to buf[:cap(buf)] // .Bytes() -> buf -> can grow up again up to buf[:cap(buf)]
// NewBuffer(buf) -> can use same buffer for later reading via bytes.Buffer // NewBuffer(buf) -> can use same buffer for later reading via bytes.Buffer
// TODO read PktHeader (fixed length) (-> length, PktType (by .code)) // TODO read PktHeader (fixed length) (-> length, PktType (by .code))
// TODO PktHeader
//rxbuf := bytes.Buffer{} //rxbuf := bytes.Buffer{}
rxbuf := bytes.NewBuffer(make([]byte, 4096)) rxbuf := bytes.NewBuffer(make([]byte, 4096))
n, err := conn.Read(rxbuf.Bytes()) n, err := conn.Read(rxbuf.Bytes())
*/
// first read to read pkt header and hopefully up to page of data in 1 syscall // first read to read pkt header and hopefully up to page of data in 1 syscall
rxbuf := Buffer{make([]byte, 4096} rxbuf := make([]byte, 4096)
n, err := io.ReadAtLeast(conn, rxbuf, PktHeadLen) n, err := io.ReadAtLeast(conn, rxbuf, PktHeadLen)
if err != nil { if err != nil {
panic(err) // TODO panic(err) // XXX err
} }
id := binary.BigEndian.Uint32(rxbuf[0:])
code := binary.BigEndian.Uint16(rxbuf[4:]) _/*id*/ = binary.BigEndian.Uint32(rxbuf[0:]) // XXX -> PktHeader.Decode() ?
_/*code*/= binary.BigEndian.Uint16(rxbuf[4:])
length := binary.BigEndian.Uint32(rxbuf[6:]) length := binary.BigEndian.Uint32(rxbuf[6:])
if length < PktHeadLen { if length < PktHeadLen {
panic() // XXX err (length is a whole packet len with header) panic("TODO pkt.length < PktHeadLen") // XXX err (length is a whole packet len with header)
} }
if length > len(rxbuf) { if length > uint32(len(rxbuf)) {
// TODO grow rxbuf // grow rxbuf
panic() rxbuf2 := make([]byte, length)
copy(rxbuf2, rxbuf[:n])
rxbuf = rxbuf2
} }
// read rest of pkt data, if we need to // read rest of pkt data, if we need to
n2, err := io.ReadFull(conn, rxbuf[n:length]) _, err = io.ReadFull(conn, rxbuf[n:length])
if err != nil {
// read first pkt chunk: header + some data (all in 1 read call) panic(err) // XXX err
rxl.N = 4096 }
n, err := rxbuf.ReadFrom(rxl)
} }
...@@ -72,7 +86,6 @@ type Server interface { ...@@ -72,7 +86,6 @@ type Server interface {
// - for every accepted connection spawn srv.ServeConn() in separate goroutine. // - for every accepted connection spawn srv.ServeConn() in separate goroutine.
// //
// the listener is closed when Serve returns. // the listener is closed when Serve returns.
// XXX text
// XXX move -> generic place ? // XXX move -> generic place ?
func Serve(ctx context.Context, l net.Listener, srv Server) error { func Serve(ctx context.Context, l net.Listener, srv Server) error {
fmt.Printf("stor: serving on %s ...\n", l.Addr()) fmt.Printf("stor: serving on %s ...\n", l.Addr())
......
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