chore: optimize calculate digest (#3343)
Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
parent
5dee749657
commit
911efebd63
|
|
@ -55,7 +55,7 @@ var peerHostConfig = func() *DaemonOption {
|
||||||
IDC: "",
|
IDC: "",
|
||||||
},
|
},
|
||||||
Download: DownloadOption{
|
Download: DownloadOption{
|
||||||
CalculateDigest: false,
|
CalculateDigest: true,
|
||||||
PieceDownloadTimeout: 30 * time.Second,
|
PieceDownloadTimeout: 30 * time.Second,
|
||||||
GRPCDialTimeout: 10 * time.Second,
|
GRPCDialTimeout: 10 * time.Second,
|
||||||
WatchdogTimeout: 30 * time.Second,
|
WatchdogTimeout: 30 * time.Second,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ var peerHostConfig = func() *DaemonOption {
|
||||||
IDC: "",
|
IDC: "",
|
||||||
},
|
},
|
||||||
Download: DownloadOption{
|
Download: DownloadOption{
|
||||||
CalculateDigest: false,
|
CalculateDigest: true,
|
||||||
PieceDownloadTimeout: 30 * time.Second,
|
PieceDownloadTimeout: 30 * time.Second,
|
||||||
GRPCDialTimeout: 10 * time.Second,
|
GRPCDialTimeout: 10 * time.Second,
|
||||||
WatchdogTimeout: 30 * time.Second,
|
WatchdogTimeout: 30 * time.Second,
|
||||||
|
|
|
||||||
|
|
@ -1395,7 +1395,7 @@ func (pt *peerTaskConductor) done() {
|
||||||
// update storage metadata
|
// update storage metadata
|
||||||
if err := pt.UpdateStorage(); err == nil {
|
if err := pt.UpdateStorage(); err == nil {
|
||||||
// validate digest
|
// validate digest
|
||||||
if err = pt.Validate(); err == nil {
|
if err = pt.tryStore(); err == nil {
|
||||||
close(pt.successCh)
|
close(pt.successCh)
|
||||||
pt.span.SetAttributes(config.AttributePeerTaskSuccess.Bool(true))
|
pt.span.SetAttributes(config.AttributePeerTaskSuccess.Bool(true))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1408,7 +1408,7 @@ func (pt *peerTaskConductor) done() {
|
||||||
pt.span.SetAttributes(config.AttributePeerTaskSuccess.Bool(false))
|
pt.span.SetAttributes(config.AttributePeerTaskSuccess.Bool(false))
|
||||||
pt.span.SetAttributes(config.AttributePeerTaskCode.Int(int(pt.failedCode)))
|
pt.span.SetAttributes(config.AttributePeerTaskCode.Int(int(pt.failedCode)))
|
||||||
pt.span.SetAttributes(config.AttributePeerTaskMessage.String(pt.failedReason))
|
pt.span.SetAttributes(config.AttributePeerTaskMessage.String(pt.failedReason))
|
||||||
pt.Errorf("validate digest failed: %s", err)
|
pt.Errorf("store failed: %s", err)
|
||||||
metrics.PeerTaskFailedCount.WithLabelValues(metrics.FailTypeP2P).Add(1)
|
metrics.PeerTaskFailedCount.WithLabelValues(metrics.FailTypeP2P).Add(1)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1580,8 +1580,7 @@ func (pt *peerTaskConductor) fail() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate stores metadata and validates digest
|
func (pt *peerTaskConductor) tryStore() error {
|
||||||
func (pt *peerTaskConductor) Validate() error {
|
|
||||||
err := pt.GetStorage().Store(pt.ctx,
|
err := pt.GetStorage().Store(pt.ctx,
|
||||||
&storage.StoreRequest{
|
&storage.StoreRequest{
|
||||||
CommonTaskRequest: storage.CommonTaskRequest{
|
CommonTaskRequest: storage.CommonTaskRequest{
|
||||||
|
|
@ -1595,22 +1594,7 @@ func (pt *peerTaskConductor) Validate() error {
|
||||||
pt.Errorf("store metadata error: %s", err)
|
pt.Errorf("store metadata error: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
if !pt.CalculateDigest {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err = pt.GetStorage().ValidateDigest(
|
|
||||||
&storage.PeerTaskMetadata{
|
|
||||||
PeerID: pt.GetPeerID(),
|
|
||||||
TaskID: pt.GetTaskID(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
pt.Errorf("validate digest error: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pt.Debugf("validate digest ok")
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *peerTaskConductor) PublishPieceInfo(pieceNum int32, size uint32) {
|
func (pt *peerTaskConductor) PublishPieceInfo(pieceNum int32, size uint32) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue