From 76f1a61d53e002f26e46e8a8afac1f714a15690b Mon Sep 17 00:00:00 2001 From: nepathak Date: Wed, 10 May 2023 20:17:40 -0700 Subject: [PATCH 1/9] Cleanup certs_test.go --- pkg/sec/certs_test.go | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/pkg/sec/certs_test.go b/pkg/sec/certs_test.go index 37c40d74..a1a39e0b 100644 --- a/pkg/sec/certs_test.go +++ b/pkg/sec/certs_test.go @@ -28,31 +28,15 @@ import ( // Sample secrets crt, not a real crt var ( - server_crt_teststr = ` ------BEGIN CERTIFICATE----- -MIIFGjCCAwICCQD30WAwBJQubzANBgkqhkiG9w0BAQsFADBPMRIwEAYDVQQKDAlK -dW5vIFRlc3QxFzAVBgNVBAMMDmNlcnQtYXV0aG9yaXR5MQswCQYDVQQGEwJVUzET ------END CERTIFICATE----- -` - server_key_teststr = ` ------BEGIN PRIVATE KEY----- -MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDP9gNEfnn9Uay6 -UggNSF1wmk4qKjhlThU2eiX0DQgwugHplRQEk0RcktmSTs6rF620HJMIKrgB9sP/ ------END PRIVATE KEY----- -` - ca_teststr = ` ------BEGIN CERTIFICATE----- -MIIFGjCCAwICCQD30WAwBJQubzANBgkqhkiG9w0BAQsFADBPMRIwEAYDVQQKDAlK -dW5vIFRlc3QxFzAVBgNVBAMMDmNlcnQtYXV0aG9yaXR5MQswCQYDVQQGEwJVUzET -ihA+JnmsWFTHotRgeeo= ------END CERTIFICATE----- -` + server_crt_teststr = `SCERT` + server_key_teststr = `SKEY` + ca_teststr = `CA` - certPem_bytes = []byte{10, 45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10, 77, 73, 73, 70, 71, 106, 67, 67, 65, 119, 73, 67, 67, 81, 68, 51, 48, 87, 65, 119, 66, 74, 81, 117, 98, 122, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 115, 70, 65, 68, 66, 80, 77, 82, 73, 119, 69, 65, 89, 68, 86, 81, 81, 75, 68, 65, 108, 75, 10, 100, 87, 53, 118, 73, 70, 82, 108, 99, 51, 81, 120, 70, 122, 65, 86, 66, 103, 78, 86, 66, 65, 77, 77, 68, 109, 78, 108, 99, 110, 81, 116, 89, 88, 86, 48, 97, 71, 57, 121, 97, 88, 82, 53, 77, 81, 115, 119, 67, 81, 89, 68, 86, 81, 81, 71, 69, 119, 74, 86, 85, 122, 69, 84, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10} + certPem_bytes = []byte{83, 67, 69, 82, 84} - certCaPem_bytes = []byte{10, 45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10, 77, 73, 73, 70, 71, 106, 67, 67, 65, 119, 73, 67, 67, 81, 68, 51, 48, 87, 65, 119, 66, 74, 81, 117, 98, 122, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 115, 70, 65, 68, 66, 80, 77, 82, 73, 119, 69, 65, 89, 68, 86, 81, 81, 75, 68, 65, 108, 75, 10, 100, 87, 53, 118, 73, 70, 82, 108, 99, 51, 81, 120, 70, 122, 65, 86, 66, 103, 78, 86, 66, 65, 77, 77, 68, 109, 78, 108, 99, 110, 81, 116, 89, 88, 86, 48, 97, 71, 57, 121, 97, 88, 82, 53, 77, 81, 115, 119, 67, 81, 89, 68, 86, 81, 81, 71, 69, 119, 74, 86, 85, 122, 69, 84, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10, 10, 45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10, 77, 73, 73, 70, 71, 106, 67, 67, 65, 119, 73, 67, 67, 81, 68, 51, 48, 87, 65, 119, 66, 74, 81, 117, 98, 122, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 115, 70, 65, 68, 66, 80, 77, 82, 73, 119, 69, 65, 89, 68, 86, 81, 81, 75, 68, 65, 108, 75, 10, 100, 87, 53, 118, 73, 70, 82, 108, 99, 51, 81, 120, 70, 122, 65, 86, 66, 103, 78, 86, 66, 65, 77, 77, 68, 109, 78, 108, 99, 110, 81, 116, 89, 88, 86, 48, 97, 71, 57, 121, 97, 88, 82, 53, 77, 81, 115, 119, 67, 81, 89, 68, 86, 81, 81, 71, 69, 119, 74, 86, 85, 122, 69, 84, 10, 105, 104, 65, 43, 74, 110, 109, 115, 87, 70, 84, 72, 111, 116, 82, 103, 101, 101, 111, 61, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45, 10} + certCaPem_bytes = []byte{83, 67, 69, 82, 84, 67, 65} - keyPem_byte = []byte{10, 45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10, 77, 73, 73, 74, 81, 119, 73, 66, 65, 68, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 83, 67, 67, 83, 48, 119, 103, 103, 107, 112, 65, 103, 69, 65, 65, 111, 73, 67, 65, 81, 68, 80, 57, 103, 78, 69, 102, 110, 110, 57, 85, 97, 121, 54, 10, 85, 103, 103, 78, 83, 70, 49, 119, 109, 107, 52, 113, 75, 106, 104, 108, 84, 104, 85, 50, 101, 105, 88, 48, 68, 81, 103, 119, 117, 103, 72, 112, 108, 82, 81, 69, 107, 48, 82, 99, 107, 116, 109, 83, 84, 115, 54, 114, 70, 54, 50, 48, 72, 74, 77, 73, 75, 114, 103, 66, 57, 115, 80, 47, 10, 45, 45, 45, 45, 45, 69, 78, 68, 32, 80, 82, 73, 86, 65, 84, 69, 32, 75, 69, 89, 45, 45, 45, 45, 45, 10} + keyPem_byte = []byte{83, 75, 69, 89} ) func createLocalSecretFile(secretfilename, secret_string string) { From 66cc9588fd7009e11bba5779f39ec825e56724af Mon Sep 17 00:00:00 2001 From: nepathak Date: Wed, 10 May 2023 20:26:17 -0700 Subject: [PATCH 2/9] use net.JoinHostPort instead of fmt.Sprintf(, ) - best practice --- cmd/dbscanserv/app/remote.go | 3 ++- pkg/cluster/config.go | 4 +++- test/testutil/server/server.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/dbscanserv/app/remote.go b/cmd/dbscanserv/app/remote.go index 984eab53..46d4ca4d 100644 --- a/cmd/dbscanserv/app/remote.go +++ b/cmd/dbscanserv/app/remote.go @@ -25,6 +25,7 @@ import ( "net/rpc" "os" "path/filepath" + "strconv" "sync" "sync/atomic" "time" @@ -144,7 +145,7 @@ func IsLocalAddress(ip string, zoneid int) bool { } func GenRemoteAddr(ip string, zoneid int) string { - return fmt.Sprintf("%s:%d", ip, getPeerPort(zoneid)) + return net.JoinHostPort(ip, strconv.Itoa(getPeerPort(zoneid))) } // Start listener diff --git a/pkg/cluster/config.go b/pkg/cluster/config.go index ad701465..90c38bfd 100644 --- a/pkg/cluster/config.go +++ b/pkg/cluster/config.go @@ -22,6 +22,8 @@ package cluster import ( "errors" "fmt" + "net" + "strconv" ) type Config struct { @@ -56,7 +58,7 @@ func (c *Config) Validate() error { for i := 0; i < int(c.NumZones); i++ { for _, host := range c.SSHosts[i] { for _, port := range c.SSPorts { - c.ConnInfo[i] = append(c.ConnInfo[i], fmt.Sprintf("%s:%d", host, port)) + c.ConnInfo[i] = append(c.ConnInfo[i], net.JoinHostPort(host, strconv.Itoa(int(port)))) } } } diff --git a/test/testutil/server/server.go b/test/testutil/server/server.go index 3585fcc5..66aa7a27 100644 --- a/test/testutil/server/server.go +++ b/test/testutil/server/server.go @@ -92,7 +92,7 @@ func (s *ServerBase) init(name string, id uint, ipAddr string, port string, sslE if err != nil { glog.Fatal(err) } - s.httpMonAddr = fmt.Sprintf("%s:%d", ipAddr, httpport+1) + s.httpMonAddr = net.JoinHostPort(ipAddr, strconv.Itoa(httpport+1)) } else { if !strings.Contains(httpMonAddr, ":") { httpMonAddr = ":" + httpMonAddr @@ -101,7 +101,7 @@ func (s *ServerBase) init(name string, id uint, ipAddr string, port string, sslE if httpHost == "" { httpHost = ipAddr } - s.httpMonAddr = fmt.Sprintf("%s:%s", httpHost, httpPort) + s.httpMonAddr = net.JoinHostPort(httpHost, httpPort) } } From 002d130ac575fb7a0b6f4cce143c2e88669e1cf7 Mon Sep 17 00:00:00 2001 From: nepathak Date: Wed, 10 May 2023 20:50:29 -0700 Subject: [PATCH 3/9] Remove bad nil guard --- cmd/proxy/proc/processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/proxy/proc/processor.go b/cmd/proxy/proc/processor.go index b21ba2c5..b9821edb 100644 --- a/cmd/proxy/proc/processor.go +++ b/cmd/proxy/proc/processor.go @@ -366,7 +366,7 @@ func (p *TwoPhaseProcessor) replyStatusToClient(st proto.OpStatus) { p.commit.noErrResponse.ssRequest.ssRespOpMsg.SetOpStatus(proto.OpStatusInconsistent) payload := p.commit.noErrResponse.ssRequest.ssRespOpMsg.GetPayload() // follow the sendRepairs - if payload != nil || payload.GetLength() == 0 { + if payload != nil { p.commit.noErrResponse.ssRequest.ssRespOpMsg.SetPayload(p.clientRequest.GetPayload()) } p.replyToClient(&p.commit.noErrResponse) From b24645332b49be15376e8ae05a7a46961031ef8e Mon Sep 17 00:00:00 2001 From: nepathak Date: Wed, 10 May 2023 22:17:17 -0700 Subject: [PATCH 4/9] Using errors.Is with the appropriate error type --- cmd/clustermgr/clusterctl/clusterctl.go | 4 +++- cmd/clustermgr/clustermgr.go | 4 +++- cmd/proxy/app/proxy.go | 4 +++- cmd/proxy/app/proxymgr.go | 4 +++- cmd/proxy/stats/statslogger.go | 4 +++- cmd/storageserv/app/ssmgr.go | 4 +++- cmd/storageserv/app/storagemgr.go | 4 +++- cmd/storageserv/compact/dbclient.go | 4 +++- cmd/storageserv/config/config.go | 4 +++- cmd/storageserv/stats/statslogger.go | 4 +++- cmd/storageserv/storage/db/config.go | 4 +++- cmd/storageserv/storage/db/dbcopy/config.go | 4 +++- cmd/storageserv/storage/db/dbcopy/main.go | 6 ++++-- cmd/storageserv/storage/db/rocksdb.go | 5 +++-- pkg/cluster/cluster.go | 8 +++++--- 15 files changed, 48 insertions(+), 19 deletions(-) diff --git a/cmd/clustermgr/clusterctl/clusterctl.go b/cmd/clustermgr/clusterctl/clusterctl.go index 97a12644..24a3d289 100644 --- a/cmd/clustermgr/clusterctl/clusterctl.go +++ b/cmd/clustermgr/clusterctl/clusterctl.go @@ -20,8 +20,10 @@ package main import ( + "errors" "flag" "fmt" + "io/fs" "os" "path/filepath" "strings" @@ -152,7 +154,7 @@ func defaultConfig(progName string) (config string) { config = fmt.Sprintf("%s/config/config.toml", dirName) _, err = os.Stat(config) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { glog.Exitf("[ERROR] %s does not exist.", config) } diff --git a/cmd/clustermgr/clustermgr.go b/cmd/clustermgr/clustermgr.go index 29ed1b61..4bc94f1f 100644 --- a/cmd/clustermgr/clustermgr.go +++ b/cmd/clustermgr/clustermgr.go @@ -20,8 +20,10 @@ package main import ( + "errors" "flag" "fmt" + "io/fs" "os" "path/filepath" @@ -151,7 +153,7 @@ func defaultConfig(progName string) (config string) { config = fmt.Sprintf("%s/config.toml", dirName) _, err = os.Stat(config) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { glog.Exitf("[ERROR] %s does not exist.", config) } diff --git a/cmd/proxy/app/proxy.go b/cmd/proxy/app/proxy.go index 995b8d19..e5a1c541 100644 --- a/cmd/proxy/app/proxy.go +++ b/cmd/proxy/app/proxy.go @@ -23,7 +23,9 @@ Juno Proxy Server package app import ( + "errors" "fmt" + "io/fs" _ "net/http/pprof" "os" "os/exec" @@ -95,7 +97,7 @@ USAGE if configFilename == "" { glog.Exitf("\n\n*** missing config option ***\n\n") } - if _, err := os.Stat(configFilename); os.IsNotExist(err) { + if _, err := os.Stat(configFilename); errors.Is(err, fs.ErrNotExist) { glog.Exitf("\n\n*** config file \"%s\" not found ***\n\n", configFilename) } appName := "[" + progName + "] " diff --git a/cmd/proxy/app/proxymgr.go b/cmd/proxy/app/proxymgr.go index 128a438b..29fe7387 100644 --- a/cmd/proxy/app/proxymgr.go +++ b/cmd/proxy/app/proxymgr.go @@ -20,7 +20,9 @@ package app import ( + "errors" "fmt" + "io/fs" "io/ioutil" "os" "strconv" @@ -80,7 +82,7 @@ func (c *CmdProxyCommon) Parse(args []string) (err error) { os.Exit(-1) } - if _, err := os.Stat(c.optConfigFile); os.IsNotExist(err) { + if _, err := os.Stat(c.optConfigFile); errors.Is(err, fs.ErrNotExist) { fmt.Fprintf(os.Stderr, "\n\n*** config file \"%s\" not found ***\n\n", c.optConfigFile) os.Exit(-1) } diff --git a/cmd/proxy/stats/statslogger.go b/cmd/proxy/stats/statslogger.go index b34de10a..80cd7d0f 100644 --- a/cmd/proxy/stats/statslogger.go +++ b/cmd/proxy/stats/statslogger.go @@ -21,8 +21,10 @@ package stats import ( "bytes" + "errors" "fmt" goio "io" + "io/fs" "os" "path/filepath" "time" @@ -131,7 +133,7 @@ func (l *statsLoggerT) Init() { } cfg := &config.Conf if cfg.StateLogEnabled { - if _, err := os.Stat(cfg.StateLogDir); os.IsNotExist(err) { + if _, err := os.Stat(cfg.StateLogDir); errors.Is(err, fs.ErrNotExist) { os.Mkdir(cfg.StateLogDir, 0777) } } diff --git a/cmd/storageserv/app/ssmgr.go b/cmd/storageserv/app/ssmgr.go index b4d349f8..4ee27b01 100644 --- a/cmd/storageserv/app/ssmgr.go +++ b/cmd/storageserv/app/ssmgr.go @@ -20,7 +20,9 @@ package app import ( + "errors" "fmt" + "io/fs" "net" "os" @@ -73,7 +75,7 @@ func (c *CmdStorageCommon) Parse(args []string) (err error) { os.Exit(-1) } - if _, err := os.Stat(c.optConfigFile); os.IsNotExist(err) { + if _, err := os.Stat(c.optConfigFile); errors.Is(err, fs.ErrNotExist) { fmt.Fprintf(os.Stderr, "\n\n*** config file \"%s\" not found ***\n\n", c.optConfigFile) os.Exit(-1) } diff --git a/cmd/storageserv/app/storagemgr.go b/cmd/storageserv/app/storagemgr.go index c5a209f3..a7600e13 100644 --- a/cmd/storageserv/app/storagemgr.go +++ b/cmd/storageserv/app/storagemgr.go @@ -20,7 +20,9 @@ package app import ( + "errors" "fmt" + "io/fs" "io/ioutil" "math" "net" @@ -134,7 +136,7 @@ func (s *ServerManager) Run() { if s.dbScanPort > 0 { cmdPath := fmt.Sprintf("%s/%s", filepath.Dir(s.cmdPath), "dbscanserv") _, err := os.Stat(cmdPath) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { glog.Exitf("missing executable file: dbscanserv.") } } diff --git a/cmd/storageserv/compact/dbclient.go b/cmd/storageserv/compact/dbclient.go index a940dd67..6d92d985 100644 --- a/cmd/storageserv/compact/dbclient.go +++ b/cmd/storageserv/compact/dbclient.go @@ -21,7 +21,9 @@ package compact import ( "encoding/binary" + "errors" "fmt" + "io/fs" "os" "path/filepath" "time" @@ -49,7 +51,7 @@ func fileExist(name string) bool { func Watch(zoneid, nodeid int, suspend service.SuspendFunc) { dir := "events" - if _, err := os.Stat(dir); os.IsNotExist(err) { + if _, err := os.Stat(dir); errors.Is(err, fs.ErrNotExist) { os.Mkdir(dir, 0777) } diff --git a/cmd/storageserv/config/config.go b/cmd/storageserv/config/config.go index 34c2c1cf..524a3de3 100644 --- a/cmd/storageserv/config/config.go +++ b/cmd/storageserv/config/config.go @@ -21,7 +21,9 @@ package config import ( "bytes" + "errors" "fmt" + "io/fs" "math" "os" "path/filepath" @@ -163,7 +165,7 @@ func LoadConfig(ssConfigFile string) (err error) { if !serverConfig.MicroShardsEnabled && len(serverConfig.DB.DbPaths) >= 1 { tagFile := fmt.Sprintf("%s/microshard_enabled.txt", serverConfig.DB.DbPaths[0].Path) _, err := os.Stat(tagFile) - if !os.IsNotExist(err) { + if !errors.Is(err, fs.ErrNotExist) { // db was converted by dbcopy tool. serverConfig.MicroShardsEnabled = true } diff --git a/cmd/storageserv/stats/statslogger.go b/cmd/storageserv/stats/statslogger.go index 5137175e..a36ca100 100644 --- a/cmd/storageserv/stats/statslogger.go +++ b/cmd/storageserv/stats/statslogger.go @@ -21,8 +21,10 @@ package stats import ( "bytes" + "errors" "fmt" goio "io" + "io/fs" "os" "path/filepath" "time" @@ -119,7 +121,7 @@ func (l *statsLoggerT) Init() { } cfg := config.ServerConfig() if cfg.StateLogEnabled { - if _, err := os.Stat(cfg.StateLogDir); os.IsNotExist(err) { + if _, err := os.Stat(cfg.StateLogDir); errors.Is(err, fs.ErrNotExist) { os.Mkdir(cfg.StateLogDir, 0777) } } diff --git a/cmd/storageserv/storage/db/config.go b/cmd/storageserv/storage/db/config.go index 0246b550..f7df81f7 100644 --- a/cmd/storageserv/storage/db/config.go +++ b/cmd/storageserv/storage/db/config.go @@ -20,7 +20,9 @@ package db import ( + "errors" "fmt" + "io/fs" "math/rand" "os" @@ -339,7 +341,7 @@ func (cfg *Config) OnLoad() { writeOptions.DisableWAL(cfg.WriteDisableWAL) if !cfg.WriteDisableWAL && len(cfg.WalDir) > 0 { - if _, err := os.Stat(cfg.WalDir); os.IsNotExist(err) { + if _, err := os.Stat(cfg.WalDir); errors.Is(err, fs.ErrNotExist) { err = os.MkdirAll(cfg.WalDir, 0777) if err != nil { glog.Exit("Error : ", err.Error()) diff --git a/cmd/storageserv/storage/db/dbcopy/config.go b/cmd/storageserv/storage/db/dbcopy/config.go index b20051a4..be179719 100644 --- a/cmd/storageserv/storage/db/dbcopy/config.go +++ b/cmd/storageserv/storage/db/dbcopy/config.go @@ -20,7 +20,9 @@ package main import ( + "errors" "fmt" + "io/fs" "os" "path/filepath" @@ -72,7 +74,7 @@ func LoadConfig(file string) string { if !cfg.MicroShardsEnabled { tagFile := fmt.Sprintf("%s/microshard_enabled.txt", dbPath) _, err := os.Stat(tagFile) - if !os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { // db was converted by dbcopy tool. cfg.MicroShardsEnabled = true cfg.NumMicroShards = 256 diff --git a/cmd/storageserv/storage/db/dbcopy/main.go b/cmd/storageserv/storage/db/dbcopy/main.go index 3361f4d1..80c06928 100644 --- a/cmd/storageserv/storage/db/dbcopy/main.go +++ b/cmd/storageserv/storage/db/dbcopy/main.go @@ -21,8 +21,10 @@ package main import ( + "errors" "flag" "fmt" + "io/fs" "os" "path/filepath" "strconv" @@ -108,7 +110,7 @@ func getDbSet(dbPath string, tgtPath string, zone, node int, dbRange string) (db } target := fmt.Sprintf("%s/%s", tgtPath, filepath.Base(path)) - if _, err := os.Stat(target); os.IsNotExist(err) { + if _, err := os.Stat(target); errors.Is(err, fs.ErrNotExist) { err = os.MkdirAll(target, 0777) if err != nil { glog.Exitf("[ERROR] %s", err) @@ -205,7 +207,7 @@ func main() { newDir := fmt.Sprintf("%s/dbcopy_%s", filepath.Dir(dbPath), filepath.Base(dbPath)) if len(tgtPath) > 0 { _, err := os.Stat(newDir) - if !os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { glog.Exitf("[ERROR] %s from last dbcopy was left over.", newDir) } } diff --git a/cmd/storageserv/storage/db/rocksdb.go b/cmd/storageserv/storage/db/rocksdb.go index 2b480b50..11b1d13c 100644 --- a/cmd/storageserv/storage/db/rocksdb.go +++ b/cmd/storageserv/storage/db/rocksdb.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "sync/atomic" "time" @@ -408,7 +409,7 @@ func (r *RocksDB) UpdateRedistShards(shards shard.Map) { glog.Infof("Create New DB with updated redist shards") // add new shards - // if _, err := os.Stat(r.dbDir); os.IsNotExist(err) { + // if _, err := os.Stat(r.dbDir); errors.Is(err, fs.ErrNotExist) { // os.Mkdir(r.dbDir, 0777) // } @@ -437,7 +438,7 @@ func (r *RocksDB) Setup() { if len(dbpath.Path) == 0 { glog.Exit("Error: DbPaths contains an empty string.") } - if _, err := os.Stat(dbpath.Path); os.IsNotExist(err) { + if _, err := os.Stat(dbpath.Path); errors.Is(err, fs.ErrNotExist) { err = os.MkdirAll(dbpath.Path, 0777) if err != nil { glog.Exit("Error : ", err.Error()) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index a55b813c..3b0827d7 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -23,6 +23,7 @@ import ( "bytes" "errors" "fmt" + "io/fs" "math/rand" "os" "path/filepath" @@ -31,8 +32,9 @@ import ( "syscall" "time" - "github.com/BurntSushi/toml" "juno/third_party/forked/golang/glog" + + "github.com/BurntSushi/toml" ) type Cluster struct { @@ -381,7 +383,7 @@ func (c *Cluster) WriteToCache(cachePath string, cacheName string, version uint3 if version > 2 { oldfile := fmt.Sprintf("%s.%d", filePrefix, version-2) err2 := os.Remove(oldfile) - if os.IsExist(err2) && err2 != nil { + if errors.Is(err2, fs.ErrExist) && err2 != nil { glog.Errorf("%s: %v", oldfile, err2) } } @@ -389,7 +391,7 @@ func (c *Cluster) WriteToCache(cachePath string, cacheName string, version uint3 cname := filepath.Clean(filepath.Join(cachePath, cacheName)) // Remove file link err = os.Remove(cname) - if os.IsExist(err) && err != nil { + if errors.Is(err, fs.ErrExist) && err != nil { glog.Errorf("%v", err) return err } From ba2ef571499ec3cc54e0cd28bc16a4e1d4837afb Mon Sep 17 00:00:00 2001 From: nepathak Date: Wed, 10 May 2023 23:37:24 -0700 Subject: [PATCH 5/9] Using err.Error() to get Error String --- cmd/dbscanserv/app/cmd.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/dbscanserv/app/cmd.go b/cmd/dbscanserv/app/cmd.go index 28026fef..a642a978 100644 --- a/cmd/dbscanserv/app/cmd.go +++ b/cmd/dbscanserv/app/cmd.go @@ -24,7 +24,6 @@ import ( "bytes" "encoding/binary" "encoding/json" - "fmt" "os" "strings" "time" @@ -285,7 +284,7 @@ func GetVersionFromDb(key []byte, zoneid int) (data []byte, valLen int, value, err := handle.Get(ro, key) if err != nil { - msg = fmt.Sprintf("%s", err) + msg = err.Error() return } @@ -300,7 +299,7 @@ func GetVersionFromDb(key []byte, zoneid int) (data []byte, valLen int, } if err != nil { - msg = fmt.Sprintf("%s", err) + msg = err.Error() return } From a1c915a6de74a2735c34cb7df0abb35a7206ea9c Mon Sep 17 00:00:00 2001 From: nepathak Date: Thu, 11 May 2023 00:20:58 -0700 Subject: [PATCH 6/9] Updating deprecated methods ioutil.ReadFile,ioutil.ReadAll and ioutil.WriteFile to os.ReadFile,io.ReadAll and os.WriteFile respectively --- cmd/proxy/app/proxymgr.go | 5 ++--- cmd/proxy/stats/monhandler.go | 6 +++--- cmd/storageserv/app/storagemgr.go | 5 ++--- cmd/storageserv/stats/monhandler.go | 4 ++-- pkg/logging/otel/test/mock_collector.go | 3 +-- pkg/sec/certs.go | 7 +++---- test/testutil/server/cluster.go | 6 +++--- test/testutil/server/server.go | 7 +++---- test/testutil/testhelper.go | 13 ++++++------- 9 files changed, 25 insertions(+), 31 deletions(-) diff --git a/cmd/proxy/app/proxymgr.go b/cmd/proxy/app/proxymgr.go index 29fe7387..19cc1433 100644 --- a/cmd/proxy/app/proxymgr.go +++ b/cmd/proxy/app/proxymgr.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io/fs" - "io/ioutil" "os" "strconv" "strings" @@ -115,7 +114,7 @@ func (c *Manager) Exec() { pidFile := cfg.PidFileName - if data, err := ioutil.ReadFile(pidFile); err == nil { + if data, err := os.ReadFile(pidFile); err == nil { if pid, err := strconv.Atoi(strings.TrimSpace(string(data))); err == nil { if process, err := os.FindProcess(pid); err == nil { if err := process.Signal(syscall.Signal(0)); err == nil { @@ -125,7 +124,7 @@ func (c *Manager) Exec() { } } } - ioutil.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0644) + os.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0644) defer os.Remove(pidFile) if len(cfg.LogLevel) == 0 || c.optLogLevel != kDefaultLogLevel { diff --git a/cmd/proxy/stats/monhandler.go b/cmd/proxy/stats/monhandler.go index fbc2ac0b..e649e78c 100644 --- a/cmd/proxy/stats/monhandler.go +++ b/cmd/proxy/stats/monhandler.go @@ -23,7 +23,7 @@ import ( "bytes" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -162,7 +162,7 @@ func (h *HandlerForMonitor) getFromWorkerWithWorkerIdByPost(r *http.Request, wor glog.Infof("Content-Type: %v\n", contents) } if resp, err = http.Post(url, contents, r.Body); err == nil { - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) resp.Body.Close() } else { glog.Errorln(err) @@ -237,7 +237,7 @@ func (h *HandlerForMonitor) getFromWorkerWithWorkerId(urlPath string, query url. url += "?" + qstr } if resp, err = http.Get(url); err == nil { - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) resp.Body.Close() } else { glog.Errorln(err) diff --git a/cmd/storageserv/app/storagemgr.go b/cmd/storageserv/app/storagemgr.go index a7600e13..ee9c288d 100644 --- a/cmd/storageserv/app/storagemgr.go +++ b/cmd/storageserv/app/storagemgr.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io/fs" - "io/ioutil" "math" "net" "os" @@ -121,7 +120,7 @@ func NewServerManager(num int, pidFileName string, path string, args []string, func (s *ServerManager) Run() { pidFile := s.pidFileName - if data, err := ioutil.ReadFile(pidFile); err == nil { + if data, err := os.ReadFile(pidFile); err == nil { if pid, err := strconv.Atoi(strings.TrimSpace(string(data))); err == nil { if process, err := os.FindProcess(pid); err == nil { if err := process.Signal(syscall.Signal(0)); err == nil { @@ -141,7 +140,7 @@ func (s *ServerManager) Run() { } } - ioutil.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0644) + os.WriteFile(pidFile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0644) defer os.Remove(pidFile) defer shmstats.Finalize() diff --git a/cmd/storageserv/stats/monhandler.go b/cmd/storageserv/stats/monhandler.go index d144d2ab..1742003c 100644 --- a/cmd/storageserv/stats/monhandler.go +++ b/cmd/storageserv/stats/monhandler.go @@ -23,7 +23,7 @@ import ( "bytes" "fmt" "html/template" - "io/ioutil" + "io" "net/http" "net/url" "strconv" @@ -124,7 +124,7 @@ func (c *HttpHandlerForMonitor) getFromWorkerWithWorkerId(urlPath string, query url += "?" + qstr } if resp, err = http.Get(url); err == nil { - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) resp.Body.Close() } else { glog.Errorln(err) diff --git a/pkg/logging/otel/test/mock_collector.go b/pkg/logging/otel/test/mock_collector.go index 03da2e13..5b29af06 100644 --- a/pkg/logging/otel/test/mock_collector.go +++ b/pkg/logging/otel/test/mock_collector.go @@ -31,7 +31,6 @@ import ( "encoding/pem" "fmt" "io" - "io/ioutil" "math/big" mathrand "math/rand" "net" @@ -162,7 +161,7 @@ func readRequest(r *http.Request) ([]byte, error) { if r.Header.Get("Content-Encoding") == "gzip" { return readGzipBody(r.Body) } - return ioutil.ReadAll(r.Body) + return io.ReadAll(r.Body) } func readGzipBody(body io.Reader) ([]byte, error) { diff --git a/pkg/sec/certs.go b/pkg/sec/certs.go index 893aefea..cacc680e 100644 --- a/pkg/sec/certs.go +++ b/pkg/sec/certs.go @@ -20,7 +20,6 @@ package sec import ( - "io/ioutil" "juno/third_party/forked/golang/glog" "os" ) @@ -31,7 +30,7 @@ type localFileProtectedT struct { } func (p *localFileProtectedT) getCertAndKeyPemBlock(cfg *Config) (certPEMBlock []byte, keyPEMBlock []byte, err error) { - certPEMBlock, err = ioutil.ReadFile(cfg.CertPemFilePath) + certPEMBlock, err = os.ReadFile(cfg.CertPemFilePath) if err != nil { return } @@ -39,7 +38,7 @@ func (p *localFileProtectedT) getCertAndKeyPemBlock(cfg *Config) (certPEMBlock [ if cfg.ClientAuth { if _, err = os.Stat(cfg.CAFilePath); err == nil { var caPEMBlock []byte - caPEMBlock, err = ioutil.ReadFile(cfg.CAFilePath) + caPEMBlock, err = os.ReadFile(cfg.CAFilePath) if err != nil { glog.Errorln(err) return @@ -52,7 +51,7 @@ func (p *localFileProtectedT) getCertAndKeyPemBlock(cfg *Config) (certPEMBlock [ } } - keyPEMBlock, err = ioutil.ReadFile(cfg.KeyPemFilePath) + keyPEMBlock, err = os.ReadFile(cfg.KeyPemFilePath) if err != nil { return } diff --git a/test/testutil/server/cluster.go b/test/testutil/server/cluster.go index 2454815d..4467ef7e 100644 --- a/test/testutil/server/cluster.go +++ b/test/testutil/server/cluster.go @@ -21,7 +21,7 @@ package server import ( "fmt" - "io/ioutil" + "io" "net" "net/http" "net/url" @@ -464,7 +464,7 @@ func (c *Cluster) IsProxyConnectedWithSS(nodes ...SSNode) bool { query += fmt.Sprintf("&node=%d,%d", ss.Zone, ss.Node) } if resp, err := http.Get(query); err == nil { - if body, err := ioutil.ReadAll(resp.Body); err == nil { + if body, err := io.ReadAll(resp.Body); err == nil { if strings.EqualFold(string(body), "true") { return true } @@ -504,7 +504,7 @@ func (c *Cluster) IsProxyNotConnectedWithSS(nodes ...SSNode) bool { query += fmt.Sprintf("&node=%d,%d", ss.Zone, ss.Node) } if resp, err := http.Get(query); err == nil { - if body, err := ioutil.ReadAll(resp.Body); err == nil { + if body, err := io.ReadAll(resp.Body); err == nil { if strings.EqualFold(string(body), "true") { return true } diff --git a/test/testutil/server/server.go b/test/testutil/server/server.go index 66aa7a27..c3bbbaaf 100644 --- a/test/testutil/server/server.go +++ b/test/testutil/server/server.go @@ -21,7 +21,8 @@ package server import ( "fmt" - "io/ioutil" + pkgio "io" + "juno/third_party/forked/golang/glog" "net" "net/http" "os" @@ -30,8 +31,6 @@ import ( "strings" "time" - "juno/third_party/forked/golang/glog" - "juno/internal/cli" "juno/pkg/io" "juno/pkg/net/netutil" @@ -189,7 +188,7 @@ func (s *Server) Restart() error { func (s *Server) IsUp() bool { query := fmt.Sprintf("http://%s/stats?info=get_pid", s.GetHttpMonAddr()) if resp, err := http.Get(query); err == nil { - if body, err := ioutil.ReadAll(resp.Body); err == nil { + if body, err := pkgio.ReadAll(resp.Body); err == nil { pids := strings.Split(string(body), ",") if len(pids) == 0 { return false diff --git a/test/testutil/testhelper.go b/test/testutil/testhelper.go index 082bd865..537e36ee 100644 --- a/test/testutil/testhelper.go +++ b/test/testutil/testhelper.go @@ -24,7 +24,6 @@ import ( "bytes" "crypto/rand" "fmt" - "io/ioutil" "net" "os" "os/exec" @@ -685,7 +684,7 @@ func AddProxyConfig(file string, config string) error { } func RemoveProxyConfig(file string, config string) error { - input, err := ioutil.ReadFile(file) + input, err := os.ReadFile(file) if err != nil { return fmt.Errorf("not able to read proxy config file: %s", err.Error()) } @@ -698,7 +697,7 @@ func RemoveProxyConfig(file string, config string) error { } } output := strings.Join(lines, "\n") - if err = ioutil.WriteFile(file, []byte(output), 0644); err != nil { + if err = os.WriteFile(file, []byte(output), 0644); err != nil { return fmt.Errorf("not able to write to file with replaced string: %s", err.Error()) } return nil @@ -725,7 +724,7 @@ func AddRemoveProxyConfigValue(file string, config string, parentConfig string, lfile = file } - _, err := ioutil.ReadFile(lfile) + _, err := os.ReadFile(lfile) if err != nil { return fmt.Errorf("not able to read proxy config file: %s err: %s", lfile, err.Error()) } @@ -787,7 +786,7 @@ func GetProxyConfigValue(file string, config string, parentConfig string, hostip lfile = file } - input, err := ioutil.ReadFile(lfile) + input, err := os.ReadFile(lfile) if err != nil { return "", fmt.Errorf("not able to read proxy config file: %s", err.Error()) } @@ -845,7 +844,7 @@ func UpdateProxyConfig(file string, old string, new string, parentConfig string, lfile = file } - input, err := ioutil.ReadFile(lfile) + input, err := os.ReadFile(lfile) if err != nil { return fmt.Errorf("not able to read proxy config file: %s err: %s", lfile, err.Error()) } @@ -890,7 +889,7 @@ func UpdateProxyConfig(file string, old string, new string, parentConfig string, return fmt.Errorf("not able to find replaced string in config file or under parent config: %s", err.Error()) } output := strings.Join(lines, "\n") //change the file with new config - if err = ioutil.WriteFile(lfile, []byte(output), 0644); err != nil { + if err = os.WriteFile(lfile, []byte(output), 0644); err != nil { return fmt.Errorf("not able to write to file with replaced string, file is: %s err: %s", lfile, err.Error()) } From 3f15ca95134d55f8ac37e7c72617046971423999 Mon Sep 17 00:00:00 2001 From: nepathak Date: Thu, 11 May 2023 12:39:09 -0700 Subject: [PATCH 7/9] Remove pprof --- cmd/proxy/app/proxy.go | 1 - cmd/proxy/stats/htmltmpl.go | 51 ---------------------------- cmd/proxy/stats/httphandler.go | 27 --------------- cmd/proxy/stats/monhandler.go | 16 --------- cmd/storageserv/app/storageserv.go | 1 - cmd/storageserv/stats/htmltmpl.go | 44 ++---------------------- cmd/storageserv/stats/httphandler.go | 24 ------------- cmd/storageserv/stats/monhandler.go | 16 --------- cmd/storageserv/stats/statsinit.go | 6 ---- pkg/logging/cal/test/main.go | 24 +------------ test/drv/junoload/junoload.go | 1 - test/functest/setup_test.go | 1 - 12 files changed, 3 insertions(+), 209 deletions(-) diff --git a/cmd/proxy/app/proxy.go b/cmd/proxy/app/proxy.go index e5a1c541..bfc55518 100644 --- a/cmd/proxy/app/proxy.go +++ b/cmd/proxy/app/proxy.go @@ -26,7 +26,6 @@ import ( "errors" "fmt" "io/fs" - _ "net/http/pprof" "os" "os/exec" "path/filepath" diff --git a/cmd/proxy/stats/htmltmpl.go b/cmd/proxy/stats/htmltmpl.go index 46433988..50c47863 100644 --- a/cmd/proxy/stats/htmltmpl.go +++ b/cmd/proxy/stats/htmltmpl.go @@ -18,54 +18,3 @@ // package stats - -import ( - "fmt" - "html/template" - "os" - - "juno/pkg/stats" -) - -var ( - pprofIndexTmpl *template.Template - pprofIndexMainTmpl *template.Template -) - -func initPprofIndexTemplate() { - queryString := "" - workerInfo := "" - - if workerIdString != "" { - queryString = "&" + "wid=" + workerIdString - workerInfo = "worker: " + workerIdString + "," - } - workerInfo += fmt.Sprintf(" pid: %d", os.Getpid()) - - mainSect := fmt.Sprintf(` -/debug/pprof/      (%s) -
-
-profiles:
- -{{range .}} -
{{.Count}}{{.Name}} -{{end}} -
-
-full goroutine stack dump
-`, workerInfo, queryString, queryString) - - page := fmt.Sprintf(` - -/debug/pprof/ -`+stats.HtmlElemScript(stats.KScriptHrefClickWithElemPath)+` - - -%s - - -`, mainSect) - pprofIndexTmpl = template.Must(template.New("pprofindex").Parse(page)) - pprofIndexMainTmpl = template.Must(template.New("pprofindexMain").Parse(mainSect)) -} diff --git a/cmd/proxy/stats/httphandler.go b/cmd/proxy/stats/httphandler.go index beb97db9..46637934 100644 --- a/cmd/proxy/stats/httphandler.go +++ b/cmd/proxy/stats/httphandler.go @@ -22,9 +22,6 @@ package stats import ( "fmt" "net/http" - "net/http/pprof" - rpprof "runtime/pprof" - "strings" //"juno/third_party/forked/golang/glog" "github.com/BurntSushi/toml" @@ -96,25 +93,6 @@ func debugShardManagerStatsHandler(w http.ResponseWriter, r *http.Request) { } } -func debugPprofHandler(w http.ResponseWriter, r *http.Request) { - if strings.HasPrefix(r.URL.Path, "/debug/pprof/") { - name := strings.TrimPrefix(r.URL.Path, "/debug/pprof/") - if name != "" { - pprof.Handler(name).ServeHTTP(w, r) - return - } - } - - profiles := rpprof.Profiles() - tmpl := pprofIndexTmpl - if r.URL.Query().Get(kQueryElemKey) == kQueryElemValueMain { - tmpl = pprofIndexMainTmpl - } - if err := tmpl.Execute(w, profiles); err != nil { - fmt.Fprint(w, err) - } -} - func initStatsForWorker(workerId int) { htmlShardMgrStats.AddSection(&htmlSectShardMgrStatsT{}) @@ -134,15 +112,10 @@ func initStatsForWorker(workerId int) { htmlstats.AddSection(&htmlSectClientStatsT{}) workerIdString = fmt.Sprintf("%d", workerId) - initPprofIndexTemplate() HttpServerMux.HandleFunc("/", indexHandler) addPage("/stats", httpStatsHandler) - addPage("/debug/pprof/", debugPprofHandler) addPage("/debug/shardmgr", debugShardManagerStatsHandler) addPage("/debug/config", debugConfigHandler) - addPage("/debug/pprof/profile", pprof.Profile) - addPage("/debug/pprof/symbol", pprof.Symbol) - addPage("/debug/pprof/trace", pprof.Trace) } diff --git a/cmd/proxy/stats/monhandler.go b/cmd/proxy/stats/monhandler.go index e649e78c..692ebec9 100644 --- a/cmd/proxy/stats/monhandler.go +++ b/cmd/proxy/stats/monhandler.go @@ -104,7 +104,6 @@ func (h *HandlerForMonitor) ListenAndServe(addr string) error { HttpServerMux.HandleFunc("/", h.httpHandler) HttpServerMux.HandleFunc("/stats/json", h.httpJsonStatsHandler) HttpServerMux.HandleFunc("/stats/text", h.httpTextStatsHandler) - HttpServerMux.HandleFunc("/debug/pprof/", h.debugPprofHandler) HttpServerMux.HandleFunc("/version", version.HttpHandler) HttpServerMux.HandleFunc("/cluster/", h.httpClusterConsoleHandler) @@ -170,21 +169,6 @@ func (h *HandlerForMonitor) getFromWorkerWithWorkerIdByPost(r *http.Request, wor return } -func (h *HandlerForMonitor) debugPprofHandler(w http.ResponseWriter, r *http.Request) { - values := r.URL.Query() - if len(values) != 0 { - if values.Get("wid") != "" { - if body, err := h.getFromWorker(r.URL.Path, values); err == nil { - w.Write(body) - } else { - glog.Errorln(err) - } - return - } - } - debugPprofHandler(w, r) -} - func (h *HandlerForMonitor) httpJsonStatsHandler(w http.ResponseWriter, r *http.Request) { var indent bool workerId := "" diff --git a/cmd/storageserv/app/storageserv.go b/cmd/storageserv/app/storageserv.go index 2c6a4592..11d8ac57 100644 --- a/cmd/storageserv/app/storageserv.go +++ b/cmd/storageserv/app/storageserv.go @@ -22,7 +22,6 @@ package app import ( "flag" "fmt" - _ "net/http/pprof" "os" "path/filepath" "strings" diff --git a/cmd/storageserv/stats/htmltmpl.go b/cmd/storageserv/stats/htmltmpl.go index f426bf9b..5fbe57ed 100644 --- a/cmd/storageserv/stats/htmltmpl.go +++ b/cmd/storageserv/stats/htmltmpl.go @@ -22,7 +22,6 @@ package stats import ( "fmt" "html/template" - "os" "juno/pkg/stats" ) @@ -74,10 +73,8 @@ var ( "is-write-stopped", } - dbIndexTmpl *template.Template - dbIndexMainTmpl *template.Template - pprofIndexTmpl *template.Template - pprofIndexMainTmpl *template.Template + dbIndexTmpl *template.Template + dbIndexMainTmpl *template.Template ) func initDbIndexTemplate(workerId string) { @@ -118,40 +115,3 @@ DB properties:
? - %3F */ -func initPprofIndexTemplate(workerId string) { - queryString := "" - workerInfo := "" - - if workerId != "" { - queryString = "&" + "wid=" + workerId - workerInfo = "worker: " + workerId + "," - } - workerInfo += fmt.Sprintf(" pid: %d", os.Getpid()) - - main := fmt.Sprintf(` -/debug/pprof/      (%s) -
-
-profiles:
- -{{range .}} -
{{.Count}}{{.Name}} -{{end}} -
-
-full goroutine stack dump
-`, workerInfo, queryString, queryString) - - page := fmt.Sprintf(` - -pprof -`+stats.HtmlElemScript(stats.KScriptHrefClickWithElemPath)+` - - -%s - - -`, main) - pprofIndexTmpl = template.Must(template.New("pprofindex").Parse(page)) - pprofIndexMainTmpl = template.Must(template.New("pprofindexmain").Parse(main)) -} diff --git a/cmd/storageserv/stats/httphandler.go b/cmd/storageserv/stats/httphandler.go index 144ca4f0..e4b1608a 100644 --- a/cmd/storageserv/stats/httphandler.go +++ b/cmd/storageserv/stats/httphandler.go @@ -22,11 +22,6 @@ package stats import ( "fmt" "net/http" - "net/http/pprof" - rpprof "runtime/pprof" - "strings" - - "juno/third_party/forked/golang/glog" "github.com/BurntSushi/toml" @@ -112,25 +107,6 @@ func httpDebugDbStatsHandler(w http.ResponseWriter, r *http.Request) { } } -func debugPprofHandler(w http.ResponseWriter, r *http.Request) { - if strings.HasPrefix(r.URL.Path, "/debug/pprof/") { - name := strings.TrimPrefix(r.URL.Path, "/debug/pprof/") - if name != "" { - pprof.Handler(name).ServeHTTP(w, r) - return - } - } - - profiles := rpprof.Profiles() - tmpl := pprofIndexTmpl - if r.URL.Query().Get(kQueryElemKey) == kQueryElemValueMain { - tmpl = pprofIndexMainTmpl - } - if err := tmpl.Execute(w, profiles); err != nil { - glog.Error(err) - } -} - func debugMemStatsHandler(w http.ResponseWriter, r *http.Request) { db.WriteSliceTrackerStats(w) } diff --git a/cmd/storageserv/stats/monhandler.go b/cmd/storageserv/stats/monhandler.go index 1742003c..d965aa1b 100644 --- a/cmd/storageserv/stats/monhandler.go +++ b/cmd/storageserv/stats/monhandler.go @@ -93,25 +93,9 @@ func (h *HttpHandlerForMonitor) Init(isChild bool, addrs []string) { HttpServerMux.HandleFunc("/", h.httpHandler) HttpServerMux.HandleFunc("/stats/json", h.httpJsonStatsHandler) HttpServerMux.HandleFunc("/stats/text", h.httpTextStatsHandler) - // HttpServerMux.HandleFunc("/debug/pprof/", h.debugPprofHandler) HttpServerMux.HandleFunc("/version", version.HttpHandler) } -func (h *HttpHandlerForMonitor) debugPprofHandler(w http.ResponseWriter, r *http.Request) { - values := r.URL.Query() - if len(values) != 0 { - if values.Get("wid") != "" { - if body, err := h.getFromWorker(r.URL.Path, values); err == nil { - w.Write(body) - } else { - glog.Errorln(err) - } - return - } - } - debugPprofHandler(w, r) -} - func (c *HttpHandlerForMonitor) getFromWorkerWithWorkerId(urlPath string, query url.Values, workerId int) (body []byte, err error) { if workerId >= c.GetNumWorkers() { err = fmt.Errorf("invalid worker id %d. should < %d ", workerId, c.GetNumWorkers()) diff --git a/cmd/storageserv/stats/statsinit.go b/cmd/storageserv/stats/statsinit.go index 208d853d..d1e2ed95 100644 --- a/cmd/storageserv/stats/statsinit.go +++ b/cmd/storageserv/stats/statsinit.go @@ -21,7 +21,6 @@ package stats import ( "fmt" - "net/http/pprof" "juno/third_party/forked/golang/glog" @@ -53,16 +52,11 @@ func initForWorker(isChild bool, workerId int, zoneId uint32, machineIndex uint3 HttpServerMux.HandleFunc("/", indexHandler) initDbIndexTemplate(workerIdString) - initPprofIndexTemplate(workerIdString) addPage("/stats", httpStatsHandler) - addPage("/debug/pprof/", debugPprofHandler) addPage("/debug/dbstats/", httpDebugDbStatsHandler) addPage("/debug/config", debugConfigHandler) - addPage("/debug/pprof/profile", pprof.Profile) - addPage("/debug/pprof/symbol", pprof.Symbol) - addPage("/debug/pprof/trace", pprof.Trace) if debug.DEBUG { addPage("/debug/memstats", debugMemStatsHandler) diff --git a/pkg/logging/cal/test/main.go b/pkg/logging/cal/test/main.go index ac57efdf..9d107065 100644 --- a/pkg/logging/cal/test/main.go +++ b/pkg/logging/cal/test/main.go @@ -37,9 +37,7 @@ import ( //"juno/pkg/logging/cal/net/protocol" //"os" // "runtime" - //"runtime/pprof" // "net/http" - // _ "net/http/pprof" "sync" "time" ) @@ -130,16 +128,7 @@ func main() { // go func() { // http.ListenAndServe("localhost:6060", nil) // }() - // if *cpuprofile != "" { - // f, err := os.Create(*cpuprofile) - // if err != nil { - // log.Fatal("could not create CPU profile: ", err) - // } - // if err := pprof.StartCPUProfile(f); err != nil { - // log.Fatal("could not start CPU profile: ", err) - // } - // defer pprof.StopCPUProfile() - // } + //config.FileName = string(*configFile) if *logType == 1 { //startCalLogger(*numGoRoutine, *numOfOperation) @@ -148,16 +137,5 @@ func main() { startGLogger(*numGoRoutine, *numOfOperation, *logLevel) } - // if *memprofile != "" { - // f, err := os.Create(*memprofile) - // if err != nil { - // log.Fatal("could not create memory profile: ", err) - // } - // runtime.GC() // get up-to-date statistics - // if err := pprof.WriteHeapProfile(f); err != nil { - // log.Fatal("could not write memory profile: ", err) - // } - // f.Close() - // } //time.Sleep(100000000000) } diff --git a/test/drv/junoload/junoload.go b/test/drv/junoload/junoload.go index 850ff48e..9297f651 100644 --- a/test/drv/junoload/junoload.go +++ b/test/drv/junoload/junoload.go @@ -24,7 +24,6 @@ import ( "fmt" "math/rand" "net/http" - _ "net/http/pprof" "os" "strings" "sync" diff --git a/test/functest/setup_test.go b/test/functest/setup_test.go index 10d47dae..e5244527 100644 --- a/test/functest/setup_test.go +++ b/test/functest/setup_test.go @@ -23,7 +23,6 @@ import ( "flag" "fmt" "net/http" - _ "net/http/pprof" "os" "os/signal" "strings" From 33a67b51ef23028c61d7a9e6f855803781220172 Mon Sep 17 00:00:00 2001 From: nepathak Date: Thu, 11 May 2023 13:23:32 -0700 Subject: [PATCH 8/9] Update missing ! for an if condition in file - cmd/storageserv/storage/db/dbcopy/main.go --- cmd/storageserv/storage/db/dbcopy/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/storageserv/storage/db/dbcopy/main.go b/cmd/storageserv/storage/db/dbcopy/main.go index 80c06928..d0a767db 100644 --- a/cmd/storageserv/storage/db/dbcopy/main.go +++ b/cmd/storageserv/storage/db/dbcopy/main.go @@ -207,7 +207,7 @@ func main() { newDir := fmt.Sprintf("%s/dbcopy_%s", filepath.Dir(dbPath), filepath.Base(dbPath)) if len(tgtPath) > 0 { _, err := os.Stat(newDir) - if errors.Is(err, fs.ErrNotExist) { + if !errors.Is(err, fs.ErrNotExist) { glog.Exitf("[ERROR] %s from last dbcopy was left over.", newDir) } } From 945fb8bbd0d5c9a19a3cb2b6ee8e0d7aec0be7b4 Mon Sep 17 00:00:00 2001 From: nepathak Date: Thu, 11 May 2023 13:43:31 -0700 Subject: [PATCH 9/9] Update missing ! for an if condition in file - cmd/storageserv/storage/db/dbcopy/config.go --- cmd/storageserv/storage/db/dbcopy/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/storageserv/storage/db/dbcopy/config.go b/cmd/storageserv/storage/db/dbcopy/config.go index be179719..a1834ee4 100644 --- a/cmd/storageserv/storage/db/dbcopy/config.go +++ b/cmd/storageserv/storage/db/dbcopy/config.go @@ -74,7 +74,7 @@ func LoadConfig(file string) string { if !cfg.MicroShardsEnabled { tagFile := fmt.Sprintf("%s/microshard_enabled.txt", dbPath) _, err := os.Stat(tagFile) - if errors.Is(err, fs.ErrNotExist) { + if !errors.Is(err, fs.ErrNotExist) { // db was converted by dbcopy tool. cfg.MicroShardsEnabled = true cfg.NumMicroShards = 256