You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

undo.go 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package undo
  18. import (
  19. "database/sql"
  20. "database/sql/driver"
  21. "errors"
  22. "sync"
  23. "github.com/seata/seata-go/pkg/datasource/sql/types"
  24. )
  25. var solts = map[types.DBType]*undoLogMgrHolder{}
  26. type undoLogMgrHolder struct {
  27. once sync.Once
  28. mgr UndoLogManager
  29. }
  30. func Regis(m UndoLogManager) error {
  31. if _, exist := solts[m.DBType()]; exist {
  32. return nil
  33. }
  34. solts[m.DBType()] = &undoLogMgrHolder{
  35. mgr: m,
  36. once: sync.Once{},
  37. }
  38. return nil
  39. }
  40. // UndoLogManager
  41. type UndoLogManager interface {
  42. Init()
  43. // InsertUndoLog
  44. InsertUndoLog(l []BranchUndoLog, tx driver.Tx) error
  45. // DeleteUndoLog
  46. DeleteUndoLogs(xid []string, branchID []int64, conn *sql.Conn) error
  47. // FlushUndoLog
  48. FlushUndoLog(txCtx *types.TransactionContext, tx driver.Tx) error
  49. // RunUndo
  50. RunUndo(xid string, branchID int64, conn *sql.Conn) error
  51. // DBType
  52. DBType() types.DBType
  53. }
  54. // GetUndoLogManager
  55. func GetUndoLogManager(d types.DBType) (UndoLogManager, error) {
  56. v, ok := solts[d]
  57. if !ok {
  58. return nil, errors.New("not found UndoLogManager")
  59. }
  60. v.once.Do(func() {
  61. v.mgr.Init()
  62. })
  63. return v.mgr, nil
  64. }
  65. // BranchUndoLog
  66. type BranchUndoLog struct {
  67. // Xid
  68. Xid string
  69. // BranchID
  70. BranchID string
  71. // Logs
  72. Logs []SQLUndoLog
  73. }
  74. // Marshal
  75. func (b *BranchUndoLog) Marshal() []byte {
  76. return nil
  77. }
  78. // SQLUndoLog
  79. type SQLUndoLog struct {
  80. SQLType types.SQLType
  81. TableName string
  82. Images types.RoundRecordImage
  83. }
  84. // UndoLogParser
  85. type UndoLogParser interface {
  86. // GetName
  87. GetName() string
  88. // GetDefaultContent
  89. GetDefaultContent() []byte
  90. // Encode
  91. Encode(l BranchUndoLog) []byte
  92. // Decode
  93. Decode(b []byte) BranchUndoLog
  94. }