Skip to content

Commit

Permalink
use fixed size arrays (ref)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jul 18, 2024
1 parent a2d04da commit 2c7b1d9
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 48 deletions.
6 changes: 3 additions & 3 deletions ais/htcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ type (
}
)

var allHTTPverbs = []string{
var htverbs = [...]string{
http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch,
http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace,
}
Expand Down Expand Up @@ -621,8 +621,8 @@ func (server *netServer) shutdown(config *cmn.Config) {
var _ http.Handler = (*httpMuxers)(nil)

func newMuxers() httpMuxers {
m := make(httpMuxers, len(allHTTPverbs))
for _, v := range allHTTPverbs {
m := make(httpMuxers, len(htverbs))
for _, v := range htverbs {
m[v] = mux.NewServeMux()
}
return m
Expand Down
6 changes: 3 additions & 3 deletions ais/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type global struct {
var g global

func handlePub(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
for _, v := range htverbs {
g.netServ.pub.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.pub.muxers[v].HandleFunc(path+"/", handler)
Expand All @@ -36,7 +36,7 @@ func handlePub(path string, handler func(http.ResponseWriter, *http.Request)) {
}

func handleControl(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
for _, v := range htverbs {
g.netServ.control.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.control.muxers[v].HandleFunc(path+"/", handler)
Expand All @@ -45,7 +45,7 @@ func handleControl(path string, handler func(http.ResponseWriter, *http.Request)
}

func handleData(path string, handler func(http.ResponseWriter, *http.Request)) {
for _, v := range allHTTPverbs {
for _, v := range htverbs {
g.netServ.data.muxers[v].HandleFunc(path, handler)
if !cos.IsLastB(path, '/') {
g.netServ.data.muxers[v].HandleFunc(path+"/", handler)
Expand Down
12 changes: 5 additions & 7 deletions api/apc/compression.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// Package apc: API control messages and constants
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package apc

import (
"github.com/NVIDIA/aistore/cmn/cos"
)

// NOTE:
// LZ4 block and frame formats: http://fastcompression.blogspot.com/2013/04/lz4-streaming-format-final.html

Expand All @@ -21,6 +17,8 @@ const (
// (alternative to lz4 compressions upon popular request)
const LZ4Compression = "lz4"

var SupportedCompression = []string{CompressNever, CompressAlways}
var SupportedCompression = [...]string{CompressNever, CompressAlways}

func IsValidCompression(c string) bool { return c == "" || cos.StringInSlice(c, SupportedCompression) }
func IsValidCompression(c string) bool {
return c == "" || c == SupportedCompression[0] || c == SupportedCompression[1]
}
4 changes: 2 additions & 2 deletions api/apc/write_policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package apc: API control messages and constants
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package apc

Expand All @@ -18,7 +18,7 @@ const (
WriteDefault = WritePolicy("") // same as `WriteImmediate` - see IsImmediate() below
)

var SupportedWritePolicy = []string{string(WriteImmediate), string(WriteDelayed), string(WriteNever)}
var SupportedWritePolicy = [...]string{string(WriteImmediate), string(WriteDelayed), string(WriteNever)}

func (wp WritePolicy) IsImmediate() bool { return wp == WriteDefault || wp == WriteImmediate }

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/cli/dsort.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var dsortStartCmd = cli.Command{
Action: startDsortHandler,
}

var phasesOrdered = []string{
var phasesOrdered = [...]string{
dsort.ExtractionPhase,
dsort.SortingPhase,
dsort.CreationPhase,
Expand Down
19 changes: 11 additions & 8 deletions cmd/cli/cli/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type (
metrics cos.StrKVs, mapBegin, mapEnd teb.StstMap, elapsed time.Duration) bool
)

// _statically_ defined for `latency` table (compare with counter and throughput tabs)
var selectedLatency = []string{
stats.GetLatency, stats.GetSize, stats.GetCount, stats.GetColdCount, stats.GetColdSize, stats.GetRedirLatency, stats.GetColdRwLatency,
stats.PutLatency, stats.PutSize, stats.PutCount, stats.PutRedirLatency,
stats.AppendLatency, stats.AppendCount,
// _statically_ defined addition for the `latency` table (compare with counter and throughput tabs)
var addLatencyTab = []string{
stats.GetSize, stats.GetCount, stats.GetColdCount, stats.GetColdSize,
stats.PutSize, stats.PutCount,
stats.AppendCount,
}

// true when called by top-level handler
Expand Down Expand Up @@ -243,11 +243,14 @@ func showLatencyHandler(c *cli.Context) error {
_warnThruLatIters(c)

// statically filter metrics (names)
selected := make(cos.StrKVs, len(selectedLatency))
selected := make(cos.StrKVs, 20)
for name, kind := range metrics {
if cos.StringInSlice(name, selectedLatency) {
switch {
case cos.StringInSlice(name, addLatencyTab):
selected[name] = kind
case strings.HasSuffix(name, ".ns") && name != stats.Uptime: // NOTE: not including and not handling "*.ns.total"
selected[name] = kind
} else if stats.IsErrMetric(name) {
case stats.IsErrMetric(name):
if strings.Contains(name, "get") || strings.Contains(name, "put") || strings.Contains(name, "append") {
selected[name] = kind
}
Expand Down
4 changes: 2 additions & 2 deletions cmn/archive/mime.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package archive: write, read, copy, append, list primitives
// across all supported formats
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package archive

Expand Down Expand Up @@ -47,7 +47,7 @@ type detect struct {
offset int
}

var FileExtensions = []string{ExtTar, ExtTgz, ExtTarGz, ExtZip, ExtTarLz4}
var FileExtensions = [...]string{ExtTar, ExtTgz, ExtTarGz, ExtZip, ExtTarLz4}

// standard file signatures
var (
Expand Down
10 changes: 6 additions & 4 deletions cmn/archive/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
_wdskey
)

var MatchMode = []string{
var MatchMode = [...]string{
"regexp",
"prefix",
"suffix",
Expand Down Expand Up @@ -379,8 +379,10 @@ func ValidateMatchMode(mmode string) (_ string, err error) {
if cos.MatchAll(mmode) {
return MatchMode[_prefix], nil
}
if !cos.StringInSlice(mmode, MatchMode) {
err = &ErrMatchMode{mmode}
for i := range MatchMode {
if MatchMode[i] == mmode {
return mmode, nil
}
}
return mmode, err
return "", &ErrMatchMode{mmode}
}
2 changes: 1 addition & 1 deletion cmn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ type (
)

// assorted named fields that require (cluster | node) restart for changes to make an effect
var ConfigRestartRequired = []string{"auth", "memsys", "net"}
var ConfigRestartRequired = [...]string{"auth", "memsys", "net"}

// dsort
const (
Expand Down
4 changes: 2 additions & 2 deletions cmn/cos/log_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package cos provides common low-level types and utilities for all aistore projects.
/*
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved.
*/
package cos

Expand Down Expand Up @@ -41,7 +41,7 @@ const (
const maxLevel = 5

// NOTE: keep in-sync with the above
var Smodules = []string{
var Smodules = [...]string{
"transport", "ais", "memsys", "cluster", "fs", "reb", "ec", "stats",
"ios", "xs", "backend", "space", "mirror", "dsort", "downloader", "etl",
"s3",
Expand Down
4 changes: 2 additions & 2 deletions cmn/cos/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
TB = 1000 * GB
)

var suffX = []string{"KIB", "MIB", "GIB", "TIB", "KB", "MB", "GB", "TB", "K", "M", "G", "T", "B"}
var unitx = [...]string{"KIB", "MIB", "GIB", "TIB", "KB", "MB", "GB", "TB", "K", "M", "G", "T", "B"}

/////////////
// SizeIEC //
Expand Down Expand Up @@ -130,7 +130,7 @@ func ParseSize(size, units string) (int64, error) {
}

func _suffix(s string) string {
for _, suffix := range suffX {
for _, suffix := range unitx {
if strings.HasSuffix(s, suffix) {
return suffix
}
Expand Down
13 changes: 10 additions & 3 deletions cmn/feat/feat.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
S3UsePathStyle // use older path-style addressing (as opposed to virtual-hosted style), e.g., https://s3.amazonaws.com/BUCKET/KEY
)

var Cluster = []string{
var Cluster = [...]string{
"Enforce-IntraCluster-Access",
"Skip-Loading-VersionChecksum-MD",
"Do-not-Auto-Detect-FileShare",
Expand All @@ -59,7 +59,7 @@ var Cluster = []string{
// "none" ====================
}

var Bucket = []string{
var Bucket = [...]string{
"Skip-Loading-VersionChecksum-MD",
"Fsync-PUT",
"S3-Presigned-Request",
Expand All @@ -73,7 +73,14 @@ func (f Flags) IsSet(flag Flags) bool { return cos.BitFlags(f).IsSet(cos.BitFlag
func (f Flags) Set(flags Flags) Flags { return Flags(cos.BitFlags(f).Set(cos.BitFlags(flags))) }
func (f Flags) String() string { return strconv.FormatUint(uint64(f), 10) }

func IsBucketScope(name string) bool { return cos.StringInSlice(name, Bucket) }
func IsBucketScope(name string) bool {
for i := range Bucket {
if name == Bucket[i] {
return true
}
}
return false
}

func CSV2Feat(s string) (Flags, error) {
if s == "" || s == "none" {
Expand Down
4 changes: 2 additions & 2 deletions cmn/network.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package cmn provides common constants, types, and utilities for AIS clients
// and AIStore.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package cmn

Expand Down Expand Up @@ -36,7 +36,7 @@ const (
DefaultSendRecvBufferSize = 128 * cos.KiB
)

var KnownNetworks = []string{NetPublic, NetIntraControl, NetIntraData}
var KnownNetworks = [...]string{NetPublic, NetIntraControl, NetIntraData}

func NetworkIsKnown(net string) bool {
return net == NetPublic || net == NetIntraControl || net == NetIntraData
Expand Down
3 changes: 2 additions & 1 deletion fs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
DiskHighWM = "(low-free-space)" // (capacity)
)

var alerts = [...]string{DiskFault, DiskOOS, Disk2Disable, Disk2Detach, DiskHighWM}

// !available mountpath // TODO: not yet used; readability
const (
DiskDisabled = "(mp-disabled)"
Expand Down Expand Up @@ -89,7 +91,6 @@ func (tcdf *TargetCDF) HasAlerts() bool {
// [convention] <DISK-NAME>[(<alert>)]
// Returns "" and (-1) when no alerts found otherwise, returns alert name and its index in the DISK-NAME string
func HasAlert(disks []string) (alert string, idx int) {
var alerts = []string{DiskFault, DiskOOS, Disk2Disable, Disk2Detach, DiskHighWM}
for _, disk := range disks {
for _, a := range alerts {
if idx = strings.Index(disk, a); idx > 0 {
Expand Down
7 changes: 3 additions & 4 deletions fs/persistent_md.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package fs provides mountpath and FQN abstractions and methods to resolve/map stored content
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package fs

Expand All @@ -18,15 +18,14 @@ import (
"github.com/NVIDIA/aistore/memsys"
)

// NOTE: tunable
const numMarkers = 1

// List of AIS metadata files and directories (basenames only)
var mdFilesDirs = []string{
var mdFilesDirs = [...]string{
fname.MarkersDir,

fname.Bmd,
fname.BmdPrevious,

fname.Vmd,
}

Expand Down
6 changes: 3 additions & 3 deletions stats/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ type (
)

// sample name ais.ip-10-0-2-19.root.log.INFO.20180404-031540.2249
var logtypes = []string{".INFO.", ".WARNING.", ".ERROR."}
var logtypes = [...]string{".INFO.", ".WARNING.", ".ERROR."}

var ignoreIdle = []string{"kalive", Uptime, "disk."}
var ignoreIdle = [...]string{"kalive", Uptime, "disk."}

var softErrNames = []string{errPrefix + GetCount, errPrefix + PutCount, errPrefix + DeleteCount, errPrefix + RenameCount}
var softErrNames = [...]string{errPrefix + GetCount, errPrefix + PutCount, errPrefix + DeleteCount, errPrefix + RenameCount}

////////////
// runner //
Expand Down

0 comments on commit 2c7b1d9

Please sign in to comment.