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

fix: apache/incubator-seata#6678 #718

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/datasource/sql/datasource/base/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -92,8 +93,9 @@ func (c *BaseTableMetaCache) refresh(ctx context.Context) {

for i := range v {
tm := v[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

问题不大,补一个单测

if _, ok := c.cache[tm.TableName]; !ok {
c.cache[tm.TableName] = &entry{
var upperTableName = strings.ToUpper(tm.TableName)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个ToUpper仅在refresh的加不行,需要在GetTableMeta的时,保证都是一致的

if _, ok := c.cache[upperTableName]; !ok {
c.cache[upperTableName] = &entry{
value: tm,
}
}
Expand Down Expand Up @@ -140,15 +142,17 @@ func (c *BaseTableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName

defer conn.Close()

v, ok := c.cache[tableName]
var upperTableName = strings.ToUpper(tableName)

v, ok := c.cache[upperTableName]
if !ok {
meta, err := c.trigger.LoadOne(ctx, dbName, tableName, conn)
meta, err := c.trigger.LoadOne(ctx, dbName, upperTableName, conn)
if err != nil {
return types.TableMeta{}, err
}

if meta != nil && !meta.IsEmpty() {
c.cache[tableName] = &entry{
c.cache[upperTableName] = &entry{
value: *meta,
lastAccess: time.Now(),
}
Expand All @@ -160,7 +164,7 @@ func (c *BaseTableMetaCache) GetTableMeta(ctx context.Context, dbName, tableName
}

v.lastAccess = time.Now()
c.cache[tableName] = v
c.cache[upperTableName] = v

return v.value, nil
}
Expand Down
Loading