Skip to content

split data more than 2M - #572

Merged
wonderflow merged 2 commits into
qiniu:masterfrom
redHJ:pdr-6528
Jun 28, 2018
Merged

wonderflow merged 2 commits into
qiniu:masterfrom
redHJ:pdr-6528

Conversation

@redHJ

@redHJ redHJ commented Jun 26, 2018

Copy link
Copy Markdown
Collaborator

@redHJ
redHJ force-pushed the pdr-6528 branch 4 times, most recently from 5c88c45 to 81123f9 Compare June 26, 2018 13:49
Comment thread sender/fault_tolerant.go Outdated
}
}

func splitData(data interface{}) (valArray []string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以写个单测

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写了

Comment thread sender/fault_tolerant.go
data := make([]Data, 1)
byteData, err := json.Marshal(failCtx.Datas[0])
if err != nil {
log.Warnf("Runner[%v] marshal data to string error %v", ft.runnerName, err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这里marshel出错,Data还是要全部返还回去,不能丢数据

@redHJ redHJ Jun 27, 2018 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边会返回过去,再后面几行,只是不放在pandora_stash,原样返回回去,看375行

@redHJ
redHJ force-pushed the pdr-6528 branch 4 times, most recently from 130d591 to 5079d95 Compare June 27, 2018 11:34
"github.com/qiniu/log"
"github.com/qiniu/pandora-go-sdk/base/reqerr"

"strings"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

导入分组修正一下

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了

Comment thread sender/fault_tolerant.go

end := lenData * splitSize
valArray = append(valArray, strData[end:])
return valArray

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实可以直接 return append(valArray, strData[end:])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了

Comment thread sender/fault_tolerant.go Outdated
// 此处将 data 改为 raw 放在 pandora_stash 中
if _, ok := failCtxData[KeyPandoraStash]; !ok {
log.Infof("Runner[%v] Sender[%v] try to convert data to string", ft.runnerName, ft.innerSender.Name())
data := make([]Data, 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是局部变量,放到下面else

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了

Comment thread sender/pandora/pandora.go Outdated
@@ -226,9 +226,9 @@ func NewSender(conf conf.MapConf) (pandoraSender sender.Sender, err error) {
// 当 schema free 为 false 时,需要自动创建 pandora_stash 字段

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释也加下,这个case需要实际测试一下

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了


func (s *mock_pandora) PostRepos_Data() echo.HandlerFunc {
return func(c echo.Context) error {
log.Println("PostRepos_Data request")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以删掉

}
}

func Test_SplitData(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个测的可以严格一点,加点中文特殊字符之类的

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了

Comment thread sender/fault_tolerant.go Outdated
}
}

func SplitData(data interface{}) (valArray []string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splitSize作为参数传入SplitData函数

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

传的data参数就应该是string类型

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改过了

@redHJ
redHJ force-pushed the pdr-6528 branch 3 times, most recently from 8faac4f to 405f9cc Compare June 28, 2018 08:47
@redHJ
redHJ force-pushed the pdr-6528 branch 2 times, most recently from 798cd82 to 88bb6e3 Compare June 28, 2018 09:12
Comment thread sender/fault_tolerant.go
}

if ft.opt.longDataDiscard {
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里丢地的话要打印一行日志

Comment thread sender/fault_tolerant.go Outdated
}

// failCtxData 的 key value 中找到 string 类型的 value 大于 2M,进行切片
if separateData != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(separateData)>0

Comment thread sender/fault_tolerant.go Outdated
for k, v := range separateData {
strVal, ok := v.(string)
if !ok {
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue

Comment thread sender/fault_tolerant.go
valArray = append(valArray, string(dataConverse[start:end]))
}

end := lenData * splitSize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end == len(dataConverse)

Comment thread sender/fault_tolerant.go Outdated
return
}
valArray := SplitData(strVal, int64(DefaultSplitSize))
if len(valArray) == 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边valArray不可能会空

Comment thread sender/fault_tolerant.go
}
}

func SplitData(data string, splitSize int64) (valArray []string) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个检查,如果splitSIze <=0 的话,返回 valArrary = []string{data}

Comment thread sender/fault_tolerant.go Outdated
retData[k] = v
}
retData[KeyPandoraSeparateId] = separateId + "_" + k + "_" + strconv.Itoa(idx)
retData[k] = val

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有个k,上面局部变量也有个k,真的好吗?

Comment thread sender/fault_tolerant.go Outdated
newFailCtx := new(datasContext)
for idx, val := range valArray {
data := Data{
KeyPandoraStash + "_" + strconv.Itoa(idx): val,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种case也要PandoraSeparateId呀,为什么这里就不加了?

@redHJ

redHJ commented Jun 28, 2018

Copy link
Copy Markdown
Collaborator Author

修过了

@wonderflow

Copy link
Copy Markdown
Contributor

LGTM

@wonderflow
wonderflow merged commit 49ff4e2 into qiniu:master Jun 28, 2018
@redHJ
redHJ deleted the pdr-6528 branch January 24, 2019 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants