This is an automated email from the ASF dual-hosted git repository.

yixia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new ff2bde29 add undo compressor log support (#659)
ff2bde29 is described below

commit ff2bde2996e34cff70286bad4f26bf0eafa93a63
Author: smiletrl <[email protected]>
AuthorDate: Thu Feb 1 17:31:31 2024 +0800

    add undo compressor log support (#659)
---
 pkg/compressor/compressor_factory.go   | 39 ---------------------
 pkg/compressor/compressor_type.go      | 62 +++++++++++-----------------------
 pkg/compressor/compressor_type_test.go | 35 -------------------
 pkg/datasource/sql/undo/base/undo.go   |  7 ++--
 pkg/datasource/sql/undo/config.go      |  5 +--
 5 files changed, 25 insertions(+), 123 deletions(-)

diff --git a/pkg/compressor/compressor_factory.go 
b/pkg/compressor/compressor_factory.go
deleted file mode 100644
index e4dbfa53..00000000
--- a/pkg/compressor/compressor_factory.go
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or 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
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package compressor
-
-func (c CompressorType) GetCompressor() Compressor {
-       switch c.String() {
-       case CompressorNone.String():
-               return &NoneCompressor{}
-       case CompressorGzip.String():
-               return &Gzip{}
-       case CompressorZip.String():
-               return &Zip{}
-       case CompressorBzip2.String():
-               return &Bzip2{}
-       case CompressorLz4.String():
-               return &Lz4{}
-       case CompressorZstd.String():
-               return &Zstd{}
-       case CompressorDeflate.String():
-               return &DeflateCompress{}
-       default:
-               panic("compressor type not implement")
-       }
-}
diff --git a/pkg/compressor/compressor_type.go 
b/pkg/compressor/compressor_type.go
index bb4d3e08..44b19d11 100644
--- a/pkg/compressor/compressor_type.go
+++ b/pkg/compressor/compressor_type.go
@@ -17,61 +17,37 @@
 
 package compressor
 
-type CompressorType int8
+type CompressorType string
 
 const (
-       CompressorNone CompressorType = iota
-       CompressorGzip
-       CompressorZip
-       CompressorSevenz
-       CompressorBzip2
-       CompressorLz4
-       CompressorDeflate
-       CompressorZstd
+       // "None" means no compressor is used
+       CompressorNone    CompressorType = "None"
+       CompressorGzip    CompressorType = "Gzip"
+       CompressorZip     CompressorType = "Zip"
+       CompressorSevenz  CompressorType = "Sevenz"
+       CompressorBzip2   CompressorType = "Bzip2"
+       CompressorLz4     CompressorType = "Lz4"
+       CompressorDeflate CompressorType = "Deflate"
+       CompressorZstd    CompressorType = "Zstd"
 )
 
-func (c CompressorType) String() string {
+func (c CompressorType) GetCompressor() Compressor {
        switch c {
        case CompressorNone:
-               return "CompressorNone"
+               return &NoneCompressor{}
        case CompressorGzip:
-               return "CompressorGzip"
+               return &Gzip{}
        case CompressorZip:
-               return "CompressorZip"
-       case CompressorSevenz:
-               return "CompressorSevenz"
+               return &Zip{}
        case CompressorBzip2:
-               return "CompressorBzip2"
+               return &Bzip2{}
        case CompressorLz4:
-               return "CompressorLz4"
+               return &Lz4{}
        case CompressorZstd:
-               return "CompressorZstd"
+               return &Zstd{}
        case CompressorDeflate:
-               return "CompressorDeflate"
+               return &DeflateCompress{}
        default:
-               return ""
-       }
-}
-
-var compressor map[string]CompressorType
-
-func GetByName(name string) CompressorType {
-       if compressor == nil {
-               compressor = map[string]CompressorType{
-                       CompressorNone.String():    CompressorNone,
-                       CompressorGzip.String():    CompressorGzip,
-                       CompressorZip.String():     CompressorZip,
-                       CompressorSevenz.String():  CompressorSevenz,
-                       CompressorBzip2.String():   CompressorBzip2,
-                       CompressorLz4.String():     CompressorLz4,
-                       CompressorZstd.String():    CompressorZstd,
-                       CompressorDeflate.String(): CompressorDeflate,
-               }
-       }
-
-       if v, ok := compressor[name]; ok {
-               return v
-       } else {
-               return CompressorNone
+               return &NoneCompressor{}
        }
 }
diff --git a/pkg/compressor/compressor_type_test.go 
b/pkg/compressor/compressor_type_test.go
deleted file mode 100644
index 5af380a1..00000000
--- a/pkg/compressor/compressor_type_test.go
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or 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
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package compressor
-
-import (
-       "testing"
-
-       "github.com/stretchr/testify/assert"
-)
-
-func TestCompressorType(t *testing.T) {
-       assert.Equal(t, CompressorNone, CompressorType(0))
-       assert.Equal(t, CompressorGzip, CompressorType(1))
-       assert.Equal(t, CompressorZip, CompressorType(2))
-       assert.Equal(t, CompressorSevenz, CompressorType(3))
-       assert.Equal(t, CompressorBzip2, CompressorType(4))
-       assert.Equal(t, CompressorLz4, CompressorType(5))
-       assert.Equal(t, CompressorDeflate, CompressorType(6))
-       assert.Equal(t, CompressorZstd, CompressorType(7))
-}
diff --git a/pkg/datasource/sql/undo/base/undo.go 
b/pkg/datasource/sql/undo/base/undo.go
index 3e5f4499..fb685301 100644
--- a/pkg/datasource/sql/undo/base/undo.go
+++ b/pkg/datasource/sql/undo/base/undo.go
@@ -223,8 +223,7 @@ func (m *BaseUndoLogManager) FlushUndoLog(tranCtx 
*types.TransactionContext, con
 
        parseContext := make(map[string]string, 0)
        parseContext[serializerKey] = "json"
-       // Todo use config
-       parseContext[compressorTypeKey] = compressor.CompressorNone.String()
+       parseContext[compressorTypeKey] = undo.UndoConfig.CompressConfig.Type
        undoLogContent := m.encodeUndoLogCtx(parseContext)
        rollbackInfo, err := m.serializeBranchUndoLog(&branchUndoLog, 
parseContext[serializerKey])
        if err != nil {
@@ -379,7 +378,7 @@ func (m *BaseUndoLogManager) 
insertUndoLogWithGlobalFinished(ctx context.Context
        // todo use config to replace
        parseContext := make(map[string]string, 0)
        parseContext[serializerKey] = "json"
-       parseContext[compressorTypeKey] = compressor.CompressorNone.String()
+       parseContext[compressorTypeKey] = undo.UndoConfig.CompressConfig.Type
        undoLogContent := m.encodeUndoLogCtx(parseContext)
 
        logParse, err := parser.GetCache().Load(parseContext[serializerKey])
@@ -495,7 +494,7 @@ func (m *BaseUndoLogManager) getRollbackInfo(rollbackInfo 
[]byte, undoContext ma
        res := rollbackInfo
        // get compress type
        if v, ok := undoContext[compressorTypeKey]; ok {
-               res, err = 
compressor.GetByName(v).GetCompressor().Decompress(rollbackInfo)
+               res, err = 
compressor.CompressorType(v).GetCompressor().Decompress(rollbackInfo)
                if err != nil {
                        log.Errorf("[getRollbackInfo] decompress fail, err: 
%+v", err)
                        return nil, err
diff --git a/pkg/datasource/sql/undo/config.go 
b/pkg/datasource/sql/undo/config.go
index fb980560..f06324db 100644
--- a/pkg/datasource/sql/undo/config.go
+++ b/pkg/datasource/sql/undo/config.go
@@ -19,6 +19,8 @@ package undo
 
 import (
        "flag"
+
+       "github.com/seata/seata-go/pkg/compressor"
 )
 
 var (
@@ -52,7 +54,6 @@ func (u *Config) RegisterFlagsWithPrefix(prefix string, f 
*flag.FlagSet) {
 }
 
 func (c *CompressConfig) RegisterFlagsWithPrefix(prefix string, f 
*flag.FlagSet) {
-       f.BoolVar(&c.Enable, prefix+".enable", true, "Whether compression is 
required.")
-       f.StringVar(&c.Type, prefix+".type", "zip", "Compression type")
+       f.StringVar(&c.Type, prefix+".type", string(compressor.CompressorNone), 
"Compression type")
        f.StringVar(&c.Threshold, prefix+".threshold", "64k", "Compression 
threshold")
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to