| 
									
										
										
										
											2021-04-19 03:41:13 +08:00
										 |  |  | // Copyright (c) 2015-2021 MinIO, Inc.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This file is part of MinIO Object Storage stack
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"encoding/gob" | 
					
						
							| 
									
										
										
										
											2024-01-20 10:27:58 +08:00
										 |  |  | 	"encoding/hex" | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2020-06-18 05:49:26 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	"io" | 
					
						
							|  |  |  | 	"net/url" | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | 	"strconv" | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	"sync/atomic" | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-20 08:53:08 +08:00
										 |  |  | 	"github.com/minio/madmin-go/v3" | 
					
						
							| 
									
										
										
										
											2023-01-19 21:22:16 +08:00
										 |  |  | 	"github.com/minio/minio/internal/bucket/bandwidth" | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	"github.com/minio/minio/internal/grid" | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/internal/http" | 
					
						
							|  |  |  | 	"github.com/minio/minio/internal/logger" | 
					
						
							|  |  |  | 	"github.com/minio/minio/internal/rest" | 
					
						
							| 
									
										
										
										
											2024-05-25 07:05:23 +08:00
										 |  |  | 	xnet "github.com/minio/pkg/v3/net" | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | // client to talk to peer Nodes.
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | type peerRESTClient struct { | 
					
						
							|  |  |  | 	host       *xnet.Host | 
					
						
							|  |  |  | 	restClient *rest.Client | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	gridHost   string | 
					
						
							|  |  |  | 	// Function that returns the grid connection for this peer when initialized.
 | 
					
						
							|  |  |  | 	// Will return nil if the grid connection is not initialized yet.
 | 
					
						
							|  |  |  | 	gridConn func() *grid.Connection | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Returns a peer rest client.
 | 
					
						
							|  |  |  | func newPeerRESTClient(peer *xnet.Host, gridHost string) *peerRESTClient { | 
					
						
							|  |  |  | 	scheme := "http" | 
					
						
							|  |  |  | 	if globalIsTLS { | 
					
						
							|  |  |  | 		scheme = "https" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	serverURL := &url.URL{ | 
					
						
							|  |  |  | 		Scheme: scheme, | 
					
						
							|  |  |  | 		Host:   peer.String(), | 
					
						
							|  |  |  | 		Path:   peerRESTPath, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	restClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken()) | 
					
						
							|  |  |  | 	// Use a separate client to avoid recursive calls.
 | 
					
						
							|  |  |  | 	healthClient := rest.NewClient(serverURL, globalInternodeTransport, newCachedAuthToken()) | 
					
						
							|  |  |  | 	healthClient.NoMetrics = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Construct a new health function.
 | 
					
						
							|  |  |  | 	restClient.HealthCheckFn = func() bool { | 
					
						
							|  |  |  | 		ctx, cancel := context.WithTimeout(context.Background(), restClient.HealthCheckTimeout) | 
					
						
							|  |  |  | 		defer cancel() | 
					
						
							|  |  |  | 		respBody, err := healthClient.Call(ctx, peerRESTMethodHealth, nil, nil, -1) | 
					
						
							|  |  |  | 		xhttp.DrainBody(respBody) | 
					
						
							|  |  |  | 		return !isNetworkError(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var gridConn atomic.Pointer[grid.Connection] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return &peerRESTClient{ | 
					
						
							|  |  |  | 		host: peer, restClient: restClient, gridHost: gridHost, | 
					
						
							|  |  |  | 		gridConn: func() *grid.Connection { | 
					
						
							|  |  |  | 			// Lazy initialization of grid connection.
 | 
					
						
							|  |  |  | 			// When we create this peer client, the grid connection is likely not yet initialized.
 | 
					
						
							|  |  |  | 			if gridHost == "" { | 
					
						
							| 
									
										
										
										
											2024-04-04 20:04:40 +08:00
										 |  |  | 				bugLogIf(context.Background(), fmt.Errorf("gridHost is empty for peer %s", peer.String()), peer.String()+":gridHost") | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 				return nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			gc := gridConn.Load() | 
					
						
							|  |  |  | 			if gc != nil { | 
					
						
							|  |  |  | 				return gc | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			gm := globalGrid.Load() | 
					
						
							|  |  |  | 			if gm == nil { | 
					
						
							|  |  |  | 				return nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			gc = gm.Connection(gridHost) | 
					
						
							|  |  |  | 			if gc == nil { | 
					
						
							| 
									
										
										
										
											2024-04-04 20:04:40 +08:00
										 |  |  | 				bugLogIf(context.Background(), fmt.Errorf("gridHost %q not found for peer %s", gridHost, peer.String()), peer.String()+":gridHost") | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 				return nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			gridConn.Store(gc) | 
					
						
							|  |  |  | 			return gc | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | // Wrapper to restClient.Call to handle network errors, in case of network error the connection is marked disconnected
 | 
					
						
							|  |  |  | // permanently. The only way to restore the connection is at the xl-sets layer by xlsets.monitorAndConnectEndpoints()
 | 
					
						
							|  |  |  | // after verifying format.json
 | 
					
						
							|  |  |  | func (client *peerRESTClient) callWithContext(ctx context.Context, method string, values url.Values, body io.Reader, length int64) (respBody io.ReadCloser, err error) { | 
					
						
							| 
									
										
										
										
											2024-05-09 08:51:34 +08:00
										 |  |  | 	if client == nil { | 
					
						
							| 
									
										
										
										
											2023-03-08 00:13:28 +08:00
										 |  |  | 		return nil, errPeerNotReachable | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	if values == nil { | 
					
						
							|  |  |  | 		values = make(url.Values) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 00:45:06 +08:00
										 |  |  | 	respBody, err = client.restClient.Call(ctx, method, values, body, length) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	if err == nil { | 
					
						
							|  |  |  | 		return respBody, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 08:51:34 +08:00
										 |  |  | 	if xnet.IsNetworkOrHostDown(err, true) { | 
					
						
							|  |  |  | 		return nil, errPeerNotReachable | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	return nil, err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Stringer provides a canonicalized representation of node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) String() string { | 
					
						
							|  |  |  | 	return client.host.String() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 01:16:07 +08:00
										 |  |  | // IsOnline returns true if the peer client is online.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) IsOnline() bool { | 
					
						
							| 
									
										
										
										
											2024-05-09 08:51:34 +08:00
										 |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return client.restClient.IsOnline() || conn.State() == grid.StateConnected | 
					
						
							| 
									
										
										
										
											2020-12-23 01:16:07 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | // Close - marks the client as closed.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) Close() error { | 
					
						
							|  |  |  | 	client.restClient.Close() | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GetLocks - fetch older locks for a remote node.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) GetLocks(ctx context.Context) (lockMap map[string][]lockRequesterInfo, err error) { | 
					
						
							|  |  |  | 	resp, err := getLocksRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	if err != nil || resp == nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-02 06:31:35 +08:00
										 |  |  | // LocalStorageInfo - fetch server information for a remote node.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LocalStorageInfo(ctx context.Context, metrics bool) (info StorageInfo, err error) { | 
					
						
							|  |  |  | 	resp, err := localStorageInfoRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 		peerRESTMetrics: strconv.FormatBool(metrics), | 
					
						
							|  |  |  | 	})) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2022-12-02 06:31:35 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | // ServerInfo - fetch server information for a remote node.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) ServerInfo(ctx context.Context, metrics bool) (info madmin.ServerProperties, err error) { | 
					
						
							|  |  |  | 	resp, err := serverInfoRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{peerRESTMetrics: strconv.FormatBool(metrics)})) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 23:55:49 +08:00
										 |  |  | // GetCPUs - fetch CPU information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetCPUs(ctx context.Context) (info madmin.CPUs, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getCPUsHandler.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-03 00:49:49 +08:00
										 |  |  | // GetNetInfo - fetch network information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetNetInfo(ctx context.Context) (info madmin.NetInfo, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getNetInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2023-11-03 00:49:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 23:55:49 +08:00
										 |  |  | // GetPartitions - fetch disk partition information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetPartitions(ctx context.Context) (info madmin.Partitions, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getPartitionsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 23:55:49 +08:00
										 |  |  | // GetOSInfo - fetch OS information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetOSInfo(ctx context.Context) (info madmin.OSInfo, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getOSInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 09:58:40 +08:00
										 |  |  | // GetSELinuxInfo - fetch SELinux information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetSELinuxInfo(ctx context.Context) (info madmin.SysServices, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getSysServicesRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2021-08-13 09:58:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 08:09:37 +08:00
										 |  |  | // GetSysConfig - fetch sys config for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetSysConfig(ctx context.Context) (info madmin.SysConfig, err error) { | 
					
						
							| 
									
										
										
										
											2022-01-06 17:51:10 +08:00
										 |  |  | 	sent := time.Now() | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getSysConfigRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	info = resp.ValueOrZero() | 
					
						
							| 
									
										
										
										
											2023-05-11 06:20:48 +08:00
										 |  |  | 	if ti, ok := info.Config["time-info"].(madmin.TimeInfo); ok { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 		rt := int32(time.Since(sent).Milliseconds()) | 
					
						
							|  |  |  | 		ti.RoundtripDuration = rt | 
					
						
							| 
									
										
										
										
											2022-01-06 17:51:10 +08:00
										 |  |  | 		info.Config["time-info"] = ti | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-25 08:09:37 +08:00
										 |  |  | 	return info, err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GetSysErrors - fetch sys errors for a remote node.
 | 
					
						
							| 
									
										
										
										
											2021-07-30 14:05:34 +08:00
										 |  |  | func (client *peerRESTClient) GetSysErrors(ctx context.Context) (info madmin.SysErrors, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getSysErrorsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2021-07-30 14:05:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 23:55:49 +08:00
										 |  |  | // GetMemInfo - fetch memory information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetMemInfo(ctx context.Context) (info madmin.MemInfo, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getMemInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-06 05:45:49 +08:00
										 |  |  | // GetMetrics - fetch metrics from a remote node.
 | 
					
						
							| 
									
										
										
										
											2022-10-03 17:10:15 +08:00
										 |  |  | func (client *peerRESTClient) GetMetrics(ctx context.Context, t madmin.MetricType, opts collectMetricsOpts) (info madmin.RealtimeMetrics, err error) { | 
					
						
							| 
									
										
										
										
											2022-07-06 05:45:49 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							| 
									
										
										
										
											2022-10-03 17:10:15 +08:00
										 |  |  | 	values.Set(peerRESTMetricsTypes, strconv.FormatUint(uint64(t), 10)) | 
					
						
							|  |  |  | 	for disk := range opts.disks { | 
					
						
							| 
									
										
										
										
											2023-07-28 02:44:13 +08:00
										 |  |  | 		values.Add(peerRESTDisk, disk) | 
					
						
							| 
									
										
										
										
											2022-08-16 22:13:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-07-19 14:50:30 +08:00
										 |  |  | 	for host := range opts.hosts { | 
					
						
							|  |  |  | 		values.Add(peerRESTHost, host) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-10-03 17:10:15 +08:00
										 |  |  | 	values.Set(peerRESTJobID, opts.jobID) | 
					
						
							| 
									
										
										
										
											2022-11-14 23:16:40 +08:00
										 |  |  | 	values.Set(peerRESTDepID, opts.depID) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	v, err := getMetricsRPC.Call(ctx, client.gridConn(), grid.NewURLValuesWith(values)) | 
					
						
							|  |  |  | 	return v.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2022-07-06 05:45:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 23:55:49 +08:00
										 |  |  | // GetProcInfo - fetch MinIO process information for a remote node.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetProcInfo(ctx context.Context) (info madmin.ProcInfo, err error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getProcInfoRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | // StartProfiling - Issues profiling command on the peer node.
 | 
					
						
							| 
									
										
										
										
											2024-08-15 18:36:00 +08:00
										 |  |  | func (client *peerRESTClient) StartProfiling(ctx context.Context, profiler string) error { | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(peerRESTProfiler, profiler) | 
					
						
							| 
									
										
										
										
											2024-08-15 18:36:00 +08:00
										 |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodStartProfiling, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // DownloadProfileData - download profiled data from a remote node.
 | 
					
						
							| 
									
										
										
										
											2024-08-15 18:36:00 +08:00
										 |  |  | func (client *peerRESTClient) DownloadProfileData(ctx context.Context) (data map[string][]byte, err error) { | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodDownloadProfilingData, nil, nil, -1) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	err = gob.NewDecoder(respBody).Decode(&data) | 
					
						
							|  |  |  | 	return data, err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 06:34:33 +08:00
										 |  |  | // GetBucketStats - load bucket statistics
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) GetBucketStats(ctx context.Context, bucket string) (BucketStats, error) { | 
					
						
							|  |  |  | 	resp, err := getBucketStatsRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 		peerRESTBucket: bucket, | 
					
						
							|  |  |  | 	})) | 
					
						
							|  |  |  | 	if err != nil || resp == nil { | 
					
						
							| 
									
										
										
										
											2021-04-05 06:34:33 +08:00
										 |  |  | 		return BucketStats{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2021-04-05 06:34:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | // GetSRMetrics loads site replication metrics, optionally for a specific bucket
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) GetSRMetrics(ctx context.Context) (SRMetricsSummary, error) { | 
					
						
							|  |  |  | 	resp, err := getSRMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	if err != nil || resp == nil { | 
					
						
							| 
									
										
										
										
											2023-08-30 16:00:59 +08:00
										 |  |  | 		return SRMetricsSummary{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2023-08-30 16:00:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 00:15:30 +08:00
										 |  |  | // GetAllBucketStats - load replication stats for all buckets
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) GetAllBucketStats(ctx context.Context) (BucketStatsMap, error) { | 
					
						
							|  |  |  | 	resp, err := getAllBucketStatsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	if err != nil || resp == nil { | 
					
						
							| 
									
										
										
										
											2022-09-13 03:40:02 +08:00
										 |  |  | 		return BucketStatsMap{}, err | 
					
						
							| 
									
										
										
										
											2022-05-24 00:15:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2022-05-24 00:15:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 04:53:54 +08:00
										 |  |  | // LoadBucketMetadata - load bucket metadata
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadBucketMetadata(ctx context.Context, bucket string) error { | 
					
						
							|  |  |  | 	_, err := loadBucketMetadataRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTBucket: bucket, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 04:53:54 +08:00
										 |  |  | // DeleteBucketMetadata - Delete bucket metadata
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) DeleteBucketMetadata(ctx context.Context, bucket string) error { | 
					
						
							|  |  |  | 	_, err := deleteBucketMetadataRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTBucket: bucket, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | // DeletePolicy - delete a specific canned policy.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) DeletePolicy(ctx context.Context, policyName string) (err error) { | 
					
						
							|  |  |  | 	_, err = deletePolicyRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTPolicy: policyName, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // LoadPolicy - reload a specific canned policy.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadPolicy(ctx context.Context, policyName string) (err error) { | 
					
						
							|  |  |  | 	_, err = loadPolicyRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTPolicy: policyName, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 04:41:06 +08:00
										 |  |  | // LoadPolicyMapping - reload a specific policy mapping
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadPolicyMapping(ctx context.Context, userOrGroup string, userType IAMUserType, isGroup bool) error { | 
					
						
							|  |  |  | 	_, err := loadPolicyMappingRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTUserOrGroup: userOrGroup, | 
					
						
							|  |  |  | 		peerRESTUserType:    strconv.Itoa(int(userType)), | 
					
						
							|  |  |  | 		peerRESTIsGroup:     strconv.FormatBool(isGroup), | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-08-14 04:41:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | // DeleteUser - delete a specific user.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) DeleteUser(ctx context.Context, accessKey string) (err error) { | 
					
						
							|  |  |  | 	_, err = deleteUserRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTUser: accessKey, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 03:10:09 +08:00
										 |  |  | // DeleteServiceAccount - delete a specific service account.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) DeleteServiceAccount(ctx context.Context, accessKey string) (err error) { | 
					
						
							|  |  |  | 	_, err = deleteSvcActRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTUser: accessKey, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2020-04-25 03:10:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | // LoadUser - reload a specific user.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadUser(ctx context.Context, accessKey string, temp bool) (err error) { | 
					
						
							|  |  |  | 	_, err = loadUserRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTUser:     accessKey, | 
					
						
							|  |  |  | 		peerRESTUserTemp: strconv.FormatBool(temp), | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-06-07 08:46:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 03:10:09 +08:00
										 |  |  | // LoadServiceAccount - reload a specific service account.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadServiceAccount(ctx context.Context, accessKey string) (err error) { | 
					
						
							|  |  |  | 	_, err = loadSvcActRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTUser: accessKey, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2020-04-25 03:10:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-03 05:25:00 +08:00
										 |  |  | // LoadGroup - send load group command to peers.
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) LoadGroup(ctx context.Context, group string) error { | 
					
						
							|  |  |  | 	_, err := loadGroupRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTGroup: group, | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-08-03 05:25:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-13 22:55:54 +08:00
										 |  |  | func (client *peerRESTClient) ReloadSiteReplicationConfig(ctx context.Context) error { | 
					
						
							|  |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := reloadSiteReplicationConfigRPC.Call(ctx, conn, grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2024-02-13 22:55:54 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-29 23:34:30 +08:00
										 |  |  | // VerifyBinary - sends verify binary message to remote peers.
 | 
					
						
							| 
									
										
										
										
											2024-01-20 10:27:58 +08:00
										 |  |  | func (client *peerRESTClient) VerifyBinary(ctx context.Context, u *url.URL, sha256Sum []byte, releaseInfo string, reader io.Reader) error { | 
					
						
							| 
									
										
										
										
											2019-08-29 06:04:43 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							| 
									
										
										
										
											2024-01-20 10:27:58 +08:00
										 |  |  | 	values.Set(peerRESTURL, u.String()) | 
					
						
							|  |  |  | 	values.Set(peerRESTSha256Sum, hex.EncodeToString(sha256Sum)) | 
					
						
							|  |  |  | 	values.Set(peerRESTReleaseInfo, releaseInfo) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodVerifyBinary, values, reader, -1) | 
					
						
							| 
									
										
										
										
											2022-07-26 08:49:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2022-07-26 08:49:47 +08:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // CommitBinary - sends commit binary message to remote peers.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) CommitBinary(ctx context.Context) error { | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodCommitBinary, nil, nil, -1) | 
					
						
							| 
									
										
										
										
											2019-08-29 06:04:43 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2019-08-29 06:04:43 +08:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | // SignalService - sends signal to peer nodes.
 | 
					
						
							| 
									
										
										
										
											2024-06-20 22:49:22 +08:00
										 |  |  | func (client *peerRESTClient) SignalService(sig serviceSignal, subSys string, dryRun bool, execAt *time.Time) error { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	values := grid.NewMSS() | 
					
						
							| 
									
										
										
										
											2019-08-28 02:37:47 +08:00
										 |  |  | 	values.Set(peerRESTSignal, strconv.Itoa(int(sig))) | 
					
						
							| 
									
										
										
										
											2024-01-20 06:22:36 +08:00
										 |  |  | 	values.Set(peerRESTDryRun, strconv.FormatBool(dryRun)) | 
					
						
							| 
									
										
										
										
											2022-05-17 07:10:51 +08:00
										 |  |  | 	values.Set(peerRESTSubSys, subSys) | 
					
						
							| 
									
										
										
										
											2024-06-20 22:49:22 +08:00
										 |  |  | 	if execAt != nil { | 
					
						
							|  |  |  | 		values.Set(peerRESTExecAt, execAt.Format(time.RFC3339Nano)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := signalServiceRPC.Call(context.Background(), client.gridConn(), values) | 
					
						
							|  |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-16 06:19:00 +08:00
										 |  |  | func (client *peerRESTClient) BackgroundHealStatus(ctx context.Context) (madmin.BgHealState, error) { | 
					
						
							|  |  |  | 	resp, err := getBackgroundHealStatusRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return resp.ValueOrZero(), err | 
					
						
							| 
									
										
										
										
											2019-06-26 07:42:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | // GetMetacacheListing - get a new or existing metacache.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetMetacacheListing(ctx context.Context, o listPathOptions) (*metacache, error) { | 
					
						
							| 
									
										
										
										
											2021-12-16 01:19:11 +08:00
										 |  |  | 	if client == nil { | 
					
						
							|  |  |  | 		resp := localMetacacheMgr.getBucket(ctx, o.Bucket).findCache(o) | 
					
						
							|  |  |  | 		return &resp, nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return getMetacacheListingRPC.Call(ctx, client.gridConn(), &o) | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // UpdateMetacacheListing - update an existing metacache it will unconditionally be updated to the new state.
 | 
					
						
							|  |  |  | func (client *peerRESTClient) UpdateMetacacheListing(ctx context.Context, m metacache) (metacache, error) { | 
					
						
							| 
									
										
										
										
											2021-12-16 01:19:11 +08:00
										 |  |  | 	if client == nil { | 
					
						
							|  |  |  | 		return localMetacacheMgr.updateCacheEntry(m) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := updateMetacacheListingRPC.Call(ctx, client.gridConn(), &m) | 
					
						
							|  |  |  | 	if err != nil || resp == nil { | 
					
						
							|  |  |  | 		return metacache{}, err | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-11 01:07:49 +08:00
										 |  |  | func (client *peerRESTClient) ReloadPoolMeta(ctx context.Context) error { | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := reloadPoolMetaRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2022-10-26 03:36:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 00:58:30 +08:00
										 |  |  | func (client *peerRESTClient) DeleteUploadID(ctx context.Context, uploadID string) error { | 
					
						
							|  |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_, err := cleanupUploadIDCacheMetaRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{ | 
					
						
							|  |  |  | 		peerRESTUploadID: uploadID, | 
					
						
							|  |  |  | 	})) | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-26 03:36:57 +08:00
										 |  |  | func (client *peerRESTClient) StopRebalance(ctx context.Context) error { | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := stopRebalanceRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2022-10-26 03:36:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (client *peerRESTClient) LoadRebalanceMeta(ctx context.Context, startRebalance bool) error { | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := loadRebalanceMetaRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{ | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 		peerRESTStartRebalance: strconv.FormatBool(startRebalance), | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2022-01-11 01:07:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 01:30:42 +08:00
										 |  |  | func (client *peerRESTClient) LoadTransitionTierConfig(ctx context.Context) error { | 
					
						
							| 
									
										
										
										
											2024-02-02 02:47:20 +08:00
										 |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	_, err := loadTransitionTierConfigRPC.Call(ctx, conn, grid.NewMSSWith(map[string]string{})) | 
					
						
							| 
									
										
										
										
											2024-02-02 11:42:56 +08:00
										 |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2021-04-20 01:30:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | func (client *peerRESTClient) doTrace(ctx context.Context, traceCh chan<- []byte, traceOpts madmin.ServiceTraceOpts) { | 
					
						
							|  |  |  | 	gridConn := client.gridConn() | 
					
						
							|  |  |  | 	if gridConn == nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	payload, err := json.Marshal(traceOpts) | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2024-04-04 20:04:40 +08:00
										 |  |  | 		bugLogIf(ctx, err) | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	st, err := gridConn.NewStream(ctx, grid.HandlerTrace, payload) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	st.Results(func(b []byte) error { | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 		select { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 		case traceCh <- b: | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			// Do not block on slow receivers.
 | 
					
						
							|  |  |  | 			// Just recycle the buffer.
 | 
					
						
							|  |  |  | 			grid.PutByteBuffer(b) | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | func (client *peerRESTClient) doListen(ctx context.Context, listenCh chan<- []byte, v url.Values) { | 
					
						
							|  |  |  | 	conn := client.gridConn() | 
					
						
							|  |  |  | 	if conn == nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	st, err := listenRPC.Call(ctx, conn, grid.NewURLValuesWith(v)) | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 	st.Results(func(b *grid.Bytes) error { | 
					
						
							|  |  |  | 		select { | 
					
						
							|  |  |  | 		case listenCh <- *b: | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			// Do not block on slow receivers.
 | 
					
						
							|  |  |  | 			b.Recycle() | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Listen - listen on peers.
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | func (client *peerRESTClient) Listen(ctx context.Context, listenCh chan<- []byte, v url.Values) { | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 	go func() { | 
					
						
							|  |  |  | 		for { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 			client.doListen(ctx, listenCh, v) | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 			select { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 			case <-ctx.Done(): | 
					
						
							| 
									
										
										
										
											2019-12-13 02:01:23 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				// There was error in the REST request, retry after sometime as probably the peer is down.
 | 
					
						
							|  |  |  | 				time.Sleep(5 * time.Second) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | // Trace - send http trace request to peer nodes
 | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | func (client *peerRESTClient) Trace(ctx context.Context, traceCh chan<- []byte, traceOpts madmin.ServiceTraceOpts) { | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 	go func() { | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | 		for { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 			// Blocks until context is canceled or an error occurs.
 | 
					
						
							|  |  |  | 			client.doTrace(ctx, traceCh, traceOpts) | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | 			select { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 			case <-ctx.Done(): | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2019-06-27 13:41:12 +08:00
										 |  |  | 				// There was error in the REST request, retry after sometime as probably the peer is down.
 | 
					
						
							|  |  |  | 				time.Sleep(5 * time.Second) | 
					
						
							| 
									
										
										
										
											2019-06-09 06:54:41 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | func (client *peerRESTClient) doConsoleLog(ctx context.Context, kind madmin.LogMask, logCh chan<- []byte) { | 
					
						
							|  |  |  | 	st, err := consoleLogRPC.Call(ctx, client.gridConn(), grid.NewMSSWith(map[string]string{ | 
					
						
							|  |  |  | 		peerRESTLogMask: strconv.Itoa(int(kind)), | 
					
						
							|  |  |  | 	})) | 
					
						
							| 
									
										
										
										
											2022-05-07 03:39:58 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	st.Results(func(b *grid.Bytes) error { | 
					
						
							| 
									
										
										
										
											2022-10-29 01:55:42 +08:00
										 |  |  | 		select { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 		case logCh <- *b: | 
					
						
							| 
									
										
										
										
											2022-10-29 01:55:42 +08:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 			consoleLogRPC.PutResponse(b) | 
					
						
							| 
									
										
										
										
											2022-10-29 01:55:42 +08:00
										 |  |  | 			// Do not block on slow receivers.
 | 
					
						
							| 
									
										
										
										
											2022-05-07 03:39:58 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2022-05-07 03:39:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-04 02:10:48 +08:00
										 |  |  | // ConsoleLog - sends request to peer nodes to get console logs
 | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | func (client *peerRESTClient) ConsoleLog(ctx context.Context, kind madmin.LogMask, logCh chan<- []byte) { | 
					
						
							| 
									
										
										
										
											2019-09-04 02:10:48 +08:00
										 |  |  | 	go func() { | 
					
						
							|  |  |  | 		for { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 			client.doConsoleLog(ctx, kind, logCh) | 
					
						
							| 
									
										
										
										
											2019-09-04 02:10:48 +08:00
										 |  |  | 			select { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 			case <-ctx.Done(): | 
					
						
							| 
									
										
										
										
											2019-09-04 02:10:48 +08:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2022-05-07 03:39:58 +08:00
										 |  |  | 				// There was error in the REST request, retry after sometime as probably the peer is down.
 | 
					
						
							|  |  |  | 				time.Sleep(5 * time.Second) | 
					
						
							| 
									
										
										
										
											2019-09-04 02:10:48 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | // newPeerRestClients creates new peer clients.
 | 
					
						
							|  |  |  | // The two slices will point to the same clients,
 | 
					
						
							|  |  |  | // but 'all' will contain nil entry for local client.
 | 
					
						
							|  |  |  | // The 'all' slice will be in the same order across the cluster.
 | 
					
						
							| 
									
										
										
										
											2020-12-02 05:50:33 +08:00
										 |  |  | func newPeerRestClients(endpoints EndpointServerPools) (remote, all []*peerRESTClient) { | 
					
						
							| 
									
										
										
										
											2020-10-30 00:25:43 +08:00
										 |  |  | 	if !globalIsDistErasure { | 
					
						
							|  |  |  | 		// Only useful in distributed setups
 | 
					
						
							|  |  |  | 		return nil, nil | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	hosts := endpoints.hostsSorted() | 
					
						
							|  |  |  | 	remote = make([]*peerRESTClient, 0, len(hosts)) | 
					
						
							|  |  |  | 	all = make([]*peerRESTClient, len(hosts)) | 
					
						
							|  |  |  | 	for i, host := range hosts { | 
					
						
							|  |  |  | 		if host == nil { | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 		all[i] = newPeerRESTClient(host, endpoints.FindGridHostsFromPeer(host)) | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 		remote = append(remote, all[i]) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	if len(all) != len(remote)+1 { | 
					
						
							| 
									
										
										
										
											2024-04-04 20:04:40 +08:00
										 |  |  | 		peersLogIf(context.Background(), fmt.Errorf("Expected number of all hosts (%v) to be remote +1 (%v)", len(all), len(remote)), logger.WarningKind) | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	return remote, all | 
					
						
							| 
									
										
										
										
											2019-03-15 07:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 11:36:00 +08:00
										 |  |  | // MonitorBandwidth - send http trace request to peer nodes
 | 
					
						
							| 
									
										
										
										
											2023-01-19 21:22:16 +08:00
										 |  |  | func (client *peerRESTClient) MonitorBandwidth(ctx context.Context, buckets []string) (*bandwidth.BucketBandwidthReport, error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	values := grid.NewURLValuesWith(map[string][]string{ | 
					
						
							|  |  |  | 		peerRESTBuckets: buckets, | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	return getBandwidthRPC.Call(ctx, client.gridConn(), values) | 
					
						
							| 
									
										
										
										
											2020-10-10 11:36:00 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | func (client *peerRESTClient) GetResourceMetrics(ctx context.Context) (<-chan MetricV2, error) { | 
					
						
							| 
									
										
										
										
											2024-02-25 16:51:38 +08:00
										 |  |  | 	resp, err := getResourceMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | 	ch := make(chan MetricV2) | 
					
						
							|  |  |  | 	go func(ch chan<- MetricV2) { | 
					
						
							| 
									
										
										
										
											2024-02-25 16:51:38 +08:00
										 |  |  | 		defer close(ch) | 
					
						
							|  |  |  | 		for _, m := range resp.Value() { | 
					
						
							|  |  |  | 			if m == nil { | 
					
						
							|  |  |  | 				continue | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			select { | 
					
						
							|  |  |  | 			case <-ctx.Done(): | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			case ch <- *m: | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}(ch) | 
					
						
							|  |  |  | 	return ch, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | func (client *peerRESTClient) GetPeerMetrics(ctx context.Context) (<-chan MetricV2, error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getPeerMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | 	ch := make(chan MetricV2) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	go func() { | 
					
						
							|  |  |  | 		defer close(ch) | 
					
						
							|  |  |  | 		for _, m := range resp.Value() { | 
					
						
							|  |  |  | 			if m == nil { | 
					
						
							|  |  |  | 				continue | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-02-09 01:11:16 +08:00
										 |  |  | 			select { | 
					
						
							|  |  |  | 			case <-ctx.Done(): | 
					
						
							|  |  |  | 				return | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 			case ch <- *m: | 
					
						
							| 
									
										
										
										
											2023-02-09 01:11:16 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 	return ch, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | func (client *peerRESTClient) GetPeerBucketMetrics(ctx context.Context) (<-chan MetricV2, error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getPeerBucketMetricsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							| 
									
										
										
										
											2023-07-19 13:25:12 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-10 17:15:15 +08:00
										 |  |  | 	ch := make(chan MetricV2) | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	go func() { | 
					
						
							|  |  |  | 		defer close(ch) | 
					
						
							|  |  |  | 		for _, m := range resp.Value() { | 
					
						
							|  |  |  | 			if m == nil { | 
					
						
							|  |  |  | 				continue | 
					
						
							| 
									
										
										
										
											2023-07-19 13:25:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			select { | 
					
						
							|  |  |  | 			case <-ctx.Done(): | 
					
						
							|  |  |  | 				return | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 			case ch <- *m: | 
					
						
							| 
									
										
										
										
											2023-07-19 13:25:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2023-07-19 13:25:12 +08:00
										 |  |  | 	return ch, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | func (client *peerRESTClient) SpeedTest(ctx context.Context, opts speedTestOpts) (SpeedTestResult, error) { | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 	values := make(url.Values) | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | 	values.Set(peerRESTSize, strconv.Itoa(opts.objectSize)) | 
					
						
							|  |  |  | 	values.Set(peerRESTConcurrent, strconv.Itoa(opts.concurrency)) | 
					
						
							|  |  |  | 	values.Set(peerRESTDuration, opts.duration.String()) | 
					
						
							|  |  |  | 	values.Set(peerRESTStorageClass, opts.storageClass) | 
					
						
							|  |  |  | 	values.Set(peerRESTBucket, opts.bucketName) | 
					
						
							| 
									
										
										
										
											2023-12-30 15:56:50 +08:00
										 |  |  | 	values.Set(peerRESTEnableSha256, strconv.FormatBool(opts.enableSha256)) | 
					
						
							| 
									
										
										
										
											2024-05-06 17:45:10 +08:00
										 |  |  | 	values.Set(peerRESTEnableMultipart, strconv.FormatBool(opts.enableMultipart)) | 
					
						
							| 
									
										
										
										
											2024-05-10 09:41:33 +08:00
										 |  |  | 	values.Set(peerRESTAccessKey, opts.creds.AccessKey) | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | 	respBody, err := client.callWithContext(context.Background(), peerRESTMethodSpeedTest, values, nil, -1) | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | 		return SpeedTestResult{}, err | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2021-09-01 05:08:23 +08:00
										 |  |  | 	waitReader, err := waitForHTTPResponse(respBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | 		return SpeedTestResult{}, err | 
					
						
							| 
									
										
										
										
											2021-09-01 05:08:23 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-13 01:12:47 +08:00
										 |  |  | 	var result SpeedTestResult | 
					
						
							| 
									
										
										
										
											2021-09-01 05:08:23 +08:00
										 |  |  | 	err = gob.NewDecoder(waitReader).Decode(&result) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return result, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if result.Error != "" { | 
					
						
							|  |  |  | 		return result, errors.New(result.Error) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result, nil | 
					
						
							| 
									
										
										
										
											2021-07-28 03:55:56 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-07 07:36:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-02 14:38:05 +08:00
										 |  |  | func (client *peerRESTClient) DriveSpeedTest(ctx context.Context, opts madmin.DriveSpeedTestOpts) (madmin.DriveSpeedTestResult, error) { | 
					
						
							|  |  |  | 	queryVals := make(url.Values) | 
					
						
							|  |  |  | 	if opts.Serial { | 
					
						
							|  |  |  | 		queryVals.Set("serial", "true") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	queryVals.Set("blocksize", strconv.FormatUint(opts.BlockSize, 10)) | 
					
						
							|  |  |  | 	queryVals.Set("filesize", strconv.FormatUint(opts.FileSize, 10)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodDriveSpeedTest, queryVals, nil, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return madmin.DriveSpeedTestResult{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2022-02-02 14:38:05 +08:00
										 |  |  | 	waitReader, err := waitForHTTPResponse(respBody) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return madmin.DriveSpeedTestResult{}, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var result madmin.DriveSpeedTestResult | 
					
						
							|  |  |  | 	err = gob.NewDecoder(waitReader).Decode(&result) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return result, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if result.Error != "" { | 
					
						
							|  |  |  | 		return result, errors.New(result.Error) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-27 06:33:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-14 05:21:55 +08:00
										 |  |  | func (client *peerRESTClient) GetLastDayTierStats(ctx context.Context) (DailyAllTierStats, error) { | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	resp, err := getLastDayTierStatsRPC.Call(ctx, client.gridConn(), grid.NewMSS()) | 
					
						
							|  |  |  | 	if err != nil || resp == nil { | 
					
						
							| 
									
										
										
										
											2022-04-14 05:21:55 +08:00
										 |  |  | 		return DailyAllTierStats{}, err | 
					
						
							| 
									
										
										
										
											2022-01-27 06:33:10 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-02-20 06:54:46 +08:00
										 |  |  | 	return *resp, nil | 
					
						
							| 
									
										
										
										
											2022-01-27 06:33:10 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-09 01:54:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // DevNull - Used by netperf to pump data to peer
 | 
					
						
							|  |  |  | func (client *peerRESTClient) DevNull(ctx context.Context, r io.Reader) error { | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodDevNull, nil, r, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2022-03-09 01:54:38 +08:00
										 |  |  | 	return err | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Netperf - To initiate netperf on peer
 | 
					
						
							|  |  |  | func (client *peerRESTClient) Netperf(ctx context.Context, duration time.Duration) (madmin.NetperfNodeResult, error) { | 
					
						
							|  |  |  | 	var result madmin.NetperfNodeResult | 
					
						
							|  |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(peerRESTDuration, duration.String()) | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(context.Background(), peerRESTMethodNetperf, values, nil, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return result, err | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-12-06 03:18:50 +08:00
										 |  |  | 	defer xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2022-03-09 01:54:38 +08:00
										 |  |  | 	err = gob.NewDecoder(respBody).Decode(&result) | 
					
						
							|  |  |  | 	return result, err | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-13 14:51:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // GetReplicationMRF - get replication MRF for bucket
 | 
					
						
							|  |  |  | func (client *peerRESTClient) GetReplicationMRF(ctx context.Context, bucket string) (chan madmin.ReplicationMRF, error) { | 
					
						
							|  |  |  | 	values := make(url.Values) | 
					
						
							|  |  |  | 	values.Set(peerRESTBucket, bucket) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	respBody, err := client.callWithContext(ctx, peerRESTMethodGetReplicationMRF, values, nil, -1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	dec := gob.NewDecoder(respBody) | 
					
						
							|  |  |  | 	ch := make(chan madmin.ReplicationMRF) | 
					
						
							|  |  |  | 	go func(ch chan madmin.ReplicationMRF) { | 
					
						
							|  |  |  | 		defer func() { | 
					
						
							|  |  |  | 			xhttp.DrainBody(respBody) | 
					
						
							| 
									
										
										
										
											2024-01-31 04:49:02 +08:00
										 |  |  | 			close(ch) | 
					
						
							| 
									
										
										
										
											2023-07-13 14:51:33 +08:00
										 |  |  | 		}() | 
					
						
							|  |  |  | 		for { | 
					
						
							|  |  |  | 			var entry madmin.ReplicationMRF | 
					
						
							|  |  |  | 			if err := dec.Decode(&entry); err != nil { | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			select { | 
					
						
							|  |  |  | 			case <-ctx.Done(): | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			case ch <- entry: | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}(ch) | 
					
						
							|  |  |  | 	return ch, nil | 
					
						
							|  |  |  | } |