Skip to content

Commit

Permalink
Merge "[FAB-2709] Fix CouchDB retry logic"
Browse files Browse the repository at this point in the history
  • Loading branch information
yacovm authored and Gerrit Code Review committed Apr 18, 2017
2 parents 599a7fa + 987496f commit c4d192b
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 129 deletions.
2 changes: 2 additions & 0 deletions core/chaincode/chaincodetest.yaml
Expand Up @@ -428,6 +428,8 @@ ledger:
couchDBAddress: 127.0.0.1:5984
username:
password:
maxRetries: 3
maxRetriesOnStartup: 10

# historyDatabase - options are true or false
# Indicates if the history of key updates should be stored in goleveldb
Expand Down
4 changes: 3 additions & 1 deletion core/chaincode/exectransaction_test.go
Expand Up @@ -125,8 +125,10 @@ func finitPeer(lis net.Listener, chainIDs ...string) {
connectURL := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
username := viper.GetString("ledger.state.couchDBConfig.username")
password := viper.GetString("ledger.state.couchDBConfig.password")
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")

couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password)
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password, maxRetries, maxRetriesOnStartup)
db, _ := couchdb.CreateCouchDatabase(*couchInstance, chainID)
//drop the test database
db.DropDatabase()
Expand Down
Expand Up @@ -55,7 +55,8 @@ type VersionedDBProvider struct {
func NewVersionedDBProvider() (*VersionedDBProvider, error) {
logger.Debugf("constructing CouchDB VersionedDBProvider")
couchDBDef := ledgerconfig.GetCouchDBDefinition()
couchInstance, err := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password)
couchInstance, err := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password,
couchDBDef.MaxRetries, couchDBDef.MaxRetriesOnStartup)
if err != nil {
return nil, err
}
Expand Down
Expand Up @@ -29,6 +29,8 @@ var connectURL = "couchdb:5984"
var badConnectURL = "couchdb:5990"
var username = ""
var password = ""
var maxRetries = 3
var maxRetriesOnStartup = 10

// TestVDBEnv provides a couch db backed versioned db for testing
type TestVDBEnv struct {
Expand All @@ -55,7 +57,7 @@ func (env *TestVDBEnv) Cleanup(dbName string) {
}
func cleanupDB(dbName string) {
//create a new connection
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password)
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password, maxRetries, maxRetriesOnStartup)
db := couchdb.CouchDatabase{CouchInstance: *couchInstance, DBName: dbName}
//drop the test database
db.DropDatabase()
Expand Down
29 changes: 12 additions & 17 deletions core/ledger/ledgerconfig/ledger_config.go
Expand Up @@ -22,25 +22,18 @@ import (
"github.com/spf13/viper"
)

// TODO remove all these config variables, they are never used as defaults
var stateDatabase = "goleveldb"
var couchDBAddress = "127.0.0.1:5984"
var username = ""
var password = ""
var historyDatabase = true

var maxBlockFileSize = 0

// CouchDBDef contains parameters
type CouchDBDef struct {
URL string
Username string
Password string
URL string
Username string
Password string
MaxRetries int
MaxRetriesOnStartup int
}

//IsCouchDBEnabled exposes the useCouchDB variable
func IsCouchDBEnabled() bool {
stateDatabase = viper.GetString("ledger.state.stateDatabase")
stateDatabase := viper.GetString("ledger.state.stateDatabase")
if stateDatabase == "CouchDB" {
return true
}
Expand Down Expand Up @@ -82,11 +75,13 @@ func GetMaxBlockfileSize() int {
//GetCouchDBDefinition exposes the useCouchDB variable
func GetCouchDBDefinition() *CouchDBDef {

couchDBAddress = viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
username = viper.GetString("ledger.state.couchDBConfig.username")
password = viper.GetString("ledger.state.couchDBConfig.password")
couchDBAddress := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
username := viper.GetString("ledger.state.couchDBConfig.username")
password := viper.GetString("ledger.state.couchDBConfig.password")
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")

return &CouchDBDef{couchDBAddress, username, password}
return &CouchDBDef{couchDBAddress, username, password, maxRetries, maxRetriesOnStartup}
}

//GetQueryLimit exposes the queryLimit variable
Expand Down

0 comments on commit c4d192b

Please sign in to comment.