Commit d3713e72 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 946500ad
......@@ -80,7 +80,7 @@ func (pkt *PktBuf) String() string {
s += fmt.Sprintf(" (%s) %v; #%d [%d]: % x", msgType, err, msgLen, len(data), data)
}
s += fmt.Sprintf(" %s %+v", msgType.Name(), msg)
s += fmt.Sprintf(" %s %v", msgType.Name(), msg) // XXX or %+v better?
if n < len(data) {
tail := data[n:]
......
......@@ -22,8 +22,9 @@ func (e *Error) Error() string {
const nodeTypeChar = "MSCA4567" // keep in sync with NodeType constants
// String returns string representation of a node uuid.
// It returns ex 'S1', 'M2', ...
func (nodeUUID NodeUUID) String() string {
// return ex 'S1', 'M2', ...
if nodeUUID == 0 {
return "?0"
}
......@@ -45,6 +46,23 @@ func (nodeUUID NodeUUID) String() string {
return s
}
// XXX place ok?
// XXX test
func UUID(typ NodeType, num int32) NodeUUID {
temp := uint32(0)
if num < 0 {
temp = 1
num = -num
}
if num >> 24 != 0 {
panic("node number out of range")
}
uuid := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
return NodeUUID(uuid)
}
// ----------------------------------------
// Addr converts network address string into NEO Address
......
......@@ -225,7 +225,13 @@ func TestMasterStorage(t *testing.T) {
IdTimestamp: 0,
}))
// XXX ... M adjust nodetab...
tc.Expect(conntx("m:1", "s:1", 1, &neo.AcceptIdentification{})) // XXX
tc.Expect(conntx("m:2", "s:2", 1, &neo.AcceptIdentification{
NodeType: neo.MASTER,
MyNodeUUID: neo.UUID(neo.MASTER, 1),
NumPartitions: 1,
NumReplicas: 1,
YourNodeUUID: neo.UUID(neo.STORAGE, 1),
}))
......
......@@ -166,7 +166,7 @@ func (m *Master) Run(ctx context.Context) (err error) {
defer wg.Done()
// XXX dup in storage
for serveCtx.Err() != nil {
for serveCtx.Err() == nil {
conn, idReq, err := l.Accept()
if err != nil {
// TODO log / throttle
......@@ -925,12 +925,8 @@ func (m *Master) accept(ctx context.Context, conn *neo.Conn, resp neo.Msg) error
// XXX it is bad idea for master to assign uuid to coming node
// -> better nodes generate really unique UUID themselves and always show with them
func (m *Master) allocUUID(nodeType neo.NodeType) neo.NodeUUID {
// see NodeUUID & NodeUUID.String for details
// XXX better to keep this code near to ^^^ (e.g. attached to NodeType)
// XXX but since whole uuid assign idea is not good - let's keep it dirty here
typ := int(nodeType & 7) << (24 + 4) // note temp=0
for num := 1; num < 1<<24; num++ {
uuid := neo.NodeUUID(typ | num)
for num := int32(1); num < 1<<24; num++ {
uuid := neo.UUID(nodeType, num)
if m.nodeTab.Get(uuid) == nil {
return uuid
}
......
......@@ -93,6 +93,8 @@ func (stor *Storage) Run(ctx context.Context) error {
if err != nil {
return err // XXX err ctx
}
defer runningf(&ctx, "storage(%v)", l.Addr())(&err)
log.Infof(ctx, "serving on %s ...", l.Addr())
// start serving incoming connections
......@@ -103,7 +105,7 @@ func (stor *Storage) Run(ctx context.Context) error {
defer wg.Done()
// XXX dup from master
for serveCtx.Err() != nil {
for serveCtx.Err() == nil {
conn, idReq, err := l.Accept()
if err != nil {
// TODO log / throttle
......
......@@ -20,6 +20,7 @@
// Package log provides logging with severity levels and tasks integration
//
// XXX inspired by cockrach
// XXX just use cockroach/util/log directly?
package log
import (
......@@ -31,17 +32,6 @@ import (
"lab.nexedi.com/kirr/neo/go/xcommon/task"
)
/*
// taskPrefix returns prefix associated to current operational task stack to put to logs
func taskPrefix(ctx context.Context) string {
s := task.Current(ctx).String()
if s != "" {
s += ": "
}
return s
}
*/
// withTask prepends string describing current operational task stack to argv and returns it
// handy to use this way:
//
......@@ -57,7 +47,7 @@ func withTask(ctx context.Context, argv ...interface{}) []interface{} {
}
if len(argv) != 0 {
task += ":"
task += ": "
}
return append([]interface{}{task}, argv...)
......@@ -99,4 +89,4 @@ func Errorf(ctx context.Context, format string, argv ...interface{}) {
}
// TODO Warningf, Errorf, ...
// TODO Warningf, ...
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