Skip to content

Commit

Permalink
Merge pull request #88 from paypal/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
NeetishPathak authored May 11, 2023
2 parents ae98769 + 945fb8b commit 6a5b624
Show file tree
Hide file tree
Showing 36 changed files with 92 additions and 289 deletions.
4 changes: 3 additions & 1 deletion cmd/clustermgr/clusterctl/clusterctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package main

import (
"errors"
"flag"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/clustermgr/clustermgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
package main

import (
"errors"
"flag"
"fmt"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/dbscanserv/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/dbscanserv/app/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/rpc"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cmd/proxy/app/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Juno Proxy Server
package app

import (
"errors"
"fmt"
_ "net/http/pprof"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -95,7 +96,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 + "] "
Expand Down
9 changes: 5 additions & 4 deletions cmd/proxy/app/proxymgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package app

import (
"errors"
"fmt"
"io/ioutil"
"io/fs"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -80,7 +81,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)
}
Expand Down Expand Up @@ -113,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 {
Expand All @@ -123,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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/proxy/proc/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 0 additions & 51 deletions cmd/proxy/stats/htmltmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<br>
<br>
profiles:<br>
<table>
{{range .}}
<tr><td align=right>{{.Count}}<td><a href="/{{.Name}}?debug=1%s">{{.Name}}</a>
{{end}}
</table>
<br>
<a href="goroutine?debug=2%s">full goroutine stack dump</a><br>
`, workerInfo, queryString, queryString)

page := fmt.Sprintf(`<html>
<head>
<title>/debug/pprof/</title>
`+stats.HtmlElemScript(stats.KScriptHrefClickWithElemPath)+`
</head>
<body>
%s
</body>
</html>
`, mainSect)
pprofIndexTmpl = template.Must(template.New("pprofindex").Parse(page))
pprofIndexMainTmpl = template.Must(template.New("pprofindexMain").Parse(mainSect))
}
27 changes: 0 additions & 27 deletions cmd/proxy/stats/httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand All @@ -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)
}
22 changes: 3 additions & 19 deletions cmd/proxy/stats/monhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -162,29 +161,14 @@ 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)
}
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 := ""
Expand Down Expand Up @@ -237,7 +221,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)
Expand Down
4 changes: 3 additions & 1 deletion cmd/proxy/stats/statslogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package stats

import (
"bytes"
"errors"
"fmt"
goio "io"
"io/fs"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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)
}
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/storageserv/app/ssmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
package app

import (
"errors"
"fmt"
"io/fs"
"net"
"os"

Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/storageserv/app/storagemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package app

import (
"errors"
"fmt"
"io/ioutil"
"io/fs"
"math"
"net"
"os"
Expand Down Expand Up @@ -119,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 {
Expand All @@ -134,12 +135,12 @@ 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.")
}
}

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()

Expand Down
1 change: 0 additions & 1 deletion cmd/storageserv/app/storageserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package app
import (
"flag"
"fmt"
_ "net/http/pprof"
"os"
"path/filepath"
"strings"
Expand Down
Loading

0 comments on commit 6a5b624

Please sign in to comment.