Skip to content

Commit 987496f

Browse files
author
Chris Elder
committed
[FAB-2709] Fix CouchDB retry logic
To account for cases when peer and couchdb start at same time, 2 minutes of retries are done. This does not work well for chaincode execution though. Need to fix it such that peer startup verification retries more times than endorsement/commit interactions with CouchDB, ideally configurable. Add two new CouchDB configuration options in core.yaml couchDBConfig: couchDBAddress: 127.0.0.1:5984 username: password: maxRetries: 3 maxRetriesOnStartup: 10 - maxRetries will control the max number of retries for http errors when connecting with CouchDB. - maxRetriesOnStartup will be a separate configuration option for specifying the number of retries during startup. This needs to be a larger number than the normal retries. - Handling of 404 error is already handled correctly - 500 errors and 4XX errors will not be retried. - Add a change to VerifyConnection to allow for the maxRetriesOnStartup to be used for retry logic in handleRequest Change-Id: Ibdf48444ef0728825a168bf4deebde5fa43f12ac Signed-off-by: Chris Elder <[email protected]>
1 parent 7984725 commit 987496f

File tree

10 files changed

+157
-129
lines changed

10 files changed

+157
-129
lines changed

core/chaincode/chaincodetest.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ ledger:
428428
couchDBAddress: 127.0.0.1:5984
429429
username:
430430
password:
431+
maxRetries: 3
432+
maxRetriesOnStartup: 10
431433

432434
# historyDatabase - options are true or false
433435
# Indicates if the history of key updates should be stored in goleveldb

core/chaincode/exectransaction_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ func finitPeer(lis net.Listener, chainIDs ...string) {
124124
connectURL := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
125125
username := viper.GetString("ledger.state.couchDBConfig.username")
126126
password := viper.GetString("ledger.state.couchDBConfig.password")
127+
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
128+
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")
127129

128-
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password)
130+
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password, maxRetries, maxRetriesOnStartup)
129131
db, _ := couchdb.CreateCouchDatabase(*couchInstance, chainID)
130132
//drop the test database
131133
db.DropDatabase()

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ type VersionedDBProvider struct {
5555
func NewVersionedDBProvider() (*VersionedDBProvider, error) {
5656
logger.Debugf("constructing CouchDB VersionedDBProvider")
5757
couchDBDef := ledgerconfig.GetCouchDBDefinition()
58-
couchInstance, err := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password)
58+
couchInstance, err := couchdb.CreateCouchInstance(couchDBDef.URL, couchDBDef.Username, couchDBDef.Password,
59+
couchDBDef.MaxRetries, couchDBDef.MaxRetriesOnStartup)
5960
if err != nil {
6061
return nil, err
6162
}

core/ledger/kvledger/txmgmt/statedb/statecouchdb/statecouchdb_test_export.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ var connectURL = "couchdb:5984"
2929
var badConnectURL = "couchdb:5990"
3030
var username = ""
3131
var password = ""
32+
var maxRetries = 3
33+
var maxRetriesOnStartup = 10
3234

3335
// TestVDBEnv provides a couch db backed versioned db for testing
3436
type TestVDBEnv struct {
@@ -55,7 +57,7 @@ func (env *TestVDBEnv) Cleanup(dbName string) {
5557
}
5658
func cleanupDB(dbName string) {
5759
//create a new connection
58-
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password)
60+
couchInstance, _ := couchdb.CreateCouchInstance(connectURL, username, password, maxRetries, maxRetriesOnStartup)
5961
db := couchdb.CouchDatabase{CouchInstance: *couchInstance, DBName: dbName}
6062
//drop the test database
6163
db.DropDatabase()

core/ledger/ledgerconfig/ledger_config.go

+12-17
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,18 @@ import (
2222
"github.com/spf13/viper"
2323
)
2424

25-
// TODO remove all these config variables, they are never used as defaults
26-
var stateDatabase = "goleveldb"
27-
var couchDBAddress = "127.0.0.1:5984"
28-
var username = ""
29-
var password = ""
30-
var historyDatabase = true
31-
32-
var maxBlockFileSize = 0
33-
3425
// CouchDBDef contains parameters
3526
type CouchDBDef struct {
36-
URL string
37-
Username string
38-
Password string
27+
URL string
28+
Username string
29+
Password string
30+
MaxRetries int
31+
MaxRetriesOnStartup int
3932
}
4033

4134
//IsCouchDBEnabled exposes the useCouchDB variable
4235
func IsCouchDBEnabled() bool {
43-
stateDatabase = viper.GetString("ledger.state.stateDatabase")
36+
stateDatabase := viper.GetString("ledger.state.stateDatabase")
4437
if stateDatabase == "CouchDB" {
4538
return true
4639
}
@@ -82,11 +75,13 @@ func GetMaxBlockfileSize() int {
8275
//GetCouchDBDefinition exposes the useCouchDB variable
8376
func GetCouchDBDefinition() *CouchDBDef {
8477

85-
couchDBAddress = viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
86-
username = viper.GetString("ledger.state.couchDBConfig.username")
87-
password = viper.GetString("ledger.state.couchDBConfig.password")
78+
couchDBAddress := viper.GetString("ledger.state.couchDBConfig.couchDBAddress")
79+
username := viper.GetString("ledger.state.couchDBConfig.username")
80+
password := viper.GetString("ledger.state.couchDBConfig.password")
81+
maxRetries := viper.GetInt("ledger.state.couchDBConfig.maxRetries")
82+
maxRetriesOnStartup := viper.GetInt("ledger.state.couchDBConfig.maxRetriesOnStartup")
8883

89-
return &CouchDBDef{couchDBAddress, username, password}
84+
return &CouchDBDef{couchDBAddress, username, password, maxRetries, maxRetriesOnStartup}
9085
}
9186

9287
//GetQueryLimit exposes the queryLimit variable

0 commit comments

Comments
 (0)