Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
7fa264d5
Commit
7fa264d5
authored
Aug 10, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d8ae847c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
57 deletions
+92
-57
go/neo/server/master.go
go/neo/server/master.go
+3
-9
go/xcommon/task/task.go
go/xcommon/task/task.go
+89
-0
go/xcommon/xcontext/xcontext.go
go/xcommon/xcontext/xcontext.go
+0
-48
No files found.
go/neo/server/master.go
View file @
7fa264d5
...
...
@@ -258,15 +258,9 @@ type storRecovery struct {
// - nil: recovery was ok and a command came for cluster to start
// - !nil: recovery was cancelled
func
(
m
*
Master
)
recovery
(
ctx
context
.
Context
)
(
err
error
)
{
m
.
log
(
"recovery"
)
//defer xerr.Context(&err, "master: recovery")
defer
m
.
errctx
(
&
err
,
"recovery"
)
my
.
Context
(
&
ctx
,
"recovery"
)
defer
xerr
.
Context
(
&
err
,
ctx
)
xcontext
.
Running
(
&
ctx
,
"recovery"
)
defer
xerr
.
Context
(
&
err
,
ctx
)
ctx
=
task
.
Running
(
ctx
,
"recovery"
)
defer
task
.
ErrContext
(
&
err
,
ctx
)
log
.
Infof
(
ctx
,
""
)
// XXX automatically log in task.Running?
m
.
setClusterState
(
neo
.
ClusterRecovering
)
rctx
,
rcancel
:=
context
.
WithCancel
(
ctx
)
...
...
go/xcommon/task/task.go
0 → 100644
View file @
7fa264d5
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package task allows to define currently running task via context XXX
package
task
import
(
"context"
)
// Task represents currently running operation
type
Task
struct
{
Parent
*
Task
Name
string
}
// String returns string representing whole operational stack.
//
// For example if task "c" is running under task "b" which in turn is running
// under task "a" - the operational stack will be "a: b: c"
func
(
t
*
Task
)
String
()
string
{
if
o
==
nil
{
return
""
}
prefix
:=
Parent
.
String
()
if
prefix
!=
""
{
prefix
+=
": "
}
return
prefix
+
t
.
Name
}
type
taskKey
struct
{}
// Running creates new task and returns new context with that task set to current
func
Running
(
ctx
context
.
Context
,
name
string
)
context
.
Context
{
context
.
WithValue
(
&
Task
{
Parent
:
Current
(
ctx
),
Name
:
name
})
}
// Current returns current task represented by context.
// if there is no current task - it returns nil.
func
Current
(
ctx
Context
)
*
Task
{
task
,
_
:=
ctx
.
Value
(
taskKey
)
.
(
*
Task
)
return
task
}
// ErrContext adds current task name to error on error return.
// to work as intended it should be called under defer like this:
//
// func myfunc(ctx, ...) (..., err error) {
// ctx = task.Running("doing something")
// defer task.ErrContext(&err, ctx)
// ...
//
// Please see lab.nexedi.com/kirr/go123/xerr.Context for semantic details
func
ErrContext
(
errp
*
error
,
ctx
Context
)
{
task
:=
Current
(
ctx
)
if
task
==
nil
{
return
}
return
xerr
.
Context
(
errp
,
task
.
Name
)
}
// XXX place
func
Logf
(
ctx
context
.
Context
,
format
string
,
argv
...
interface
{})
{
s
:=
CurrentOp
(
ctx
)
.
String
()
if
s
!=
""
{
s
+=
": "
}
s
+=
fmt
.
Sprintf
(
format
,
argv
...
)
log
.
Log
(
s
)
}
go/xcommon/xcontext/xcontext.go
View file @
7fa264d5
...
...
@@ -135,51 +135,3 @@ func Canceled(err error) bool {
return
false
}
// ---- operational stack ----
// Operation provides text representing currently running operation
type
Operation
struct
{
Parent
*
operation
Name
string
}
// String returns string representing whole operational stack
func
(
o
*
Operation
)
String
()
string
{
if
o
==
nil
{
return
""
}
prefix
:=
Parent
.
String
()
if
prefix
!=
""
{
prefix
+=
": "
}
return
prefix
+
o
.
Name
}
type
opKey
struct
{}
func
PushOp
(
ctxp
*
context
.
Context
,
name
string
)
{
*
ctxp
=
context
.
WithValue
(
&
Operation
{
Parent
:
CurrentOp
(
*
ctxp
),
Name
:
name
})
}
// CurrentOp returns current operation represented by context.
// if there is no current operation - it returns nil.
func
CurrentOp
(
ctx
Context
)
*
Operation
{
op
:=
ctx
.
Value
(
opKey
)
if
op
==
nil
{
return
nil
}
return
op
.
(
*
Operation
)
}
// XXX place
func
Logf
(
ctx
context
.
Context
,
format
string
,
argv
...
interface
{})
{
s
:=
CurrentOp
(
ctx
)
.
String
()
if
s
!=
""
{
s
+=
": "
}
s
+=
fmt
.
Sprintf
(
format
,
argv
...
)
log
.
Log
(
s
)
}
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