diff --git a/Makefile b/Makefile deleted file mode 100644 index dee483d..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -OUTPUT_BINARY_NAME = "coordinator" -OUTPUT_DIR_NAME = "coordinator" - - -ASSETS_DIR_NAME = "assets" -BUILD_DIR = "../../build" - -build: - go build -o ${BUILD_DIR}/${OUTPUT_DIR_NAME}/${OUTPUT_BINARY_NAME}${OUTPUT_BINARY_EXT} - @if [ -d ${ASSETS_DIR_NAME} ] && [ -n "`ls -A ${ASSETS_DIR_NAME}`" ] ;then \ - cp -r ${ASSETS_DIR_NAME}/* ${BUILD_DIR}/${OUTPUT_DIR_NAME}/; \ - fi - -clean: - rm -f ${BUILD_DIR}/${OUTPUT_DIR_NAME}/${OUTPUT_BINARY_NAME} \ No newline at end of file diff --git a/internal/services/object.go b/internal/services/object.go index c98a60a..2411749 100644 --- a/internal/services/object.go +++ b/internal/services/object.go @@ -26,8 +26,11 @@ func (svc *Service) PreDownloadObject(msg *coormsg.PreDownloadObject) *coormsg.P } // 查询客户端所属节点 + foundBelongNode := true belongNode, err := svc.db.Node().GetByExternalIP(svc.db.SQLCtx(), msg.Body.ClientExternalIP) - if err != nil { + if err == sql.ErrNoRows { + foundBelongNode = false + } else if err != nil { logger.WithField("ClientExternalIP", msg.Body.ClientExternalIP). Warnf("query client belong node failed, err: %s", err.Error()) return ramsg.ReplyFailed[coormsg.PreDownloadObjectResp](errorcode.OPERATION_FAILED, "query client belong node failed") @@ -58,7 +61,7 @@ func (svc *Service) PreDownloadObject(msg *coormsg.PreDownloadObject) *coormsg.P node.ExternalIP, node.LocalIP, // LocationID 相同则认为是在同一个地域 - belongNode.LocationID == node.LocationID, + foundBelongNode && belongNode.LocationID == node.LocationID, )) } @@ -152,8 +155,11 @@ func (svc *Service) PreUploadRepObject(msg *coormsg.PreUploadRepObject) *coormsg } // 查询客户端所属节点 + foundBelongNode := true belongNode, err := svc.db.Node().GetByExternalIP(svc.db.SQLCtx(), msg.Body.ClientExternalIP) - if err != nil { + if err == sql.ErrNoRows { + foundBelongNode = false + } else if err != nil { logger.WithField("ClientExternalIP", msg.Body.ClientExternalIP). Warnf("query client belong node failed, err: %s", err.Error()) return ramsg.ReplyFailed[coormsg.PreUploadResp](errorcode.OPERATION_FAILED, "query client belong node failed") @@ -166,7 +172,7 @@ func (svc *Service) PreUploadRepObject(msg *coormsg.PreUploadRepObject) *coormsg node.ExternalIP, node.LocalIP, // LocationID 相同则认为是在同一个地域 - belongNode.LocationID == node.LocationID, + foundBelongNode && belongNode.LocationID == node.LocationID, )) } @@ -226,8 +232,11 @@ func (svc *Service) PreUpdateRepObject(msg *coormsg.PreUpdateRepObject) *coormsg } // 查询客户端所属节点 + foundBelongNode := true belongNode, err := svc.db.Node().GetByExternalIP(svc.db.SQLCtx(), msg.Body.ClientExternalIP) - if err != nil { + if err == sql.ErrNoRows { + foundBelongNode = false + } else if err != nil { logger.WithField("ClientExternalIP", msg.Body.ClientExternalIP). Warnf("query client belong node failed, err: %s", err.Error()) return ramsg.ReplyFailed[coormsg.PreUpdateRepObjectResp](errorcode.OPERATION_FAILED, "query client belong node failed") @@ -247,7 +256,7 @@ func (svc *Service) PreUpdateRepObject(msg *coormsg.PreUpdateRepObject) *coormsg node.ExternalIP, node.LocalIP, // LocationID 相同则认为是在同一个地域 - belongNode.LocationID == node.LocationID, + foundBelongNode && belongNode.LocationID == node.LocationID, // 此节点存储了对象旧文件 lo.ContainsBy(cachingNodes, func(n model.Node) bool { return n.NodeID == node.NodeID }), )) diff --git a/magefiles/magefile.go b/magefiles/magefile.go new file mode 100644 index 0000000..db98358 --- /dev/null +++ b/magefiles/magefile.go @@ -0,0 +1,22 @@ +//go:build mage + +package main + +import ( + "magefiles" + "magefiles/utils" + + //mage:import + "magefiles/targets" +) + +var Default = Build + +func Build() error { + return utils.Build(magefiles.BuildArgs{ + OutputBinName: "coordinator", + OutputDirName: "coordinator", + AssetsDir: "assets", + PubArgs: targets.PubGoBuildArgs, + }) +}