-
Notifications
You must be signed in to change notification settings - Fork 269
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
optimize meta data #352
Merged
Merged
optimize meta data #352
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d105b36
optimize meta data
luky116 e161f12
reformat code
luky116 21f7e31
fix conn
luky116 e7c2acd
fix test
luky116 2cad577
fix test
luky116 3bf4702
fix test
luky116 13ce283
fix confilict
luky116 c6727c9
fix test
luky116 89caeda
fix test
luky116 dae38e4
add log
luky116 bcfe77a
fix test
luky116 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ import ( | |
"github.com/seata/seata-go/pkg/datasource/sql/types" | ||
"github.com/seata/seata-go/pkg/datasource/sql/undo" | ||
"github.com/seata/seata-go/pkg/protocol/branch" | ||
"github.com/seata/seata-go/pkg/protocol/message" | ||
"github.com/seata/seata-go/pkg/rm" | ||
) | ||
|
||
|
@@ -52,7 +51,7 @@ func init() { | |
_ = fs.Parse([]string{}) | ||
|
||
atSourceManager.worker = NewAsyncWorker(prometheus.DefaultRegisterer, asyncWorkerConf, atSourceManager) | ||
datasource.RegisterResourceManager(branch.BranchTypeAT, atSourceManager) | ||
rm.GetRmCacheInstance().RegisterResourceManager(atSourceManager) | ||
} | ||
|
||
type ATSourceManager struct { | ||
|
@@ -62,51 +61,43 @@ type ATSourceManager struct { | |
rmRemoting *rm.RMRemoting | ||
} | ||
|
||
// Register a Resource to be managed by Resource Manager | ||
func (mgr *ATSourceManager) RegisterResource(res rm.Resource) error { | ||
mgr.resourceCache.Store(res.GetResourceId(), res) | ||
|
||
return mgr.basic.RegisterResource(res) | ||
} | ||
|
||
// Unregister a Resource from the Resource Manager | ||
func (mgr *ATSourceManager) UnregisterResource(res rm.Resource) error { | ||
return mgr.basic.UnregisterResource(res) | ||
func (a *ATSourceManager) GetBranchType() branch.BranchType { | ||
return branch.BranchTypeAT | ||
} | ||
|
||
// Get all resources managed by this manager | ||
func (mgr *ATSourceManager) GetManagedResources() map[string]rm.Resource { | ||
ret := make(map[string]rm.Resource) | ||
func (a *ATSourceManager) GetCachedResources() *sync.Map { | ||
return &a.resourceCache | ||
} | ||
|
||
mgr.resourceCache.Range(func(key, value interface{}) bool { | ||
ret[key.(string)] = value.(rm.Resource) | ||
return true | ||
}) | ||
// Register a Resource to be managed by Resource Manager | ||
func (a *ATSourceManager) RegisterResource(res rm.Resource) error { | ||
a.resourceCache.Store(res.GetResourceId(), res) | ||
|
||
return ret | ||
return a.basic.RegisterResource(res) | ||
} | ||
|
||
// BranchRollback Rollback the corresponding transactions according to the request | ||
func (mgr *ATSourceManager) BranchRollback(ctx context.Context, req message.BranchRollbackRequest) (branch.BranchStatus, error) { | ||
val, ok := mgr.resourceCache.Load(req.ResourceId) | ||
// Unregister a Resource from the Resource Manager | ||
func (a *ATSourceManager) UnregisterResource(res rm.Resource) error { | ||
return a.basic.UnregisterResource(res) | ||
} | ||
|
||
if !ok { | ||
return branch.BranchStatusPhaseoneFailed, fmt.Errorf("resource %s not found", req.ResourceId) | ||
// Rollback a branch transaction | ||
func (a *ATSourceManager) BranchRollback(ctx context.Context, branchResource rm.BranchResource) (branch.BranchStatus, error) { | ||
var dbResource *DBResource | ||
if resource, ok := a.resourceCache.Load(branchResource.ResourceId); !ok { | ||
err := fmt.Errorf("DB resource is not exist, resourceId: %s", branchResource.ResourceId) | ||
return 0, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不应该用0吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 改为了 |
||
} else { | ||
dbResource, _ = resource.(*DBResource) | ||
} | ||
|
||
res := val.(*DBResource) | ||
|
||
undoMgr, err := undo.GetUndoLogManager(res.dbType) | ||
undoMgr, err := undo.GetUndoLogManager(dbResource.dbType) | ||
if err != nil { | ||
return branch.BranchStatusUnknown, err | ||
} | ||
|
||
/*conn, err := res.target.Conn(ctx) | ||
if err != nil { | ||
return branch.BranchStatusUnknown, err | ||
}*/ | ||
|
||
if err := undoMgr.RunUndo(ctx, req.Xid, req.BranchId, res.conn); err != nil { | ||
if err := undoMgr.RunUndo(ctx, branchResource.Xid, branchResource.BranchId, dbResource.db); err != nil { | ||
transErr, ok := err.(*types.TransactionError) | ||
if !ok { | ||
return branch.BranchStatusPhaseoneFailed, err | ||
|
@@ -123,28 +114,28 @@ func (mgr *ATSourceManager) BranchRollback(ctx context.Context, req message.Bran | |
} | ||
|
||
// BranchCommit | ||
func (mgr *ATSourceManager) BranchCommit(ctx context.Context, req message.BranchCommitRequest) (branch.BranchStatus, error) { | ||
mgr.worker.BranchCommit(ctx, req) | ||
func (a *ATSourceManager) BranchCommit(ctx context.Context, resource rm.BranchResource) (branch.BranchStatus, error) { | ||
a.worker.BranchCommit(ctx, resource) | ||
return branch.BranchStatusPhaseoneDone, nil | ||
} | ||
|
||
// LockQuery | ||
func (mgr *ATSourceManager) LockQuery(ctx context.Context, req message.GlobalLockQueryRequest) (bool, error) { | ||
func (a *ATSourceManager) LockQuery(ctx context.Context, param rm.LockQueryParam) (bool, error) { | ||
return false, nil | ||
} | ||
|
||
// BranchRegister | ||
func (mgr *ATSourceManager) BranchRegister(ctx context.Context, req rm.BranchRegisterParam) (int64, error) { | ||
return mgr.rmRemoting.BranchRegister(req) | ||
func (a *ATSourceManager) BranchRegister(ctx context.Context, req rm.BranchRegisterParam) (int64, error) { | ||
return a.rmRemoting.BranchRegister(req) | ||
} | ||
|
||
// BranchReport | ||
func (mgr *ATSourceManager) BranchReport(ctx context.Context, req message.BranchReportRequest) error { | ||
func (a *ATSourceManager) BranchReport(ctx context.Context, param rm.BranchReportParam) error { | ||
return nil | ||
} | ||
|
||
// CreateTableMetaCache | ||
func (mgr *ATSourceManager) CreateTableMetaCache(ctx context.Context, resID string, dbType types.DBType, | ||
func (a *ATSourceManager) CreateTableMetaCache(ctx context.Context, resID string, dbType types.DBType, | ||
db *sql.DB) (datasource.TableMetaCache, error) { | ||
return mgr.basic.CreateTableMetaCache(ctx, resID, dbType, db) | ||
return a.basic.CreateTableMetaCache(ctx, resID, dbType, db) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的