Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
power-node
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
power-node
Commits
d7b442d3
Commit
d7b442d3
authored
Jun 24, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix lru map read and write error
parent
da1e895c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
9 deletions
+43
-9
node_manager.go
models/node_manager.go
+35
-0
msg_handler.go
nm/msg_handler.go
+6
-6
task_handler.go
nm/task_handler.go
+2
-3
No files found.
models/node_manager.go
View file @
d7b442d3
package
models
import
(
"github.com/golang/groupcache/lru"
nodeManagerV1
"github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
"sync"
"time"
...
...
@@ -134,3 +135,37 @@ func (n *NodeManagerClient) UpdateStatus(status bool) {
defer
n
.
mutex
.
Unlock
()
n
.
Status
=
status
}
// SafeLruCache is a thread-safe wrapper around lru.Cache
type
SafeLruCache
struct
{
mu
sync
.
Mutex
cache
*
lru
.
Cache
}
// NewSafeLruCache creates a new SafeLruCache
func
NewSafeLruCache
(
maxEntries
int
)
*
SafeLruCache
{
return
&
SafeLruCache
{
cache
:
lru
.
New
(
maxEntries
),
}
}
// Add adds a value to the cache
func
(
sc
*
SafeLruCache
)
Add
(
key
lru
.
Key
,
value
interface
{})
{
sc
.
mu
.
Lock
()
defer
sc
.
mu
.
Unlock
()
sc
.
cache
.
Add
(
key
,
value
)
}
// Get retrieves a value from the cache
func
(
sc
*
SafeLruCache
)
Get
(
key
lru
.
Key
)
(
interface
{},
bool
)
{
sc
.
mu
.
Lock
()
defer
sc
.
mu
.
Unlock
()
return
sc
.
cache
.
Get
(
key
)
}
// Remove removes a value from the cache
func
(
sc
*
SafeLruCache
)
Remove
(
key
lru
.
Key
)
{
sc
.
mu
.
Lock
()
defer
sc
.
mu
.
Unlock
()
sc
.
cache
.
Remove
(
key
)
}
nm/msg_handler.go
View file @
d7b442d3
...
...
@@ -85,13 +85,13 @@ func (n *NodeManagerHandler) DistributionMsgWorker(nodeManagerMsgChan chan *node
isSuccess
=
false
taskExecRes
.
TaskExecError
=
fmt
.
Sprintf
(
"worker:%s-%s-%s"
,
conf
.
GetConfig
()
.
SignPublicAddress
.
Hex
(),
"Task exec error"
,
taskExecRes
.
TaskExecError
)
}
reqHash
,
respHash
,
minerSign
:=
taskMsgWorker
.
GetMinerSign
(
taskMsg
,
taskExecRes
.
TaskRespBody
)
_
,
_
,
minerSign
:=
taskMsgWorker
.
GetMinerSign
(
taskMsg
,
taskExecRes
.
TaskRespBody
)
taskResultParams
:=
utils
.
BuildParams
(
taskMsg
.
TaskId
,
containerSign
,
minerSign
,
taskExecRes
,
isSuccess
)
taskMsgWorker
.
LruCache
.
Add
(
taskMsg
.
TaskId
+
models
.
TaskType
,
taskMsg
.
TaskType
)
taskMsgWorker
.
LruCache
.
Add
(
taskMsg
.
TaskId
+
models
.
ContainerSign
,
containerSign
)
taskMsgWorker
.
LruCache
.
Add
(
taskMsg
.
TaskId
+
models
.
MinerSign
,
minerSign
)
taskMsgWorker
.
LruCache
.
Add
(
taskMsg
.
TaskId
+
models
.
ReqHash
,
reqHash
)
taskMsgWorker
.
LruCache
.
Add
(
taskMsg
.
TaskId
+
models
.
RespHash
,
respHash
)
//
taskMsgWorker.LruCache.Add(taskMsg.TaskId+models.TaskType, taskMsg.TaskType)
//
taskMsgWorker.LruCache.Add(taskMsg.TaskId+models.ContainerSign, containerSign)
//
taskMsgWorker.LruCache.Add(taskMsg.TaskId+models.MinerSign, minerSign)
//
taskMsgWorker.LruCache.Add(taskMsg.TaskId+models.ReqHash, reqHash)
//
taskMsgWorker.LruCache.Add(taskMsg.TaskId+models.RespHash, respHash)
msgRespWorker
.
RegisterMsgResp
(
n
.
nodeManager
,
n
.
worker
,
SubmitResultResp
,
taskResultParams
)
log
.
Info
(
"--------------taskMsg--------------:"
,
taskMsg
)
}(
n
.
msgRespWorker
,
n
.
taskMsgWorker
,
taskMsg
)
...
...
nm/task_handler.go
View file @
d7b442d3
...
...
@@ -11,7 +11,6 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/golang/groupcache/lru"
baseV1
"github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1"
nodeManagerV1
"github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
"io"
...
...
@@ -27,7 +26,7 @@ import (
type
TaskWorker
struct
{
Wg
*
sync
.
WaitGroup
LruCache
*
lru
.
Cache
LruCache
*
models
.
SafeLru
Cache
DockerOp
*
operate
.
DockerOp
CmdOp
*
operate
.
Command
TaskMsg
chan
*
nodeManagerV1
.
PushTaskMessage
...
...
@@ -53,7 +52,7 @@ type TaskOp struct {
func
NewTaskWorker
(
op
*
operate
.
DockerOp
)
*
TaskWorker
{
return
&
TaskWorker
{
Wg
:
&
sync
.
WaitGroup
{},
LruCache
:
lru
.
New
(
100
),
LruCache
:
models
.
NewSafeLruCache
(
100
),
DockerOp
:
op
,
TaskMsg
:
make
(
chan
*
nodeManagerV1
.
PushTaskMessage
,
0
),
IsExecAiTask
:
false
,
...
...
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