Skip to content

Commit

Permalink
harmony: Address storage iface review
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 27, 2024
1 parent 4d6a0df commit c92779f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
2 changes: 0 additions & 2 deletions cmd/lotus-provider/deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ Get it with: jq .PrivateKey ~/.lotus-miner/keystore/MF2XI2BNNJ3XILLQOJUXMYLUMU`,
}
}

fmt.Println("last line of populate")

return nil
}

Expand Down
10 changes: 0 additions & 10 deletions lib/harmony/harmonytask/harmonytask.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,3 @@ func (e *TaskEngine) ResourcesAvailable() resources.Resources {
}
return tmp
}

// This helps <task>.Do() determine where its storage allocation is.
func (e *TaskEngine) GetWorkingLocation(taskID TaskID) string {
for _, t := range e.handlers {
if v, ok := t.LocationMap.Load(taskID); ok {
return v.(string)
}
}
return ""
}
29 changes: 12 additions & 17 deletions lib/harmony/harmonytask/task_type_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"runtime"
"strconv"
"sync"
"sync/atomic"
"time"

Expand All @@ -20,9 +19,8 @@ var log = logging.Logger("harmonytask")
type taskTypeHandler struct {
TaskInterface
TaskTypeDetails
TaskEngine *TaskEngine
Count atomic.Int32
LocationMap sync.Map
TaskEngine *TaskEngine
Count atomic.Int32
}

func (h *taskTypeHandler) AddTask(extra func(TaskID, *harmonydb.Tx) (bool, error)) {
Expand Down Expand Up @@ -97,21 +95,16 @@ top:
return false
}

var location string
releaseStorage := func() {
}
if h.TaskTypeDetails.Cost.Storage != nil {
if c := h.TaskTypeDetails.Cost.Storage.Claim; c != nil {
if err = c(int(*tID)); err != nil {
log.Infow("did not accept task", "task_id", strconv.Itoa(int(*tID)), "reason", "storage claim failed", "name", h.Name, "error", err)
return false
}
h.LocationMap.Store(*tID, location)
releaseStorage = func() {
if err := h.TaskTypeDetails.Cost.Storage.MarkComplete(); err != nil {
log.Errorw("Could not release storage", "error", err)
}
h.LocationMap.Delete(*tID)
if err = h.TaskTypeDetails.Cost.Storage.Claim(int(*tID)); err != nil {
log.Infow("did not accept task", "task_id", strconv.Itoa(int(*tID)), "reason", "storage claim failed", "name", h.Name, "error", err)
return false
}
releaseStorage = func() {
if err := h.TaskTypeDetails.Cost.Storage.MarkComplete(int(*tID)); err != nil {
log.Errorw("Could not release storage", "error", err)
}
}
}
Expand All @@ -128,6 +121,8 @@ top:
}
if ct == 0 {
log.Infow("did not accept task", "task_id", strconv.Itoa(int(*tID)), "reason", "already Taken", "name", h.Name)
releaseStorage()

var tryAgain = make([]TaskID, 0, len(ids)-1)
for _, id := range ids {
if id != *tID {
Expand Down Expand Up @@ -273,7 +268,7 @@ func (h *taskTypeHandler) AssertMachineHasCapacity() error {
}

if h.TaskTypeDetails.Cost.Storage != nil {
if has := h.TaskTypeDetails.Cost.Storage.HasCapacity; has != nil && !has() {
if !h.TaskTypeDetails.Cost.Storage.HasCapacity() {
return errors.New("Did not accept " + h.Name + " task: out of available Storage")
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/harmony/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Resources struct {
}

// Optional Storage management.
// See storagemgr/storagemgt.go for more details.
type Storage interface {
HasCapacity() bool

Expand All @@ -37,7 +36,7 @@ type Storage interface {

// This allows some other system to consider the task done.
// It's up to the caller to remove the data, if that applies.
MarkComplete() error
MarkComplete(taskID int) error
}
type Reg struct {
Resources
Expand Down

0 comments on commit c92779f

Please sign in to comment.