Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2db1b68d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2db1b68d
编写于
7月 17, 2017
作者:
H
helinwang
提交者:
GitHub
7月 17, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2885 from helinwang/handle_err
Add gometalinter errcheck to pre-commit-hook, fix all Go unchecked errors.
上级
50fa7e63
25e57949
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
140 addition
and
70 deletion
+140
-70
.pre-commit-config.yaml
.pre-commit-config.yaml
+5
-5
.travis.yml
.travis.yml
+2
-0
go/master/c/client.go
go/master/c/client.go
+2
-3
go/master/client.go
go/master/client.go
+4
-1
go/master/client_internal_test.go
go/master/client_internal_test.go
+18
-4
go/master/client_test.go
go/master/client_test.go
+20
-4
go/master/etcd_client.go
go/master/etcd_client.go
+2
-2
go/master/inmem_store.go
go/master/inmem_store.go
+1
-1
go/master/service.go
go/master/service.go
+1
-2
go/pserver/client/c/cclient.go
go/pserver/client/c/cclient.go
+11
-12
go/pserver/client/client.go
go/pserver/client/client.go
+1
-1
go/pserver/client/client_test.go
go/pserver/client/client_test.go
+23
-5
go/pserver/client/etcd_client.go
go/pserver/client/etcd_client.go
+7
-8
go/pserver/etcd_client.go
go/pserver/etcd_client.go
+3
-6
go/pserver/optimizer.go
go/pserver/optimizer.go
+3
-5
go/pserver/service.go
go/pserver/service.go
+32
-11
paddle/scripts/travis/check_style.sh
paddle/scripts/travis/check_style.sh
+5
-0
未找到文件。
.pre-commit-config.yaml
浏览文件 @
2db1b68d
...
...
@@ -21,10 +21,10 @@
sha
:
28c0ea8a67a3e2dbbf4822ef44e85b63a0080a29
hooks
:
-
id
:
clang-formater
-
repo
:
https://github.com/
dnephin
/pre-commit-golang
sha
:
e4693a4c282b4fc878eda172a929f7a6508e7d16
-
repo
:
https://github.com/
PaddlePaddle
/pre-commit-golang
sha
:
16398aeccf263adaf53b2495eed0406347d76281
hooks
:
-
id
:
go-fmt
files
:
(.*\.go)
-
id
:
go
-lint
files
:
(.*\.go)
types
:
[
go
]
-
id
:
go
metalinter
types
:
[
go
]
.travis.yml
浏览文件 @
2db1b68d
...
...
@@ -41,6 +41,8 @@ before_install:
-
pip install rarfile
-
curl https://glide.sh/get | bash
-
eval "$(GIMME_GO_VERSION=1.8.3 gimme)"
-
go get -u github.com/alecthomas/gometalinter
-
gometalinter --install
-
|
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
script
:
...
...
go/master/c/client.go
浏览文件 @
2db1b68d
...
...
@@ -23,7 +23,6 @@ import (
log
"github.com/sirupsen/logrus"
)
var
nullPtr
=
unsafe
.
Pointer
(
uintptr
(
0
))
var
mu
sync
.
Mutex
var
handleMap
=
make
(
map
[
C
.
paddle_master_client
]
*
master
.
Client
)
var
curHandle
C
.
paddle_master_client
...
...
@@ -114,13 +113,13 @@ func paddle_next_record(client C.paddle_master_client, record **C.uchar) C.int {
if
err
!=
nil
{
// Error
// TODO: return the type of error?
*
record
=
(
*
C
.
uchar
)(
n
ullPtr
)
*
record
=
(
*
C
.
uchar
)(
n
il
)
return
-
1
}
if
len
(
r
)
==
0
{
// Empty record
*
record
=
(
*
C
.
uchar
)(
n
ullPtr
)
*
record
=
(
*
C
.
uchar
)(
n
il
)
return
0
}
...
...
go/master/client.go
浏览文件 @
2db1b68d
...
...
@@ -69,7 +69,10 @@ func (c *Client) getRecords() {
// We treat a task as finished whenever the last data
// instance of the task is read. This is not exactly
// correct, but a reasonable approximation.
c
.
taskFinished
(
t
.
Meta
.
ID
)
err
=
c
.
taskFinished
(
t
.
Meta
.
ID
)
if
err
!=
nil
{
log
.
Errorln
(
err
)
}
}
}
...
...
go/master/client_internal_test.go
浏览文件 @
2db1b68d
...
...
@@ -66,11 +66,21 @@ func TestGetFinishTask(t *testing.T) {
for
i
:=
0
;
i
<
totalTask
*
chunkPerTask
;
i
++
{
w
:=
recordio
.
NewWriter
(
f
,
-
1
,
-
1
)
w
.
Write
(
nil
)
_
,
err
=
w
.
Write
(
nil
)
if
err
!=
nil
{
panic
(
err
)
}
// call Close to force RecordIO writing a chunk.
w
.
Close
()
err
=
w
.
Close
()
if
err
!=
nil
{
panic
(
err
)
}
}
err
=
f
.
Close
()
if
err
!=
nil
{
panic
(
err
)
}
f
.
Close
()
// Manually intialize client to avoid calling c.getRecords()
c
:=
&
Client
{}
...
...
@@ -79,7 +89,11 @@ func TestGetFinishTask(t *testing.T) {
ch
:=
make
(
chan
string
,
1
)
ch
<-
addr
go
c
.
monitorMaster
(
ch
)
c
.
SetDataset
([]
string
{
path
})
err
=
c
.
SetDataset
([]
string
{
path
})
if
err
!=
nil
{
panic
(
err
)
}
checkOnePass
:=
func
(
i
int
)
{
var
tasks
[]
Task
for
idx
:=
0
;
idx
<
totalTask
;
idx
++
{
...
...
go/master/client_test.go
浏览文件 @
2db1b68d
...
...
@@ -57,14 +57,30 @@ func TestNextRecord(t *testing.T) {
w
:=
recordio
.
NewWriter
(
f
,
-
1
,
-
1
)
for
i
:=
0
;
i
<
total
;
i
++
{
w
.
Write
([]
byte
{
byte
(
i
)})
_
,
err
=
w
.
Write
([]
byte
{
byte
(
i
)})
if
err
!=
nil
{
panic
(
err
)
}
}
err
=
w
.
Close
()
if
err
!=
nil
{
panic
(
err
)
}
err
=
f
.
Close
()
if
err
!=
nil
{
panic
(
err
)
}
w
.
Close
()
f
.
Close
()
curAddr
:=
make
(
chan
string
,
1
)
curAddr
<-
fmt
.
Sprintf
(
":%d"
,
p
)
c
:=
master
.
NewClient
(
curAddr
,
10
)
c
.
SetDataset
([]
string
{
path
})
err
=
c
.
SetDataset
([]
string
{
path
})
if
err
!=
nil
{
panic
(
err
)
}
for
pass
:=
0
;
pass
<
50
;
pass
++
{
received
:=
make
(
map
[
byte
]
bool
)
for
i
:=
0
;
i
<
total
;
i
++
{
...
...
go/master/etcd_client.go
浏览文件 @
2db1b68d
...
...
@@ -30,7 +30,7 @@ type EtcdClient struct {
// NewEtcdClient creates a new EtcdClient.
func
NewEtcdClient
(
endpoints
[]
string
,
addr
string
,
lockPath
,
addrPath
,
statePath
string
,
ttlSec
int
)
(
*
EtcdClient
,
error
)
{
log
.
Debugf
(
"Connecting to etcd at %v"
,
endpoints
)
// TODO(helin): gracefully shutdown etcd store. Bec
ua
se etcd
// TODO(helin): gracefully shutdown etcd store. Bec
au
se etcd
// store holds a etcd lock, even though the lock will expire
// when the lease timeout, we need to implement graceful
// shutdown to release the lock.
...
...
@@ -60,7 +60,7 @@ func NewEtcdClient(endpoints []string, addr string, lockPath, addrPath, statePat
}
log
.
Debugf
(
"Successfully acquired lock at %s."
,
lockPath
)
put
:=
clientv3
.
OpPut
(
addrPath
,
string
(
addr
)
)
put
:=
clientv3
.
OpPut
(
addrPath
,
addr
)
resp
,
err
:=
cli
.
Txn
(
context
.
Background
())
.
If
(
lock
.
IsOwner
())
.
Then
(
put
)
.
Commit
()
if
err
!=
nil
{
return
nil
,
err
...
...
go/master/inmem_store.go
浏览文件 @
2db1b68d
...
...
@@ -4,7 +4,7 @@ import "sync"
// InMemStore is an in memory implementation of Store interface.
//
// It does not tolerate the fault that ca
su
es the program to crash.
// It does not tolerate the fault that ca
us
es the program to crash.
type
InMemStore
struct
{
mu
sync
.
Mutex
buf
[]
byte
...
...
go/master/service.go
浏览文件 @
2db1b68d
...
...
@@ -160,7 +160,7 @@ func (s *Service) recover() (bool, error) {
// snapshot *must* be called with s.mu being held.
func
(
s
*
Service
)
snapshot
()
error
{
// TO
OD
(helin): etcd request has a size limit, so the snapshot
// TO
DO
(helin): etcd request has a size limit, so the snapshot
// size is limited by the max request size. We should either
// divide the snapshot into smaller chunks and save under
// different keys, or configure the request size to be big
...
...
@@ -289,7 +289,6 @@ func (s *Service) processFailedTask(t taskEntry, epoch int) {
log
.
Warningf
(
"Task %v failed %d times, discard."
,
t
.
Task
,
t
.
NumFailure
)
s
.
taskQueues
.
Todo
=
append
(
s
.
taskQueues
.
Todo
,
t
)
return
}
func
(
s
*
Service
)
checkTimeoutFunc
(
taskID
int
,
epoch
int
)
func
()
{
...
...
go/pserver/client/c/cclient.go
浏览文件 @
2db1b68d
...
...
@@ -34,7 +34,6 @@ import (
log
"github.com/sirupsen/logrus"
)
var
nullPtr
=
unsafe
.
Pointer
(
uintptr
(
0
))
var
mu
sync
.
Mutex
var
handleMap
=
make
(
map
[
C
.
paddle_pserver_client
]
*
client
.
Client
)
var
curHandle
C
.
paddle_pserver_client
...
...
@@ -63,7 +62,7 @@ func remove(client C.paddle_pserver_client) *client.Client {
}
func
cArrayToSlice
(
p
unsafe
.
Pointer
,
len
int
)
[]
byte
{
if
p
==
n
ullPtr
{
if
p
==
n
il
{
return
nil
}
...
...
@@ -101,11 +100,11 @@ func paddle_new_pserver_client(addrs *C.char, selected int) C.paddle_pserver_cli
}
//export paddle_new_etcd_pserver_client
func
paddle_new_etcd_pserver_client
(
etcd
_e
ndpoints
*
C
.
char
,
selected
int
)
C
.
paddle_pserver_client
{
func
paddle_new_etcd_pserver_client
(
etcd
E
ndpoints
*
C
.
char
,
selected
int
)
C
.
paddle_pserver_client
{
// TODO(Longfei: use etcd lock to decide which trainer to initialize the parameters)
addr
:=
C
.
GoString
(
etcd
_e
ndpoints
)
etcd
_c
lient
:=
client
.
NewEtcd
(
addr
)
c
:=
client
.
NewClient
(
etcd
_client
,
etcd_c
lient
.
Desired
(),
selector
(
selected
!=
0
))
addr
:=
C
.
GoString
(
etcd
E
ndpoints
)
etcd
C
lient
:=
client
.
NewEtcd
(
addr
)
c
:=
client
.
NewClient
(
etcd
Client
,
etcdC
lient
.
Desired
(),
selector
(
selected
!=
0
))
return
add
(
c
)
}
...
...
@@ -124,20 +123,20 @@ func paddle_begin_init_params(client C.paddle_pserver_client) C.int {
}
//export paddle_init_param
func
paddle_init_param
(
client
C
.
paddle_pserver_client
,
param
C
.
paddle_parameter
,
param
_config
unsafe
.
Pointer
,
config_l
en
C
.
int
)
C
.
int
{
func
paddle_init_param
(
client
C
.
paddle_pserver_client
,
param
C
.
paddle_parameter
,
param
Config
unsafe
.
Pointer
,
configL
en
C
.
int
)
C
.
int
{
et
:=
pserver
.
ElementType
(
param
.
element_type
)
name
:=
C
.
GoString
(
param
.
name
)
content
:=
cArrayToSlice
(
unsafe
.
Pointer
(
param
.
content
),
int
(
param
.
content_len
))
pc
:=
pserver
.
ParameterWithConfig
{
Param
:
pserver
.
Parameter
{
Name
:
name
,
ElementType
:
et
,
Content
:
content
},
Config
:
cArrayToSlice
(
param
_config
,
int
(
config_l
en
)),
Config
:
cArrayToSlice
(
param
Config
,
int
(
configL
en
)),
}
c
:=
get
(
client
)
err
:=
c
.
InitParam
(
pc
)
if
err
!=
nil
{
if
err
.
Error
()
==
pserver
.
AlreadyInitialized
{
log
.
Warningf
(
"parameter %s already initialized, treat paddle_init_param as sucessful."
,
name
)
log
.
Warningf
(
"parameter %s already initialized, treat paddle_init_param as suc
c
essful."
,
name
)
return
C
.
PSERVER_OK
}
log
.
Errorln
(
err
)
...
...
@@ -153,7 +152,7 @@ func paddle_finish_init_params(client C.paddle_pserver_client) C.int {
err
:=
c
.
FinishInitParams
()
if
err
!=
nil
{
if
err
.
Error
()
==
pserver
.
AlreadyInitialized
{
log
.
Warningln
(
"parameters already initialized, treat paddle_finish_init_params as sucessful."
)
log
.
Warningln
(
"parameters already initialized, treat paddle_finish_init_params as suc
c
essful."
)
return
C
.
PSERVER_OK
}
...
...
@@ -223,12 +222,12 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter,
p
:=
ps
[
i
]
param
:=
*
(
**
C
.
paddle_parameter
)(
unsafe
.
Pointer
((
uintptr
(
unsafe
.
Pointer
(
dst
))
+
uintptr
(
i
)
*
unsafe
.
Sizeof
(
*
dst
))))
if
unsafe
.
Pointer
(
param
)
==
n
ullPtr
{
if
unsafe
.
Pointer
(
param
)
==
n
il
{
log
.
Errorln
(
"must pre-allocate parameter."
)
return
C
.
PSERVER_ERROR
}
if
unsafe
.
Pointer
(
param
.
content
)
!=
n
ullPtr
{
if
unsafe
.
Pointer
(
param
.
content
)
!=
n
il
{
if
int
(
param
.
content_len
)
!=
len
(
p
.
Content
)
{
log
.
Errorf
(
"the pre-allocated content len does not match parameter content len. Pre-allocated len: %d, returned len: %d"
,
param
.
content_len
,
len
(
p
.
Content
))
return
C
.
PSERVER_ERROR
...
...
go/pserver/client/client.go
浏览文件 @
2db1b68d
...
...
@@ -233,7 +233,7 @@ func (c *Client) Save(path string) error {
func
strHash
(
s
string
)
uint32
{
h
:=
fnv
.
New32a
()
h
.
Write
([]
byte
(
s
))
_
,
_
=
h
.
Write
([]
byte
(
s
))
return
h
.
Sum32
()
}
...
...
go/pserver/client/client_test.go
浏览文件 @
2db1b68d
...
...
@@ -79,15 +79,33 @@ func initEtcdClient() {
log
.
Errorf
(
"err %v"
,
err
)
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
client
.
Delete
(
ctx
,
pserver
.
PsDesired
)
client
.
Delete
(
ctx
,
pserver
.
PsPath
)
client
.
Put
(
ctx
,
pserver
.
PsDesired
,
strconv
.
Itoa
(
numPserver
))
_
,
err
=
client
.
Delete
(
ctx
,
pserver
.
PsDesired
)
if
err
!=
nil
{
panic
(
err
)
}
_
,
err
=
client
.
Delete
(
ctx
,
pserver
.
PsPath
)
if
err
!=
nil
{
panic
(
err
)
}
_
,
err
=
client
.
Put
(
ctx
,
pserver
.
PsDesired
,
strconv
.
Itoa
(
numPserver
))
if
err
!=
nil
{
panic
(
err
)
}
ports
:=
initClient
()
for
i
:=
0
;
i
<
numPserver
;
i
++
{
client
.
Put
(
ctx
,
pserver
.
PsPath
+
strconv
.
Itoa
(
i
),
":"
+
strconv
.
Itoa
(
ports
[
i
]))
_
,
err
=
client
.
Put
(
ctx
,
pserver
.
PsPath
+
strconv
.
Itoa
(
i
),
":"
+
strconv
.
Itoa
(
ports
[
i
]))
if
err
!=
nil
{
panic
(
err
)
}
}
cancel
()
client
.
Close
()
err
=
client
.
Close
()
if
err
!=
nil
{
panic
(
err
)
}
}
type
selector
bool
...
...
go/pserver/client/etcd_client.go
浏览文件 @
2db1b68d
...
...
@@ -12,8 +12,7 @@ import (
)
const
(
// DefaultEtcdTimeout is the default etcd timeout
DefaultEtcdTimeout
time
.
Duration
=
5
*
time
.
Second
defaultEtcdTimeout
time
.
Duration
=
5
*
time
.
Second
)
// EtcdClient is used by pserver client that is a part of trainer process.
...
...
@@ -48,7 +47,7 @@ func (p *EtcdClient) Desired() int {
psDesired
,
err
=
strconv
.
Atoi
(
string
(
resp
.
Kvs
[
0
]
.
Value
))
if
err
!=
nil
{
log
.
Errorf
(
"psDesired %
s
invalid %v"
,
psDesired
,
err
)
log
.
Errorf
(
"psDesired %
d
invalid %v"
,
psDesired
,
err
)
time
.
Sleep
(
p
.
timeout
)
continue
}
...
...
@@ -67,12 +66,12 @@ func (p *EtcdClient) List() []Server {
for
{
for
i
:=
0
;
i
<
psDesired
;
i
++
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
p
.
timeout
)
cancel
()
psKey
:=
pserver
.
PsPath
+
strconv
.
Itoa
(
i
)
log
.
Debugf
(
"checking %s"
,
psKey
)
resp
,
err
:=
p
.
client
.
Get
(
ctx
,
psKey
)
cancel
()
if
err
!=
nil
{
log
.
Infof
(
"Get psKey=%s error, %v"
,
psKey
,
err
)
log
.
Infof
(
"Get psKey=
%s error, %v"
,
psKey
,
err
)
time
.
Sleep
(
p
.
timeout
)
continue
}
...
...
@@ -107,11 +106,11 @@ func NewEtcd(endpoints string) *EtcdClient {
for
{
cli
,
err
=
clientv3
.
New
(
clientv3
.
Config
{
Endpoints
:
ep
,
DialTimeout
:
D
efaultEtcdTimeout
,
DialTimeout
:
d
efaultEtcdTimeout
,
})
if
err
!=
nil
{
log
.
Errorf
(
"Init etcd connection failed: %v"
,
err
)
time
.
Sleep
(
D
efaultEtcdTimeout
)
time
.
Sleep
(
d
efaultEtcdTimeout
)
continue
}
break
...
...
@@ -119,7 +118,7 @@ func NewEtcd(endpoints string) *EtcdClient {
log
.
Infof
(
"Connected to etcd: %s
\n
"
,
endpoints
)
client
:=
&
EtcdClient
{
client
:
cli
,
timeout
:
D
efaultEtcdTimeout
,
timeout
:
d
efaultEtcdTimeout
,
endpoints
:
ep
,
}
return
client
...
...
go/pserver/etcd_client.go
浏览文件 @
2db1b68d
...
...
@@ -177,10 +177,10 @@ func (e *EtcdClient) registerPserverEtcd(ctx context.Context, port int) (int, er
break
}
}
if
registered
==
true
{
if
registered
{
return
nil
}
return
errors
.
New
(
"not registerd, may due to already have enough pservers"
)
return
errors
.
New
(
"not register
e
d, may due to already have enough pservers"
)
},
concurrency
.
WithAbortContext
(
ctx
),
concurrency
.
WithIsolation
(
concurrency
.
RepeatableReads
))
if
err
!=
nil
{
...
...
@@ -211,8 +211,5 @@ func (e *EtcdClient) PutKey(key string, value []byte, timeout time.Duration) err
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
_
,
err
:=
e
.
etcdClient
.
Put
(
ctx
,
key
,
string
(
value
))
cancel
()
if
err
!=
nil
{
return
err
}
return
nil
}
go/pserver/optimizer.go
浏览文件 @
2db1b68d
...
...
@@ -14,8 +14,6 @@ import (
log
"github.com/sirupsen/logrus"
)
var
nullPtr
=
unsafe
.
Pointer
(
uintptr
(
0
))
type
optimizer
struct
{
opt
*
C
.
struct_paddle_optimizer
elementType
ElementType
...
...
@@ -23,7 +21,7 @@ type optimizer struct {
}
func
cArrayToSlice
(
p
unsafe
.
Pointer
,
len
int
)
[]
byte
{
if
p
==
n
ullPtr
{
if
p
==
n
il
{
return
nil
}
...
...
@@ -92,8 +90,8 @@ func (o *optimizer) UpdateParameter(g Gradient) error {
}
func
(
o
*
optimizer
)
Cleanup
()
{
if
unsafe
.
Pointer
(
o
.
opt
)
!=
n
ullPtr
{
if
unsafe
.
Pointer
(
o
.
opt
)
!=
n
il
{
C
.
paddle_release_optimizer
(
o
.
opt
)
o
.
opt
=
(
*
C
.
struct_paddle_optimizer
)(
n
ullPtr
)
o
.
opt
=
(
*
C
.
struct_paddle_optimizer
)(
n
il
)
}
}
go/pserver/service.go
浏览文件 @
2db1b68d
...
...
@@ -211,7 +211,7 @@ func (s *Service) GetParam(name string, parameter *Parameter) error {
// learning optimization methods are stochastic in
// nature. This race condition is allowed deliberately
// to save the program from making a copy of the
// paramter content.
// param
e
ter content.
parameter
.
Name
=
name
parameter
.
ElementType
=
opt
.
elementType
parameter
.
Content
=
opt
.
GetWeights
()
...
...
@@ -219,7 +219,7 @@ func (s *Service) GetParam(name string, parameter *Parameter) error {
}
// pserver save checkpoint
func
(
s
*
Service
)
doCheckpoint
()
error
{
func
(
s
*
Service
)
doCheckpoint
()
(
err
error
)
{
<-
s
.
initialized
s
.
mu
.
Lock
()
defer
s
.
mu
.
Unlock
()
...
...
@@ -237,9 +237,9 @@ func (s *Service) doCheckpoint() error {
}
var
buf
bytes
.
Buffer
encoder
:=
gob
.
NewEncoder
(
&
buf
)
err
:
=
encoder
.
Encode
(
cp
)
err
=
encoder
.
Encode
(
cp
)
if
err
!=
nil
{
return
err
return
}
cpMeta
:=
checkpointMeta
{}
...
...
@@ -248,10 +248,14 @@ func (s *Service) doCheckpoint() error {
h
:=
md5
.
New
()
cpMeta
.
MD5
=
hex
.
EncodeToString
(
h
.
Sum
(
buf
.
Bytes
()))
cpMetajson
,
_
:=
json
.
Marshal
(
cpMeta
)
cpMetajson
,
err
:=
json
.
Marshal
(
cpMeta
)
if
err
!=
nil
{
return
}
err
=
s
.
client
.
PutKey
(
filepath
.
Join
(
PsCheckpoint
,
strconv
.
Itoa
(
s
.
idx
)),
cpMetajson
,
3
*
time
.
Second
)
if
err
!=
nil
{
return
err
return
}
if
_
,
err
=
os
.
Stat
(
cpMeta
.
UUID
);
os
.
IsNotExist
(
err
)
{
log
.
Info
(
"checkpoint does not exists."
)
...
...
@@ -264,15 +268,32 @@ func (s *Service) doCheckpoint() error {
}
}
f
,
err
:=
os
.
Create
(
cpMeta
.
UUID
)
defer
f
.
Close
()
if
err
!=
nil
{
return
err
return
}
defer
func
()
{
closeErr
:=
f
.
Close
()
if
closeErr
!=
nil
{
if
err
!=
nil
{
log
.
Errorln
(
closeErr
)
}
else
{
// Set closeErr as return value.
err
=
closeErr
}
}
}()
writer
:=
bufio
.
NewWriter
(
f
)
_
,
err
=
writer
.
Write
(
buf
.
Bytes
())
writer
.
Flush
()
if
err
!=
nil
{
return
err
return
}
return
nil
err
=
writer
.
Flush
()
if
err
!=
nil
{
return
}
return
}
paddle/scripts/travis/check_style.sh
浏览文件 @
2db1b68d
...
...
@@ -13,6 +13,11 @@ export PATH=/usr/bin:$PATH
pre-commit
install
clang-format
--version
# set up go environment for running gometalinter
mkdir
-p
$GOPATH
/src/github.com/PaddlePaddle/
ln
-sf
$TRAVIS_BUILD_DIR
$GOPATH
/src/github.com/PaddlePaddle/Paddle
cd
$GOPATH
/src/github.com/PaddlePaddle/Paddle/go
;
glide
install
;
cd
-
if
!
pre-commit run
-a
;
then
git diff
--exit-code
fi
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录