-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Preparestmt use LRU Map instead default map #7435
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
Conversation
gorm.go
Outdated
@@ -65,6 +69,11 @@ type Config struct { | |||
callbacks *callbacks | |||
cacheStore *sync.Map | |||
} | |||
type PrepareStmtLruConfig struct { |
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.
This is no longer needed?
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.
already deleted
gorm.go
Outdated
@@ -268,7 +277,7 @@ func (db *DB) Session(config *Session) *DB { | |||
if v, ok := db.cacheStore.Load(preparedStmtDBKey); ok { | |||
preparedStmt = v.(*PreparedStmtDB) | |||
} else { | |||
preparedStmt = NewPreparedStmtDB(db.ConnPool) | |||
preparedStmt = NewPreparedStmtDB(db.ConnPool, db.Config.PrepareStmtMaxSize, db.Config.PrepareStmtTTL) |
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.
Do we need to allow session-level configuration? For example, configure it here: https://github.com/go-gorm/gorm/blob/master/gorm.go#L107
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.
if config.PrepareStmt {
preparedStmt := NewPreparedStmtDB(db.ConnPool, config.PrepareStmtMaxSize, config.PrepareStmtTTL)
db.cacheStore.Store(preparedStmtDBKey, preparedStmt)
db.ConnPool = preparedStmt
}
session default use static config
prepare_stmt.go
Outdated
Mux *sync.RWMutex | ||
ConnPool | ||
} | ||
|
||
func NewPreparedStmtDB(connPool ConnPool) *PreparedStmtDB { | ||
const DEFAULT_MAX_SIZE = (1 << 63) - 1 |
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.
Could we relocate the majority of the following code to an internal package, such as internal/stmt_store, to prevent the exposure of additional structs or methods?
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.
cause circular dependency
…o feature/sup_lru_prepareStmt
Build failed in 32bit environment GOARCH=386 go test -timeout 20m -v ./...
shell: /usr/bin/bash -e {0}
# gorm.io/gorm/internal/stmt_store
Error:
../../../go/pkg/mod/gorm.io/[email protected]/internal/stmt_store/stmt_store.go:99:10:
cannot use defaultMaxSize (untyped int constant 9223372036854775807) as int value in assignment (overflows) |
We've just hit this as well in #7442. A .1 release would be highly appreciated. |
GROM default map may be cause memory leak
What did this pull request do?
PrepareStmt support use lrumap instead default Map
PreparedStmtDB stmt change to interface to defined maps
User Case Description
TestPreparedStmtLruFromTransaction check lru active