traeak commented on a change in pull request #2931: reuse single riak cluster 
connection, up riak heartbeat timeout
URL: https://github.com/apache/trafficcontrol/pull/2931#discussion_r230912693
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/riaksvc/riak_services.go
 ##########
 @@ -241,60 +268,88 @@ func RiakServersToCluster(servers []ServerAddr, 
authOptions *riak.AuthOptions) (
        }
        opts := &riak.ClusterOptions{
                Nodes:             nodes,
-               ExecutionAttempts: MaxCommandExecutionAttempts,
+               ExecutionAttempts: DefaultMaxCommandExecutionAttempts,
        }
        cluster, err := riak.NewCluster(opts)
        if err != nil {
                return nil, errors.New("creating riak cluster: " + err.Error())
        }
-       return RiakStorageCluster{Cluster: cluster}, nil
+       return cluster, err
 }
 
-func GetRiakClusterTx(tx *sql.Tx, authOptions *riak.AuthOptions) 
(StorageCluster, error) {
-       servers, err := GetRiakServers(tx)
+func GetRiakStorageCluster(servers []ServerAddr, authOptions 
*riak.AuthOptions) (StorageCluster, error) {
+       cluster, err := GetRiakCluster(servers, authOptions)
        if err != nil {
-               return nil, errors.New("getting riak servers: " + err.Error())
-       }
-       cluster, err := RiakServersToCluster(servers, authOptions)
-       if err != nil {
-               return nil, errors.New("creating riak cluster from servers: " + 
err.Error())
+               return nil, err
        }
-       return cluster, nil
+       return RiakStorageCluster{Cluster: cluster}, nil
 }
 
-func WithClusterTx(tx *sql.Tx, authOpts *riak.AuthOptions, f 
func(StorageCluster) error) error {
-       cluster, err := GetRiakClusterTx(tx, authOpts)
-       if err != nil {
-               return errors.New("getting riak cluster: " + err.Error())
-       }
-       if err = cluster.Start(); err != nil {
-               return errors.New("starting riak cluster: " + err.Error())
-       }
-       defer func() {
-               if err := cluster.Stop(); err != nil {
-                       log.Errorln("error stopping Riak cluster: " + 
err.Error())
+func GetPooledCluster(tx *sql.Tx, authOptions *riak.AuthOptions) 
(StorageCluster, error) {
+
+       clusterMutex.Lock()
+       defer clusterMutex.Unlock()
+
+       tryLoad := false
+
+       // should we try to reload the cluster?
+       newservers, err := GetRiakServers(tx)
+
+       if err == nil {
+               if 0 < len(newservers) {
 
 Review comment:
   fairly minor
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to