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 Apr 11, 2024
1 parent 810e867 commit 087721b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 12 additions & 8 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
spdkapi "github.com/longhorn/longhorn-spdk-engine/pkg/api"
spdkclient "github.com/longhorn/longhorn-spdk-engine/pkg/client"

lhutils "github.com/longhorn/go-common-libs/utils"
"github.com/longhorn/longhorn-instance-manager/pkg/client"
"github.com/longhorn/longhorn-instance-manager/pkg/meta"
"github.com/longhorn/longhorn-instance-manager/pkg/types"
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 lhutils.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
10 changes: 3 additions & 7 deletions pkg/process/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
"k8s.io/mount-utils"

commonUtils "github.com/longhorn/go-common-libs/utils"
lhUtils "github.com/longhorn/go-common-libs/utils"
rpc "github.com/longhorn/longhorn-instance-manager/pkg/imrpc"
"github.com/longhorn/longhorn-instance-manager/pkg/types"
"github.com/longhorn/longhorn-instance-manager/pkg/util"
Expand Down Expand Up @@ -155,13 +155,13 @@ func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string

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

if mp, exists := volumeMountPointMap[volumeNameSHAStr]; exists {
p.Conditions[types.EngineConditionFilesystemReadOnly] = commonUtils.IsMountPointReadOnly(mp)
p.Conditions[types.EngineConditionFilesystemReadOnly] = lhUtils.IsMountPointReadOnly(mp)
processesToUpdate = append(processesToUpdate, p)
}
}
Expand All @@ -170,10 +170,6 @@ func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string
return processesToUpdate
}

func isEngineProcess(p *Process) bool {
return p.PortCount == DefaultEnginePortCount
}

// ProcessCreate will create a process according to the request.
// If the specified process name exists already, the creation will fail.
func (pm *Manager) ProcessCreate(ctx context.Context, req *rpc.ProcessCreateRequest) (ret *rpc.ProcessResponse, err error) {
Expand Down

0 comments on commit 087721b

Please sign in to comment.