Merge pull request #642 from alecgrieser/cherry-pick-golang-db-cache-fix

fix: cache databases by cluster file and DB name in golang bindings.
This commit is contained in:
Evan Tschannen 2018-07-30 10:26:49 -07:00 committed by GitHub
commit 4ac909e4f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -193,12 +193,17 @@ var apiVersion int
var networkStarted bool
var networkMutex sync.Mutex
type DatabaseId struct {
clusterFile string
dbName string
}
var openClusters map[string]Cluster
var openDatabases map[string]Database
var openDatabases map[DatabaseId]Database
func init() {
openClusters = make(map[string]Cluster)
openDatabases = make(map[string]Database)
openDatabases = make(map[DatabaseId]Database)
}
func startNetwork() error {
@ -288,13 +293,13 @@ func Open(clusterFile string, dbName []byte) (Database, error) {
openClusters[clusterFile] = cluster
}
db, ok := openDatabases[string(dbName)]
db, ok := openDatabases[DatabaseId{clusterFile, string(dbName)}]
if !ok {
db, e = cluster.OpenDatabase(dbName)
if e != nil {
return Database{}, e
}
openDatabases[string(dbName)] = db
openDatabases[DatabaseId{clusterFile, string(dbName)}] = db
}
return db, nil

View File

@ -2,6 +2,14 @@
Release Notes
#############
5.2.7
=====
Bindings
--------
* The go bindings now caches database connections on a per-cluster basis. `(Issue #607) <https://github.com/apple/foundationdb/issues/607>`_
5.2.6
=====