Commit 5c24c361 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 505cf34b
......@@ -29,7 +29,7 @@ package neo
//
// Oid space is divided (partitioned) into Np parts via
//
// ptid(oid) = oid % Np XXX ptid -> pid ?
// pid(oid) = oid % Np
//
// rule. The `oid % Np` is known as partition identifier of oid.
//
......@@ -38,7 +38,7 @@ package neo
//
// Given Np, R and []Storage PartitionTable tries to organize
//
// Ptid -> []Storage
// Pid -> []Storage
//
// mapping so that
//
......@@ -107,9 +107,9 @@ package neo
type PartitionTable struct {
// XXX do we need sync.Mutex here for updates ?
ptTab [][]PartitionCell // [#Np]
PtTab [][]PartitionCell // [#Np] XXX naming
ptid PTid // ↑ for versioning XXX -> ver ?
PTid PTid // ↑ for versioning XXX -> ver ?
}
// PartitionCell describes one storage in a ptid entry in partition table
......@@ -140,7 +140,7 @@ type PartitionCell struct {
//
// XXX or keep not only NodeUUID in PartitionCell - add *Node ?
func (pt *PartitionTable) OperationalWith(nt *NodeTable) bool {
for _, ptEntry := range pt.ptTab {
for _, ptEntry := range pt.PtTab {
if len(ptEntry) == 0 {
return false
}
......
......@@ -208,7 +208,7 @@ type Checksum [20]byte
// Partition Table identifier
// Zero value means "invalid id" (<-> None in py.PPTID)
type PTid uint64 // XXX move to common place ?
type PTid uint64
// XXX move -> marshalutil.go ?
......
......@@ -227,7 +227,7 @@ loop:
// we are interested in latest partTab
// NOTE during recovery no one must be subscribed to
// partTab so it is ok to simply change whole m.partTab
if r.partTab.ptid > m.partTab.ptid {
if r.partTab.PTid > m.partTab.PTid {
m.partTab = r.partTab
}
......@@ -324,16 +324,16 @@ func storCtlRecovery(ctx context.Context, link *neo.NodeLink, res chan storRecov
// reconstruct partition table from response
pt := neo.PartitionTable{}
pt.ptid = resp.PTid
pt.PTid = resp.PTid
for _, row := range resp.RowList {
i := row.Offset
for i >= uint32(len(pt.ptTab)) {
pt.ptTab = append(pt.ptTab, []neo.PartitionCell{})
for i >= uint32(len(pt.PtTab)) {
pt.PtTab = append(pt.PtTab, []neo.PartitionCell{})
}
//pt.ptTab[i] = append(pt.ptTab[i], row.CellList...)
//pt.PtTab[i] = append(pt.PtTab[i], row.CellList...)
for _, cell := range row.CellList {
pt.ptTab[i] = append(pt.ptTab[i], neo.PartitionCell{
pt.PtTab[i] = append(pt.PtTab[i], neo.PartitionCell{
NodeUUID: cell.NodeUUID,
CellState: cell.CellState,
})
......
......@@ -136,40 +136,3 @@ func IdentifyPeer(link *neo.NodeLink, myNodeType neo.NodeType) (nodeInfo neo.Req
return req, nil
}
// IdentifyWith identifies local node with remote peer
// it also verifies peer's node type to what caller expects
// XXX place != ok (this is client, not server ?)
func IdentifyWith(expectPeerType neo.NodeType, link *neo.NodeLink, myInfo neo.NodeInfo, clusterName string) (accept *neo.AcceptIdentification, err error) {
defer xerr.Contextf(&err, "%s: request identification", link)
conn, err := link.NewConn()
if err != nil {
return nil, err
}
defer func() {
err2 := conn.Close()
if err == nil && err2 != nil {
err = err2
}
}()
accept = &neo.AcceptIdentification{}
err = neo.Ask(conn, &neo.RequestIdentification{
NodeType: myInfo.NodeType,
NodeUUID: myInfo.NodeUUID,
Address: myInfo.Address,
ClusterName: clusterName,
IdTimestamp: myInfo.IdTimestamp, // XXX ok?
}, accept)
if err != nil {
return nil, err // XXX err ctx ?
}
if accept.NodeType != expectPeerType {
return nil, fmt.Errorf("accepted, but peer is not %v (identifies as %v)", expectPeerType, accept.NodeType)
}
return accept, nil
}
......@@ -138,7 +138,7 @@ func (stor *Storage) talkMaster1(ctx context.Context) error {
// TODO Mlink.Close() on return / cancel
// request identification this way registering our node to master
accept, err := IdentifyWith(neo.MASTER, Mlink, stor.myInfo, stor.clusterName)
accept, err := neo.IdentifyWith(neo.MASTER, Mlink, stor.myInfo, stor.clusterName)
if err != nil {
return err
}
......
......@@ -6,6 +6,8 @@ import (
"reflect"
"../zodb"
"lab.nexedi.com/kirr/go123/xerr"
)
// RecvAndDecode receives packet from conn and decodes it
......@@ -124,8 +126,7 @@ func Expect(conn *Conn, msg Pkt) (err error) {
// ------------------------------------------
// XXX vvv place = ok ?
// XXX place=?
// errEncode translates an error into Error packet
// XXX more text describing relation with zodb errors
......@@ -156,3 +157,42 @@ func ErrDecode(e *Error) error {
return e
}
// ------------------------------------------
// XXX place=?
// IdentifyWith identifies local node with remote peer
// it also verifies peer's node type to what caller expects
func IdentifyWith(expectPeerType NodeType, link *NodeLink, myInfo NodeInfo, clusterName string) (accept *AcceptIdentification, err error) {
defer xerr.Contextf(&err, "%s: request identification", link)
conn, err := link.NewConn()
if err != nil {
return nil, err
}
defer func() {
err2 := conn.Close()
if err == nil && err2 != nil {
err = err2
}
}()
accept = &AcceptIdentification{}
err = Ask(conn, &RequestIdentification{
NodeType: myInfo.NodeType,
NodeUUID: myInfo.NodeUUID,
Address: myInfo.Address,
ClusterName: clusterName,
IdTimestamp: myInfo.IdTimestamp, // XXX ok?
}, accept)
if err != nil {
return nil, err // XXX err ctx ?
}
if accept.NodeType != expectPeerType {
return nil, fmt.Errorf("accepted, but peer is not %v (identifies as %v)", expectPeerType, accept.NodeType)
}
return accept, nil
}
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