Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: undolog add decompressor func #457

Merged
merged 236 commits into from
Mar 14, 2023

Conversation

wang1309
Copy link
Contributor

What this PR does:
add undo log decompressor func

Which issue(s) this PR fixes:
none

Fixes #449

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2023

Codecov Report

Merging #457 (b244cab) into master (437f712) will decrease coverage by 0.72%.
The diff coverage is 0.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #457      +/-   ##
==========================================
- Coverage   39.05%   38.33%   -0.72%     
==========================================
  Files         144      150       +6     
  Lines        9120    10011     +891     
==========================================
+ Hits         3562     3838     +276     
- Misses       5264     5855     +591     
- Partials      294      318      +24     
Impacted Files Coverage Δ
pkg/client/client.go 0.00% <ø> (ø)
pkg/compressor/compressor_factory.go 0.00% <0.00%> (ø)
pkg/compressor/compressor_type.go 0.00% <0.00%> (ø)
pkg/compressor/none_compressor.go 0.00% <0.00%> (ø)
pkg/datasource/sql/tx_at.go 23.52% <0.00%> (-2.19%) ⬇️
pkg/datasource/sql/parser/parser_factory.go 50.00% <0.00%> (-0.95%) ⬇️
pkg/datasource/sql/exec/at/delete_executor.go 23.23% <0.00%> (-0.24%) ⬇️
pkg/rm/init.go 0.00% <0.00%> (ø)
pkg/client/config.go 61.66% <0.00%> (ø)
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件不要

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个暂时好像不能删,项目编译的时候没有执行go generate,导致CI通过不了。

Copy link
Contributor

Choose a reason for hiding this comment

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

这个暂时好像不能删,项目编译的时候没有执行go generate,导致CI通过不了。

这个文件的作用是来干嘛的呀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

用于获取常量的字符串

Copy link
Contributor

Choose a reason for hiding this comment

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

用于获取常量的字符串

为啥会影响CI呢?看看报啥错,挺奇怪

Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件看看可以删除了吗


"github.com/seata/seata-go/pkg/util/log"
)

type DeflateCompress struct{}

var (
deflateOnce sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

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

所有的单例都去了吧,每次返回一个新对象

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

pkg/compressor/compressor_factory.go Outdated Show resolved Hide resolved
@@ -17,21 +17,6 @@

package compressor

type CompressorType int8
Copy link
Contributor

Choose a reason for hiding this comment

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

这个看看是否可以直接写在这里

Copy link
Contributor Author

Choose a reason for hiding this comment

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

感觉可能还是放在compress_type 文件一起好点,比较内聚一点。

// UndoLogId The constant undo_log column name xid
// this field is not use in mysql
UndoLogId = "id"

Copy link
Contributor

Choose a reason for hiding this comment

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

这些变量如果没用到,就删了吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -213,7 +215,7 @@ func (m *BaseUndoLogManager) FlushUndoLog(tranCtx *types.TransactionContext, con

parseContext := make(map[string]string, 0)
parseContext[serializerKey] = "jackson"
parseContext[compressorTypeKey] = "NONE"
parseContext[compressorTypeKey] = compressor.CompressorNone.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

这里从配置文件读取使用了哪个压缩方式
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

看代码seata-go这里默认是不压缩,应该没做这一步。

@@ -480,16 +494,30 @@ func (m *BaseUndoLogManager) DecodeMap(str string) map[string]string {
return res
}

func (m *BaseUndoLogManager) UnmarshalContext(undoContext []byte) (map[string]string, error) {
res := make(map[string]string)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里是和这个方法做对对应吗?看这里的逻辑有点复杂, 再确认下哈
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

存储的时候用的 json 格式

Copy link
Contributor Author

Choose a reason for hiding this comment

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

所以这里用 unmarshal 是和存储一一对应的,应该没啥问题。

@106umao 106umao changed the title Feat undolog add decompressor func feat undolog add decompressor func Feb 11, 2023
@106umao 106umao changed the title feat undolog add decompressor func feat: undolog add decompressor func Feb 11, 2023
testUndoLog := func() {
manager := mysql.NewUndoLogManager()

db, err := sql.Open(sql2.SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_client?multiStatements=true")
Copy link
Contributor

Choose a reason for hiding this comment

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

数据库操作应该是可以 Mock 的,另外这个测试文件放在 pkg/datasource/sql/undo/base 下比较合适

Copy link
Contributor Author

Choose a reason for hiding this comment

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

放在这里会有循环引用问题,这个文件也可以先删了

# By default we only accept connections from localhost
bind-address = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
Copy link
Contributor

Choose a reason for hiding this comment

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

缺少换行符

- ./mysql:/docker-entrypoint-initdb.d
- ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
ports:
- "3306:3306"
Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件应该拆一个 pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

应该误提交了,我回退一下

sleep 5
curl http://127.0.0.1:7091
sleep 10

Copy link
Contributor

Choose a reason for hiding this comment

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

同上

`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_unionkey` (`xid`,`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
Copy link
Contributor

Choose a reason for hiding this comment

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

用于获取常量的字符串

为啥会影响CI呢?看看报啥错,挺奇怪

var compressor map[string]CompressorType

func GetByName(name string) CompressorType {
if compressor == nil {
Copy link
Contributor

@luky116 luky116 Feb 11, 2023

Choose a reason for hiding this comment

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

改为switch...case,每次返回一个新的对象,这样就不要用这个map了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯嗯,请教一下为何改为 switch case,感觉这里实现问题不大。

@@ -23,6 +23,10 @@ import (

type Zstd struct{}

func NewZstd() *Zstd {
Copy link
Contributor

Choose a reason for hiding this comment

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

如果new没有参数,可以不用写New函数?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯,感觉还是有好一点,这能够收敛一下,后期也好维护。

* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件看看可以删除了吗

@@ -354,7 +368,7 @@ func (m *BaseUndoLogManager) insertUndoLogWithGlobalFinished(ctx context.Context
// todo use config to replace
parseContext := make(map[string]string, 0)
parseContext[serializerKey] = "jackson"
parseContext[compressorTypeKey] = "NONE"
parseContext[compressorTypeKey] = compressor.CompressorNone.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

这里能读取下配置文件吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

嗯,这块配置现在有了吗,我看有个todo

CompressorSevenz
CompressorBzip2
CompressorLz4
CompressorDefault
Copy link
Contributor

Choose a reason for hiding this comment

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

image

CompressorDefault和CompressorMaxl好像和java对不上?
CompressorDeflate应该在CompressorZstd前面

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

var compressorFactory map[string]Compressor

func (c CompressorType) GetCompressor() Compressor {
if compressorFactory == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

switch

不用单例模式

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -27,6 +27,10 @@ import (
type Bzip2 struct {
}

func NewBizp2() *Bzip2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

没有参数不用New

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

type CompressorType int8

const (
CompressorNone CompressorType = iota
Copy link
Contributor

Choose a reason for hiding this comment

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

加一个单测

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


var _CompressorType_index = [...]uint8{0, 14, 28, 41, 57, 72, 85, 102, 116, 133, 147}

func (i CompressorType) String() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

手动写String函数

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -213,7 +215,7 @@ func (m *BaseUndoLogManager) FlushUndoLog(tranCtx *types.TransactionContext, con

parseContext := make(map[string]string, 0)
parseContext[serializerKey] = "jackson"
parseContext[compressorTypeKey] = "NONE"
parseContext[compressorTypeKey] = compressor.CompressorNone.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

加个todo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@github-actions github-actions bot removed the module/rm label Mar 9, 2023
@georgehao georgehao merged commit 46da59f into apache:master Mar 14, 2023
georgehao pushed a commit to georgehao/seata-go that referenced this pull request May 7, 2023
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.

AT undo log 解压缩集成