Skip to content

Commit

Permalink
fix: parse the process name to get the process type instead of using …
Browse files Browse the repository at this point in the history
…port count

ref: longhorn/longhorn 7393

Signed-off-by: Jack Lin <jack.lin@suse.com>

fix: fix
  • Loading branch information
ChanYiLin committed Mar 25, 2024
1 parent 62c25ce commit 84feb41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 12 additions & 8 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/longhorn/longhorn-instance-manager/pkg/client"
"github.com/longhorn/longhorn-instance-manager/pkg/meta"
improc "github.com/longhorn/longhorn-instance-manager/pkg/process"
"github.com/longhorn/longhorn-instance-manager/pkg/types"

rpc "github.com/longhorn/longhorn-instance-manager/pkg/imrpc"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (ops V1DataEngineInstanceOps) InstanceCreate(req *rpc.InstanceCreateRequest
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Spec.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceCreate(req *rpc.InstanceCreateRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -198,7 +199,7 @@ func (ops V1DataEngineInstanceOps) InstanceDelete(req *rpc.InstanceDeleteRequest
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceDelete(req *rpc.InstanceDeleteRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -260,7 +261,7 @@ func (ops V1DataEngineInstanceOps) InstanceGet(req *rpc.InstanceGetRequest) (*rp
if err != nil {
return nil, err
}
return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceGet(req *rpc.InstanceGetRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -324,7 +325,11 @@ func (ops V1DataEngineInstanceOps) InstanceList(instances map[string]*rpc.Instan
return err
}
for _, process := range processes {
instances[process.Spec.Name] = processResponseToInstanceResponse(process)
processType := types.InstanceTypeReplica
if improc.IsEngineProcess(process.Spec.Name) {
processType = types.InstanceTypeEngine
}
instances[process.Spec.Name] = processResponseToInstanceResponse(process, processType)
}
return nil
}
Expand Down Expand Up @@ -387,7 +392,7 @@ func (ops V1DataEngineInstanceOps) InstanceReplace(req *rpc.InstanceReplaceReque
return nil, err
}

return processResponseToInstanceResponse(process), nil
return processResponseToInstanceResponse(process, req.Spec.Type), nil
}

func (ops V2DataEngineInstanceOps) InstanceReplace(req *rpc.InstanceReplaceRequest) (*rpc.InstanceResponse, error) {
Expand Down Expand Up @@ -648,12 +653,11 @@ func (s *Server) watchProcess(ctx context.Context, req *emptypb.Empty, client *c
}
}

func processResponseToInstanceResponse(p *rpc.ProcessResponse) *rpc.InstanceResponse {
func processResponseToInstanceResponse(p *rpc.ProcessResponse, processType string) *rpc.InstanceResponse {
return &rpc.InstanceResponse{
Spec: &rpc.InstanceSpec{
Name: p.Spec.Name,
// Leave Type empty. It will be determined in longhorn manager.
Type: "",
Type: processType,
// Deprecated
BackendStoreDriver: rpc.BackendStoreDriver_v1,
DataEngine: rpc.DataEngine_DATA_ENGINE_V1,
Expand Down
9 changes: 9 additions & 0 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package process

import (
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -186,3 +187,11 @@ func (p *Process) IsStopped() bool {
defer p.lock.RUnlock()
return p.State == StateStopped || p.State == StateError
}

func IsEngineProcess(name string) bool {
// engine process name example: pvc-5a8ee916-5989-46c6-bafc-ddbf7c802499-e-0
nameSlices := strings.Split(name, "-")
processType := nameSlices[len(nameSlices)-2]

return processType == "e"
}
2 changes: 1 addition & 1 deletion pkg/process/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string

for _, p := range pm.processes {
p.lock.Lock()
if isEngineProcess(p) && p.State == StateRunning {
if IsEngineProcess(p.Name) && p.State == StateRunning {
volumeName := util.ProcessNameToVolumeName(p.Name)
volumeNameSHA := sha256.Sum256([]byte(volumeName))
volumeNameSHAStr := hex.EncodeToString(volumeNameSHA[:])
Expand Down

0 comments on commit 84feb41

Please sign in to comment.