[#772] node: Apply gofumpt

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-10-31 14:56:55 +03:00
parent 00aa6d9749
commit 79088baa06
136 changed files with 293 additions and 239 deletions

View file

@ -50,12 +50,12 @@ func initConfig(cmd *cobra.Command, _ []string) error {
}
pathDir := filepath.Dir(configPath)
err = os.MkdirAll(pathDir, 0700)
err = os.MkdirAll(pathDir, 0o700)
if err != nil {
return fmt.Errorf("create dir %s: %w", pathDir, err)
}
f, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0600)
f, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0o600)
if err != nil {
return fmt.Errorf("open %s: %w", configPath, err)
}

View file

@ -76,7 +76,7 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
}
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
f, err := os.OpenFile(p, os.O_CREATE, 0644)
f, err := os.OpenFile(p, os.O_CREATE, 0o644)
if err != nil {
return nil, fmt.Errorf("can't create wallet file: %w", err)
}

View file

@ -83,7 +83,7 @@ func newLocalClient(cmd *cobra.Command, v *viper.Viper, wallets []*wallet.Wallet
go bc.Run()
if cmd.Name() != "init" {
f, err := os.OpenFile(dumpPath, os.O_RDONLY, 0600)
f, err := os.OpenFile(dumpPath, os.O_RDONLY, 0o600)
if err != nil {
return nil, fmt.Errorf("can't open local dump: %w", err)
}

View file

@ -15,16 +15,14 @@ import (
"github.com/spf13/viper"
)
var (
rootCmd = &cobra.Command{
Use: "frostfs-adm",
Short: "FrostFS Administrative Tool",
Long: `FrostFS Administrative Tool provides functions to setup and
var rootCmd = &cobra.Command{
Use: "frostfs-adm",
Short: "FrostFS Administrative Tool",
Long: `FrostFS Administrative Tool provides functions to setup and
manage FrostFS network deployment.`,
RunE: entryPoint,
SilenceUsage: true,
}
)
RunE: entryPoint,
SilenceUsage: true,
}
func init() {
cobra.OnInitialize(func() { initConfig(rootCmd) })

View file

@ -145,7 +145,7 @@ func storageConfig(cmd *cobra.Command, args []string) {
}
out := applyTemplate(c)
fatalOnErr(os.WriteFile(outPath, out, 0644))
fatalOnErr(os.WriteFile(outPath, out, 0o644))
cmd.Println("Node is ready for work! Run `frostfs-node -config " + outPath + "`")
}

View file

@ -106,7 +106,7 @@ func createEACL(cmd *cobra.Command, _ []string) {
return
}
err = os.WriteFile(outArg, buf.Bytes(), 0644)
err = os.WriteFile(outArg, buf.Bytes(), 0o644)
if err != nil {
cmd.PrintErrln(err)
os.Exit(1)

View file

@ -130,6 +130,6 @@ func createToken(cmd *cobra.Command, _ []string) {
}
out, _ := cmd.Flags().GetString(outFlag)
err = os.WriteFile(out, data, 0644)
err = os.WriteFile(out, data, 0o644)
commonCmd.ExitOnErr(cmd, "can't write token to file: %w", err)
}

View file

@ -51,7 +51,7 @@ var getContainerInfoCmd = &cobra.Command{
data = cnr.Marshal()
}
err = os.WriteFile(containerPathTo, data, 0644)
err = os.WriteFile(containerPathTo, data, 0o644)
commonCmd.ExitOnErr(cmd, "can't write container to file: %w", err)
}
},

View file

@ -52,7 +52,7 @@ var getExtendedACLCmd = &cobra.Command{
cmd.Println("dumping data to file:", containerPathTo)
err = os.WriteFile(containerPathTo, data, 0644)
err = os.WriteFile(containerPathTo, data, 0o644)
commonCmd.ExitOnErr(cmd, "could not write eACL to file: %w", err)
},
}

View file

@ -20,7 +20,7 @@ var containerNodesCmd = &cobra.Command{
Short: "Show nodes for container",
Long: "Show nodes taking part in a container at the current epoch.",
Run: func(cmd *cobra.Command, args []string) {
var cnr, pkey = getContainer(cmd)
cnr, pkey := getContainer(cmd)
if pkey == nil {
pkey = key.GetOrGenerate(cmd)

View file

@ -132,7 +132,7 @@ func createOutWriter(cmd *cobra.Command, filename string) (out io.Writer, closer
out = os.Stdout
closer = func() {}
} else {
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("can't open file '%s': %w", filename, err))
}

View file

@ -191,7 +191,7 @@ func getRequiredPlacement(cmd *cobra.Command, objInfo *objectNodesInfo, placemen
numOfReplicas := placementPolicy.ReplicaNumberByIndex(repIdx)
var nodeIdx uint32
for _, n := range rep {
if !objInfo.isLock && nodeIdx == numOfReplicas { //lock object should be on all container nodes
if !objInfo.isLock && nodeIdx == numOfReplicas { // lock object should be on all container nodes
break
}
nodes[n.Hash()] = n
@ -213,7 +213,8 @@ func getRequiredPlacement(cmd *cobra.Command, objInfo *objectNodesInfo, placemen
}
func getActualPlacement(cmd *cobra.Command, netmap *netmapSDK.NetMap, requiredPlacement map[uint64]netmapSDK.NodeInfo,
pk *ecdsa.PrivateKey, objInfo *objectNodesInfo) map[uint64]boolError {
pk *ecdsa.PrivateKey, objInfo *objectNodesInfo,
) map[uint64]boolError {
result := make(map[uint64]boolError)
resultMtx := &sync.Mutex{}

View file

@ -31,7 +31,8 @@ func init() {
objectHashCmd,
objectRangeCmd,
objectLockCmd,
objectNodesCmd}
objectNodesCmd,
}
Cmd.AddCommand(objectChildCommands...)

View file

@ -81,7 +81,7 @@ func createSession(cmd *cobra.Command, _ []string) {
}
filename, _ := cmd.Flags().GetString(outFlag)
err = os.WriteFile(filename, data, 0644)
err = os.WriteFile(filename, data, 0o644)
commonCmd.ExitOnErr(cmd, "can't write token to file: %w", err)
}

View file

@ -48,7 +48,7 @@ func convertEACLTable(cmd *cobra.Command, _ []string) {
return
}
err = os.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0o644)
commonCmd.ExitOnErr(cmd, "can't write exteded ACL table to file: %w", err)
cmd.Printf("extended ACL table was successfully dumped to %s\n", to)

View file

@ -78,7 +78,7 @@ func keyerGenerate(filename string, d *keyer.Dashboard) error {
}
if filename != "" {
return os.WriteFile(filename, key, 0600)
return os.WriteFile(filename, key, 0o600)
}
return nil

View file

@ -56,7 +56,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) {
return
}
err = os.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0o644)
commonCmd.ExitOnErr(cmd, "can't write signed bearer token to file: %w", err)
cmd.Printf("signed bearer token was successfully dumped to %s\n", to)

View file

@ -76,7 +76,7 @@ func signSessionToken(cmd *cobra.Command, _ []string) {
return
}
err = os.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0o644)
if err != nil {
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("can't write signed session token to %s: %w", to, err))
}

View file

@ -13,7 +13,7 @@ import (
func newConfig() (*viper.Viper, error) {
var err error
var dv = viper.New()
dv := viper.New()
defaultConfiguration(dv)

View file

@ -59,7 +59,7 @@ func WriteObjectToFile(cmd *cobra.Command, path string, data []byte) {
}
ExitOnErr(cmd, Errf("could not write file: %w",
os.WriteFile(path, data, 0644)))
os.WriteFile(path, data, 0o644)))
cmd.Printf("\nSaved payload to '%s' file\n", path)
}

View file

@ -22,7 +22,7 @@ func TestApiclientSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, 15*time.Second, apiclientconfig.DialTimeout(c))
require.Equal(t, 20*time.Second, apiclientconfig.StreamTimeout(c))
require.Equal(t, 30*time.Second, apiclientconfig.ReconnectTimeout(c))

View file

@ -38,7 +38,6 @@ func New(configFile, configDir, envPrefix string) *Config {
configViper.WithConfigFile(configFile),
configViper.WithConfigDir(configDir),
configViper.WithEnvPrefix(envPrefix))
if err != nil {
panic(err)
}

View file

@ -15,8 +15,8 @@ func TestConfigDir(t *testing.T) {
cfgFileName0 := path.Join(dir, "cfg_00.json")
cfgFileName1 := path.Join(dir, "cfg_01.yml")
require.NoError(t, os.WriteFile(cfgFileName0, []byte(`{"storage":{"shard_pool_size":15}}`), 0777))
require.NoError(t, os.WriteFile(cfgFileName1, []byte("logger:\n level: debug"), 0777))
require.NoError(t, os.WriteFile(cfgFileName0, []byte(`{"storage":{"shard_pool_size":15}}`), 0o777))
require.NoError(t, os.WriteFile(cfgFileName1, []byte("logger:\n level: debug"), 0o777))
c := New("", dir, "")
require.Equal(t, "debug", cast.ToString(c.Sub("logger").Value("level")))

View file

@ -35,7 +35,7 @@ func TestContractsSection(t *testing.T) {
expProxy, err := util.Uint160DecodeStringLE("ad7c6b55b737b696e5c82c85445040964a03e97f")
require.NoError(t, err)
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
balance := contractsconfig.Balance(c)
container := contractsconfig.Container(c)
netmap := contractsconfig.Netmap(c)

View file

@ -24,7 +24,7 @@ func TestControlSection(t *testing.T) {
pubs[0], _ = keys.NewPublicKeyFromString("035839e45d472a3b7769a2a1bd7d54c4ccd4943c3b40f547870e83a8fcbfb3ce11")
pubs[1], _ = keys.NewPublicKeyFromString("028f42cfcb74499d7b15b35d9bff260a1c8d27de4f446a627406a382d8961486d6")
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, pubs, controlconfig.AuthorizedKeys(c))
require.Equal(t, "localhost:8090", controlconfig.GRPC(c).Endpoint())
}

View file

@ -42,7 +42,7 @@ func TestEngineSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
num := 0
require.EqualValues(t, 100, engineconfig.ShardErrorThreshold(c))
@ -78,7 +78,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 3221225472, wc.SizeLimit())
require.Equal(t, "tmp/0/meta", meta.Path())
require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm())
require.Equal(t, fs.FileMode(0o644), meta.BoltDB().Perm())
require.Equal(t, 100, meta.BoltDB().MaxBatchSize())
require.Equal(t, 10*time.Millisecond, meta.BoltDB().MaxBatchDelay())
@ -89,7 +89,7 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, 2, len(ss))
blz := blobovniczaconfig.From((*config.Config)(ss[0]))
require.Equal(t, "tmp/0/blob/blobovnicza", ss[0].Path())
require.EqualValues(t, 0644, blz.BoltDB().Perm())
require.EqualValues(t, 0o644, blz.BoltDB().Perm())
require.EqualValues(t, 4194304, blz.Size())
require.EqualValues(t, 1, blz.ShallowDepth())
require.EqualValues(t, 4, blz.ShallowWidth())
@ -97,7 +97,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 10, blz.LeafWidth())
require.Equal(t, "tmp/0/blob", ss[1].Path())
require.EqualValues(t, 0644, ss[1].Perm())
require.EqualValues(t, 0o644, ss[1].Perm())
fst := fstreeconfig.From((*config.Config)(ss[1]))
require.EqualValues(t, 5, fst.Depth())
@ -112,7 +112,7 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, mode.ReadOnly, sc.Mode())
case 1:
require.Equal(t, "tmp/1/blob/pilorama.db", pl.Path())
require.Equal(t, fs.FileMode(0644), pl.Perm())
require.Equal(t, fs.FileMode(0o644), pl.Perm())
require.True(t, pl.NoSync())
require.Equal(t, 5*time.Millisecond, pl.MaxBatchDelay())
require.Equal(t, 100, pl.MaxBatchSize())
@ -127,7 +127,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 4294967296, wc.SizeLimit())
require.Equal(t, "tmp/1/meta", meta.Path())
require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm())
require.Equal(t, fs.FileMode(0o644), meta.BoltDB().Perm())
require.Equal(t, 200, meta.BoltDB().MaxBatchSize())
require.Equal(t, 20*time.Millisecond, meta.BoltDB().MaxBatchDelay())
@ -146,7 +146,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 10, blz.LeafWidth())
require.Equal(t, "tmp/1/blob", ss[1].Path())
require.EqualValues(t, 0644, ss[1].Perm())
require.EqualValues(t, 0o644, ss[1].Perm())
fst := fstreeconfig.From((*config.Config)(ss[1]))
require.EqualValues(t, 5, fst.Depth())

View file

@ -9,7 +9,7 @@ import (
type Config config.Config
// PermDefault are default permission bits for BlobStor data.
const PermDefault = 0660
const PermDefault = 0o660
func From(x *config.Config) *Config {
return (*Config)(x)

View file

@ -13,7 +13,7 @@ type Config config.Config
const (
// PermDefault is a default permission bits for metabase file.
PermDefault = 0660
PermDefault = 0o660
)
// Perm returns the value of "perm" config parameter as a fs.FileMode.

View file

@ -13,7 +13,7 @@ type Config config.Config
const (
// PermDefault is a default permission bits for metabase file.
PermDefault = 0660
PermDefault = 0o660
)
// From wraps config section into Config.

View file

@ -17,7 +17,7 @@ func TestGRPCSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
num := 0
IterateEndpoints(c, func(sc *Config) {

View file

@ -17,7 +17,7 @@ func TestLoggerSection_Level(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
v := loggerconfig.Level(c)
require.Equal(t, "debug", v)
}

View file

@ -22,7 +22,7 @@ func TestMetricsSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
to := metricsconfig.ShutdownTimeout(c)
addr := metricsconfig.Address(c)

View file

@ -23,14 +23,12 @@ func TestMorphSection(t *testing.T) {
const path = "../../../../config/example/node"
var (
rpcs = []client.Endpoint{
{"wss://rpc1.morph.frostfs.info:40341/ws", 1},
{"wss://rpc2.morph.frostfs.info:40341/ws", 2},
}
)
rpcs := []client.Endpoint{
{"wss://rpc1.morph.frostfs.info:40341/ws", 1},
{"wss://rpc2.morph.frostfs.info:40341/ws", 2},
}
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, rpcs, morphconfig.RPCEndpoint(c))
require.Equal(t, 30*time.Second, morphconfig.DialTimeout(c))
require.Equal(t, 15*time.Second, morphconfig.CacheTTL(c))

View file

@ -56,7 +56,7 @@ func TestNodeSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
key := Key(c)
addrs := BootstrapAddresses(c)
attributes := Attributes(c)

View file

@ -21,7 +21,7 @@ func TestObjectSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, 100, objectconfig.Put(c).PoolSizeRemote())
require.Equal(t, 200, objectconfig.Put(c).PoolSizeLocal())
require.EqualValues(t, 10, objectconfig.TombstoneLifetime(c))

View file

@ -19,7 +19,7 @@ func TestPolicerSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, 15*time.Second, policerconfig.HeadTimeout(c))
}

View file

@ -25,7 +25,7 @@ func TestProfilerSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
to := profilerconfig.ShutdownTimeout(c)
addr := profilerconfig.Address(c)

View file

@ -20,7 +20,7 @@ func TestReplicatorSection(t *testing.T) {
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
require.Equal(t, 15*time.Second, replicatorconfig.PutTimeout(c))
require.Equal(t, 10, replicatorconfig.PoolSize(c))
}

View file

@ -35,7 +35,7 @@ func TestTreeSection(t *testing.T) {
require.NoError(t, err)
expectedKeys = append(expectedKeys, key)
var fileConfigTest = func(c *config.Config) {
fileConfigTest := func(c *config.Config) {
treeSec := treeconfig.Tree(c)
require.True(t, treeSec.Enabled())

View file

@ -239,7 +239,8 @@ func listenMorphNotifications(ctx context.Context, c *cfg) {
}
func registerNotificationHandlers(scHash util.Uint160, lis event.Listener, parsers map[event.Type]event.NotificationParser,
subs map[event.Type][]event.Handler) {
subs map[event.Type][]event.Handler,
) {
for typ, handlers := range subs {
pi := event.NotificationParserInfo{}
pi.SetType(typ)

View file

@ -353,7 +353,8 @@ func createSearchSvcV2(sSearch *searchsvc.Service, keyStorage *util.KeyStorage)
}
func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator,
coreConstructor *cache.ClientCache) *getsvc.Service {
coreConstructor *cache.ClientCache,
) *getsvc.Service {
ls := c.cfgObject.cfgLocalStorage.localStorage
return getsvc.New(
@ -375,7 +376,8 @@ func createGetServiceV2(sGet *getsvc.Service, keyStorage *util.KeyStorage) *gets
}
func createDeleteService(c *cfg, keyStorage *util.KeyStorage, sGet *getsvc.Service,
sSearch *searchsvc.Service, sPut *putsvc.Service) *deletesvc.Service {
sSearch *searchsvc.Service, sPut *putsvc.Service,
) *deletesvc.Service {
return deletesvc.New(
sGet,
sSearch,
@ -396,7 +398,8 @@ func createDeleteServiceV2(sDelete *deletesvc.Service) *deletesvcV2.Service {
}
func createSplitService(c *cfg, sPutV2 *putsvcV2.Service, sGetV2 *getsvcV2.Service,
sSearchV2 *searchsvcV2.Service, sDeleteV2 *deletesvcV2.Service) *objectService.TransportSplitter {
sSearchV2 *searchsvcV2.Service, sDeleteV2 *deletesvcV2.Service,
) *objectService.TransportSplitter {
return objectService.NewTransportSplitter(
c.cfgGRPC.maxChunkSize,
c.cfgGRPC.maxAddrAmount,

View file

@ -23,7 +23,7 @@ func initTracing(ctx context.Context, c *cfg) {
fn: func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
err := tracing.Shutdown(ctx) //cfg context cancels before close
err := tracing.Shutdown(ctx) // cfg context cancels before close
if err != nil {
c.log.Error(logs.FrostFSNodeFailedShutdownTracing, zap.Error(err))
}

View file

@ -59,7 +59,7 @@ func validateConfig(c *config.Config) error {
default:
return fmt.Errorf("unexpected storage type: %s (shard %d)", blobstor[i].Type(), shardNum)
}
if blobstor[i].Perm()&0600 != 0600 {
if blobstor[i].Perm()&0o600 != 0o600 {
return fmt.Errorf("invalid permissions for blobstor component: %s, "+
"expected at least rw- for the owner (shard %d)",
blobstor[i].Perm(), shardNum)

View file

@ -10,7 +10,8 @@ import (
// PrettyPrintNodeInfo print information about network node with given indent and index.
// To avoid printing attribute list use short parameter.
func PrettyPrintNodeInfo(cmd *cobra.Command, node netmap.NodeInfo,
index int, indent string, short bool) {
index int, indent string, short bool,
) {
var strState string
switch {

View file

@ -22,7 +22,8 @@ func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
IterateAddresses(func(string) bool)
NumberOfAddresses() int
ExternalAddresses() []string
}) error {
},
) error {
var a network.AddressGroup
err := a.FromIterator(info)
@ -49,7 +50,8 @@ func NodeInfoFromNetmapElement(dst *NodeInfo, info interface {
PublicKey() []byte
Addresses() network.AddressGroup
ExternalAddresses() network.AddressGroup
}) {
},
) {
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses(), info.ExternalAddresses())
}

View file

@ -43,7 +43,8 @@ func (c SenderClassifier) Classify(
ownerID *user.ID,
ownerKey *keys.PublicKey,
idCnr cid.ID,
cnr container.Container) (res *ClassifyResult, err error) {
cnr container.Container,
) (res *ClassifyResult, err error) {
ownerKeyInBytes := ownerKey.Bytes()
// TODO: #767 get owner from frostfs.id if present
@ -114,7 +115,8 @@ func (c SenderClassifier) isInnerRingKey(owner []byte) (bool, error) {
func (c SenderClassifier) isContainerKey(
owner, idCnr []byte,
cnr container.Container) (bool, error) {
cnr container.Container,
) (bool, error) {
nm, err := core.GetLatestNetworkMap(c.netmap) // first check current netmap
if err != nil {
return false, err
@ -140,7 +142,8 @@ func (c SenderClassifier) isContainerKey(
func lookupKeyInContainer(
nm *netmap.NetMap,
owner, idCnr []byte,
cnr container.Container) (bool, error) {
cnr container.Container,
) (bool, error) {
cnrVectors, err := nm.ContainerNodes(cnr.PlacementPolicy(), idCnr)
if err != nil {
return false, err

View file

@ -117,6 +117,7 @@ type testEpochState struct {
func (s *testEpochState) EpochCounter() uint64 {
return s.counter
}
func (s *testEpochState) EpochDuration() uint64 {
return s.duration
}

View file

@ -60,5 +60,4 @@ fee:
require.Equal(t, fixedn.Fixed8(10), config.MainChainFee(), "main chain fee invalid")
require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid")
})
}

View file

@ -35,7 +35,8 @@ import (
func (s *Server) initNetmapProcessor(cfg *viper.Viper,
cnrClient *container.Client,
alphaSync event.Handler) error {
alphaSync event.Handler,
) error {
locodeValidator, err := s.newLocodeValidator(cfg)
if err != nil {
return err
@ -250,7 +251,8 @@ func (s *Server) initAlphabetProcessor(cfg *viper.Viper) error {
}
func (s *Server) initContainerProcessor(cfg *viper.Viper, cnrClient *container.Client,
frostfsIDClient *frostfsid.Client) error {
frostfsIDClient *frostfsid.Client,
) error {
// container processor
containerProcessor, err := cont.New(&cont.Params{
Log: s.log,

View file

@ -328,7 +328,8 @@ func (s *Server) registerStarter(f func() error) {
// New creates instance of inner ring sever structure.
func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error,
metrics *metrics.InnerRingServiceMetrics) (*Server, error) {
metrics *metrics.InnerRingServiceMetrics,
) (*Server, error) {
var err error
server := &Server{
log: log,

View file

@ -256,6 +256,7 @@ func (c *testMorphClient) Invoke(contract util.Uint160, fee fixedn.Fixed8, metho
})
return nil
}
func (c *testMorphClient) TransferGas(receiver util.Uint160, amount fixedn.Fixed8) error {
c.transferedGas = append(c.transferedGas, transferGas{
receiver: receiver,

View file

@ -73,8 +73,7 @@ func (s *testAlphabetState) IsAlphabet() bool {
return s.isAlphabet
}
type testPresicionConverter struct {
}
type testPresicionConverter struct{}
func (c *testPresicionConverter) ToFixed8(v int64) int64 {
return v

View file

@ -319,6 +319,7 @@ func (e *testPutEvent) Signature() []byte {
func (e *testPutEvent) SessionToken() []byte {
return e.st
}
func (e *testPutEvent) NotaryRequest() *payload.P2PNotaryRequest {
return e.nr
}

View file

@ -301,8 +301,7 @@ func (s *testAlphabetState) IsAlphabet() bool {
return s.isAlphabet
}
type testPrecisionConverter struct {
}
type testPrecisionConverter struct{}
func (c *testPrecisionConverter) ToBalancePrecision(v int64) int64 {
return v
@ -318,10 +317,12 @@ func (c *testBalaceClient) Mint(p balance.MintPrm) error {
c.mint = append(c.mint, p)
return nil
}
func (c *testBalaceClient) Lock(p balance.LockPrm) error {
c.lock = append(c.lock, p)
return nil
}
func (c *testBalaceClient) Burn(p balance.BurnPrm) error {
c.burn = append(c.burn, p)
return nil
@ -349,6 +350,7 @@ type testMorphClient struct {
func (c *testMorphClient) GasBalance() (res int64, err error) {
return c.balance, nil
}
func (c *testMorphClient) TransferGas(receiver util.Uint160, amount fixedn.Fixed8) error {
c.transferGas = append(c.transferGas, transferGas{
receiver: receiver,

View file

@ -205,7 +205,7 @@ func generateTestKeys(t *testing.T) testKeys {
require.NoError(t, err, "failed to create expected new alphabet")
if len(result.newAlphabetExp) == 0 {
continue //can be happen because of random and sort
continue // can be happen because of random and sort
}
var irKeys keys.PublicKeys

View file

@ -309,12 +309,15 @@ type testEpochState struct {
func (s *testEpochState) SetEpochCounter(c uint64) {
s.counter = c
}
func (s *testEpochState) EpochCounter() uint64 {
return s.counter
}
func (s *testEpochState) SetEpochDuration(d uint64) {
s.duration = d
}
func (s *testEpochState) EpochDuration() uint64 {
return s.duration
}

View file

@ -20,8 +20,7 @@ type DeletePrm struct {
}
// DeleteRes groups the resulting values of Delete operation.
type DeleteRes struct {
}
type DeleteRes struct{}
// SetAddress sets the address of the requested object.
func (p *DeletePrm) SetAddress(addr oid.Address) {

View file

@ -12,9 +12,7 @@ import (
// Exists check if object with the specified address is stored in b.
func (b *Blobovnicza) Exists(ctx context.Context, addr oid.Address) (bool, error) {
var (
exists = false
)
exists := false
_, span := tracing.StartSpanFromContext(ctx, "Blobovnicza.Exists",
trace.WithAttributes(

View file

@ -116,8 +116,7 @@ func (x *IteratePrm) IgnoreErrors() {
}
// IterateRes groups the resulting values of Iterate operation.
type IterateRes struct {
}
type IterateRes struct{}
// Iterate goes through all stored objects, and passes IterationElement to parameterized handler until error return.
//

View file

@ -20,8 +20,7 @@ type PutPrm struct {
}
// PutRes groups the resulting values of Put operation.
type PutRes struct {
}
type PutRes struct{}
// SetAddress sets the address of the saving object.
func (p *PutPrm) SetAddress(addr oid.Address) {

View file

@ -96,7 +96,7 @@ func (m *activeDBManager) getCurrentActiveIfOk(lvlPath string) (*activeDB, error
return nil, nil
}
blz, err := db.Open() //open db for usage, will be closed on activeDB.Close()
blz, err := db.Open() // open db for usage, will be closed on activeDB.Close()
if err != nil {
return nil, err
}
@ -156,7 +156,7 @@ func (m *activeDBManager) getNextSharedDB(lvlPath string) (*sharedDB, error) {
for iterCount < m.leafWidth {
path := filepath.Join(lvlPath, u64ToHexString(idx))
shDB := m.dbManager.GetByPath(path)
db, err := shDB.Open() //open db to hold active DB open, will be closed if db is full, after m.replace or by activeDBManager.Close()
db, err := shDB.Open() // open db to hold active DB open, will be closed if db is full, after m.replace or by activeDBManager.Close()
if err != nil {
return nil, err
}

View file

@ -80,7 +80,7 @@ func (c *dbCache) create(path string) *sharedDB {
value = c.dbManager.GetByPath(path)
_, err := value.Open() //open db to hold reference, closed by evictedDB.Close() or if cache closed
_, err := value.Open() // open db to hold reference, closed by evictedDB.Close() or if cache closed
if err != nil {
return value
}

View file

@ -40,14 +40,14 @@ func (b *Blobovniczas) Init() error {
}
func (b *Blobovniczas) openManagers() {
b.commondbManager.Open() //order important
b.commondbManager.Open() // order important
b.activeDBManager.Open()
b.dbCache.Open()
}
// Close implements common.Storage.
func (b *Blobovniczas) Close() error {
b.dbCache.Close() //order important
b.dbCache.Close() // order important
b.activeDBManager.Close()
b.commondbManager.Close()

View file

@ -55,7 +55,7 @@ func TestExistsInvalidStorageID(t *testing.T) {
// An invalid boltdb file is created so that it returns an error when opened
require.NoError(t, os.MkdirAll(filepath.Join(dir, relBadFileDir), os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(dir, relBadFileDir, badFileName), []byte("not a boltdb file content"), 0777))
require.NoError(t, os.WriteFile(filepath.Join(dir, relBadFileDir, badFileName), []byte("not a boltdb file content"), 0o777))
res, err := b.Exists(context.Background(), common.ExistsPrm{Address: addr, StorageID: []byte(filepath.Join(relBadFileDir, badFileName))})
require.Error(t, err)

View file

@ -28,7 +28,8 @@ type sharedDB struct {
}
func newSharedDB(options []blobovnicza.Option, path string, readOnly bool,
metrics blobovnicza.Metrics, openDBCounter *openDBCounter, closedFlag *atomic.Bool, log *logger.Logger) *sharedDB {
metrics blobovnicza.Metrics, openDBCounter *openDBCounter, closedFlag *atomic.Bool, log *logger.Logger,
) *sharedDB {
return &sharedDB{
guard: &sync.RWMutex{},
@ -110,7 +111,8 @@ type levelDbManager struct {
}
func newLevelDBManager(width uint64, options []blobovnicza.Option, rootPath string, lvlPath string,
readOnly bool, metrics blobovnicza.Metrics, openDBCounter *openDBCounter, closedFlog *atomic.Bool, log *logger.Logger) *levelDbManager {
readOnly bool, metrics blobovnicza.Metrics, openDBCounter *openDBCounter, closedFlog *atomic.Bool, log *logger.Logger,
) *levelDbManager {
result := &levelDbManager{
databases: make([]*sharedDB, width),
}

View file

@ -28,7 +28,7 @@ type cfg struct {
type Option func(*cfg)
const (
defaultPerm = 0700
defaultPerm = 0o700
defaultOpenedCacheSize = 50
defaultBlzShallowDepth = 2
defaultBlzShallowWidth = 16

View file

@ -77,7 +77,7 @@ var _ common.Storage = (*FSTree)(nil)
func New(opts ...Option) *FSTree {
f := &FSTree{
Info: Info{
Permissions: 0700,
Permissions: 0o700,
RootPath: "./",
},
Config: nil,

View file

@ -7,7 +7,6 @@ import (
)
func TestGeneric(t *testing.T) {
newMetabase := func(t *testing.T) storagetest.Component {
return New(
WithStorages(defaultStorages(t.TempDir(), 128)))

View file

@ -18,9 +18,7 @@ import (
// If the descriptor is present, only one sub-storage is tried,
// Otherwise, each sub-storage is tried in order.
func (b *BlobStor) Get(ctx context.Context, prm common.GetPrm) (res common.GetRes, err error) {
var (
startedAt = time.Now()
)
startedAt := time.Now()
defer func() {
b.metrics.Get(time.Since(startedAt), len(res.RawData), err == nil, prm.StorageID != nil)
}()

View file

@ -19,9 +19,7 @@ import (
// If the descriptor is present, only one sub-storage is tried,
// Otherwise, each sub-storage is tried in order.
func (b *BlobStor) GetRange(ctx context.Context, prm common.GetRangePrm) (res common.GetRangeRes, err error) {
var (
startedAt = time.Now()
)
startedAt := time.Now()
defer func() {
b.metrics.GetRange(time.Since(startedAt), len(res.Data), err == nil, prm.StorageID != nil)
}()

View file

@ -91,7 +91,7 @@ func runTestIgnoreLogicalErrors(t *testing.T, s common.Storage, objects []object
seen := make(map[string]objectDesc)
var n int
var logicErr = errors.New("logic error")
logicErr := errors.New("logic error")
var iterPrm common.IteratePrm
iterPrm.IgnoreErrors = true
iterPrm.Handler = func(elem common.IterationElement) error {

View file

@ -6,8 +6,10 @@ import (
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
const deleteOp = "DELETE"
const putOp = "PUT"
const (
deleteOp = "DELETE"
putOp = "PUT"
)
func logOp(l *logger.Logger, op string, addr oid.Address, typ string, sID []byte) {
storagelog.Write(l,

View file

@ -30,7 +30,7 @@ func (e *StorageEngine) open(ctx context.Context) error {
defer e.mtx.Unlock()
var wg sync.WaitGroup
var errCh = make(chan shardInitError, len(e.shards))
errCh := make(chan shardInitError, len(e.shards))
for id, sh := range e.shards {
wg.Add(1)
@ -75,7 +75,7 @@ func (e *StorageEngine) Init(ctx context.Context) error {
e.mtx.Lock()
defer e.mtx.Unlock()
var errCh = make(chan shardInitError, len(e.shards))
errCh := make(chan shardInitError, len(e.shards))
var eg errgroup.Group
if e.cfg.lowMem && e.anyShardRequiresRefill() {
eg.SetLimit(1)

View file

@ -62,7 +62,7 @@ func TestInitializationFailure(t *testing.T) {
OpenFile: opts.openFileMetabase,
}),
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{})),
shard.WithWriteCache(true),
shard.WithWriteCacheOptions(wcOpts),
@ -228,7 +228,6 @@ func TestPersistentShardID(t *testing.T) {
require.Equal(t, te.shards[1].id, newTe.shards[0].id)
require.Equal(t, te.shards[0].id, newTe.shards[1].id)
require.NoError(t, newTe.ng.Close(context.Background()))
}
func TestReload(t *testing.T) {
@ -299,7 +298,7 @@ func engineWithShards(t *testing.T, path string, num int) (*StorageEngine, []str
blobstor.WithStorages(newStorages(filepath.Join(addPath, strconv.Itoa(id)), errSmallSize))),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(addPath, fmt.Sprintf("%d.metabase", id))),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{}),
),
}

View file

@ -143,7 +143,8 @@ func (e *StorageEngine) reportShardError(
sh hashedShard,
msg string,
err error,
fields ...zap.Field) {
fields ...zap.Field,
) {
if isLogical(err) {
e.log.Warn(msg,
zap.Stringer("shard_id", sh.ID()),
@ -162,7 +163,8 @@ func (e *StorageEngine) reportShardErrorWithFlags(
block bool,
msg string,
err error,
fields ...zap.Field) {
fields ...zap.Field,
) {
sid := sh.ID()
e.log.Warn(msg, append([]zap.Field{
zap.Stringer("shard_id", sid),

View file

@ -144,7 +144,7 @@ func newStorages(root string, smallSize uint64) []blobstor.SubStorage {
blobovniczatree.WithRootPath(filepath.Join(root, "blobovnicza")),
blobovniczatree.WithBlobovniczaShallowDepth(1),
blobovniczatree.WithBlobovniczaShallowWidth(1),
blobovniczatree.WithPermissions(0700)),
blobovniczatree.WithPermissions(0o700)),
Policy: func(_ *objectSDK.Object, data []byte) bool {
return uint64(len(data)) < smallSize
},
@ -163,7 +163,7 @@ func newTestStorages(root string, smallSize uint64) ([]blobstor.SubStorage, *tes
blobovniczatree.WithRootPath(filepath.Join(root, "blobovnicza")),
blobovniczatree.WithBlobovniczaShallowDepth(1),
blobovniczatree.WithBlobovniczaShallowWidth(1),
blobovniczatree.WithPermissions(0700)),
blobovniczatree.WithPermissions(0o700)),
))
largeFileStorage := teststore.New(
teststore.WithSubstorage(fstree.New(
@ -205,7 +205,8 @@ func testDefaultShardOptions(t testing.TB, id int) []shard.Option {
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{}),
)}
),
}
}

View file

@ -59,12 +59,12 @@ func newEngineWithErrorThreshold(t testing.TB, dir string, errThreshold uint32)
shard.WithBlobStorOptions(blobstor.WithStorages(storages)),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(dir, fmt.Sprintf("%d.metabase", id))),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{}),
),
shard.WithPiloramaOptions(
pilorama.WithPath(filepath.Join(dir, fmt.Sprintf("%d.pilorama", id))),
pilorama.WithPerm(0700)),
pilorama.WithPerm(0o700)),
}
})
e := te.engine

View file

@ -163,7 +163,6 @@ func (e *StorageEngine) Evacuate(ctx context.Context, prm EvacuateShardPrm) (*Ev
res := NewEvacuateShardRes()
ctx = ctxOrBackground(ctx, prm.async)
eg, egCtx, err := e.evacuateLimiter.TryStart(ctx, shardIDs, res)
if err != nil {
return nil, err
}
@ -187,7 +186,8 @@ func ctxOrBackground(ctx context.Context, background bool) context.Context {
}
func (e *StorageEngine) evacuateShards(ctx context.Context, shardIDs []string, prm EvacuateShardPrm, res *EvacuateShardRes,
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard) error {
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard,
) error {
var err error
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.evacuateShards",
trace.WithAttributes(
@ -246,7 +246,8 @@ func (e *StorageEngine) getTotalObjectsCount(ctx context.Context, shardsToEvacua
}
func (e *StorageEngine) evacuateShard(ctx context.Context, shardID string, prm EvacuateShardPrm, res *EvacuateShardRes,
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard) error {
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard,
) error {
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.evacuateShard",
trace.WithAttributes(
attribute.String("shardID", shardID),
@ -322,7 +323,8 @@ func (e *StorageEngine) getActualShards(shardIDs []string, handlerDefined bool)
}
func (e *StorageEngine) evacuateObjects(ctx context.Context, sh *shard.Shard, toEvacuate []object.AddressWithType, prm EvacuateShardPrm, res *EvacuateShardRes,
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard) error {
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard,
) error {
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.evacuateObjects",
trace.WithAttributes(
attribute.Int("objects_count", len(toEvacuate)),
@ -378,7 +380,8 @@ func (e *StorageEngine) evacuateObjects(ctx context.Context, sh *shard.Shard, to
}
func (e *StorageEngine) tryEvacuateObjectLocal(ctx context.Context, addr oid.Address, object *objectSDK.Object, sh *shard.Shard,
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard, res *EvacuateShardRes) (bool, error) {
shards []pooledShard, weights []float64, shardsToEvacuate map[string]*shard.Shard, res *EvacuateShardRes,
) (bool, error) {
hrw.SortHasherSliceByWeightValue(shards, weights, hrw.StringHash(addr.EncodeToString()))
for j := range shards {
select {

View file

@ -39,7 +39,7 @@ func newEngineEvacuate(t *testing.T, shardNum int, objPerShard int) (*StorageEng
}})),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(dir, fmt.Sprintf("%d.metabase", id))),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{})),
}
})
@ -137,7 +137,7 @@ func TestEvacuateShard(t *testing.T) {
func TestEvacuateNetwork(t *testing.T) {
t.Parallel()
var errReplication = errors.New("handler error")
errReplication := errors.New("handler error")
acceptOneOf := func(objects []*objectSDK.Object, max uint64) func(context.Context, oid.Address, *objectSDK.Object) error {
var n uint64

View file

@ -72,9 +72,10 @@ func TestListWithCursor(t *testing.T) {
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
shard.WithMetaBaseOptions(
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0700),
meta.WithPermissions(0o700),
meta.WithEpochState(epochState{}),
)}
),
}
}).engine
require.NoError(t, e.Open(context.Background()))
require.NoError(t, e.Init(context.Background()))

View file

@ -48,6 +48,7 @@ func TestError(t *testing.T) {
}
})
}
func TestNilWrap(t *testing.T) {
require.NoError(t, Wrap(nil))
}

View file

@ -69,7 +69,6 @@ func (db *DB) GetChildren(ctx context.Context, addresses []oid.Address) (map[oid
}
return nil
})
if err != nil {
return nil, metaerr.Wrap(err)
}

View file

@ -10,8 +10,10 @@ import (
"go.etcd.io/bbolt"
)
var objectPhyCounterKey = []byte("phy_counter")
var objectLogicCounterKey = []byte("logic_counter")
var (
objectPhyCounterKey = []byte("phy_counter")
objectLogicCounterKey = []byte("logic_counter")
)
type objectType uint8

View file

@ -45,7 +45,7 @@ func newDB(t testing.TB, opts ...meta.Option) *meta.DB {
bdb := meta.New(
append([]meta.Option{
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
meta.WithPermissions(0600),
meta.WithPermissions(0o600),
meta.WithEpochState(epochState{}),
}, opts...)...,
)

View file

@ -98,8 +98,8 @@ func (db *DB) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) {
var rawRemoved uint64
var availableRemoved uint64
var err error
var sizes = make([]uint64, len(prm.addrs))
var availableSizes = make([]uint64, len(prm.addrs))
sizes := make([]uint64, len(prm.addrs))
availableSizes := make([]uint64, len(prm.addrs))
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
// We need to clear slice because tx can try to execute multiple times.

View file

@ -83,7 +83,6 @@ func (db *DB) FilterExpired(ctx context.Context, epoch uint64, addresses []oid.A
}
return nil
})
if err != nil {
return nil, metaerr.Wrap(err)
}

View file

@ -115,7 +115,7 @@ func (db *DB) listWithCursor(tx *bbolt.Tx, result []objectcore.AddressWithType,
graveyardBkt := tx.Bucket(graveyardBucketName)
garbageBkt := tx.Bucket(garbageBucketName)
var rawAddr = make([]byte, cidSize, addressKeySize)
rawAddr := make([]byte, cidSize, addressKeySize)
loop:
for ; name != nil; name, _ = c.Next() {

View file

@ -211,7 +211,6 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) {
for _, v := range expected {
require.Equal(t, 1, v)
}
}
func sortAddresses(addrWithType []object.AddressWithType) []object.AddressWithType {

View file

@ -244,7 +244,6 @@ func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) ([]oid.Addres
return nil
})
if err != nil {
return nil, err
}

View file

@ -101,7 +101,8 @@ func (db *DB) put(tx *bbolt.Tx,
obj *objectSDK.Object,
id []byte,
si *objectSDK.SplitInfo,
currEpoch uint64) error {
currEpoch uint64,
) error {
cnr, ok := obj.ContainerID()
if !ok {
return errors.New("missing container in object")

View file

@ -23,7 +23,7 @@ func TestVersion(t *testing.T) {
newDB := func(t *testing.T) *DB {
return New(WithPath(filepath.Join(dir, t.Name())),
WithPermissions(0600), WithEpochState(epochStateImpl{}))
WithPermissions(0o600), WithEpochState(epochStateImpl{}))
}
check := func(t *testing.T, db *DB) {
require.NoError(t, db.boltDB.View(func(tx *bbolt.Tx) error {

View file

@ -28,6 +28,7 @@ func (m *fstreeMetrics) SetParentID(parentID string) {
func (m *fstreeMetrics) SetMode(readOnly bool) {
m.m.SetMode(m.shardID, m.path, readOnly)
}
func (m *fstreeMetrics) Close() {
m.m.Close(m.shardID, m.path)
}
@ -35,24 +36,29 @@ func (m *fstreeMetrics) Close() {
func (m *fstreeMetrics) Iterate(d time.Duration, success bool) {
m.m.MethodDuration(m.shardID, m.path, "Iterate", d, success)
}
func (m *fstreeMetrics) Delete(d time.Duration, success bool) {
m.m.MethodDuration(m.shardID, m.path, "Delete", d, success)
}
func (m *fstreeMetrics) Exists(d time.Duration, success bool) {
m.m.MethodDuration(m.shardID, m.path, "Exists", d, success)
}
func (m *fstreeMetrics) Put(d time.Duration, size int, success bool) {
m.m.MethodDuration(m.shardID, m.path, "Put", d, success)
if success {
m.m.AddPut(m.shardID, m.path, size)
}
}
func (m *fstreeMetrics) Get(d time.Duration, size int, success bool) {
m.m.MethodDuration(m.shardID, m.path, "Get", d, success)
if success {
m.m.AddGet(m.shardID, m.path, size)
}
}
func (m *fstreeMetrics) GetRange(d time.Duration, size int, success bool) {
m.m.MethodDuration(m.shardID, m.path, "GetRange", d, success)
if success {

View file

@ -111,6 +111,7 @@ func (t *boltForest) SetMode(m mode.Mode) error {
t.metrics.SetMode(m)
return nil
}
func (t *boltForest) Open(_ context.Context, readOnly bool) error {
err := util.MkdirAllX(filepath.Dir(t.path), t.perm)
if err != nil {
@ -137,6 +138,7 @@ func (t *boltForest) Open(_ context.Context, readOnly bool) error {
t.metrics.SetMode(m)
return nil
}
func (t *boltForest) Init() error {
if t.mode.NoMetabase() || t.db.IsReadOnly() {
return nil
@ -150,6 +152,7 @@ func (t *boltForest) Init() error {
return err
})
}
func (t *boltForest) Close() error {
var err error
if t.db != nil {

View file

@ -71,7 +71,8 @@ func (f *memoryForest) TreeAddByPath(_ context.Context, d CIDDescriptor, treeID
Parent: node,
Meta: Meta{
Time: s.timestamp(d.Position, d.Size),
Items: []KeyValue{{Key: attr, Value: []byte(path[j])}}},
Items: []KeyValue{{Key: attr, Value: []byte(path[j])}},
},
Child: s.findSpareID(),
})
lm[j-i] = op.Move
@ -113,9 +114,11 @@ func (f *memoryForest) Init() error {
func (f *memoryForest) Open(context.Context, bool) error {
return nil
}
func (f *memoryForest) SetMode(mode.Mode) error {
return nil
}
func (f *memoryForest) Close() error {
return nil
}

View file

@ -36,7 +36,8 @@ var providers = []struct {
f := NewBoltForest(
append([]Option{
WithPath(filepath.Join(t.TempDir(), "test.db")),
WithMaxBatchSize(1)}, opts...)...)
WithMaxBatchSize(1),
}, opts...)...)
require.NoError(t, f.Open(context.Background(), false))
require.NoError(t, f.Init())
t.Cleanup(func() {
@ -68,7 +69,8 @@ func testForestTreeMove(t *testing.T, s Forest) {
meta := []KeyValue{
{Key: AttributeVersion, Value: []byte("XXX")},
{Key: AttributeFilename, Value: []byte("file.txt")}}
{Key: AttributeFilename, Value: []byte("file.txt")},
}
lm, err := s.TreeAddByPath(context.Background(), d, treeID, AttributeFilename, []string{"path", "to"}, meta)
require.NoError(t, err)
require.Equal(t, 3, len(lm))
@ -261,7 +263,8 @@ func testForestTreeAdd(t *testing.T, s Forest) {
meta := []KeyValue{
{Key: AttributeVersion, Value: []byte("XXX")},
{Key: AttributeFilename, Value: []byte("file.txt")}}
{Key: AttributeFilename, Value: []byte("file.txt")},
}
m := &Move{
Parent: RootID,
Child: RootID,
@ -306,7 +309,8 @@ func testForestTreeAddByPath(t *testing.T, s Forest) {
meta := []KeyValue{
{Key: AttributeVersion, Value: []byte("XXX")},
{Key: AttributeFilename, Value: []byte("file.txt")}}
{Key: AttributeFilename, Value: []byte("file.txt")},
}
t.Run("invalid descriptor", func(t *testing.T) {
_, err := s.TreeAddByPath(context.Background(), CIDDescriptor{cid, 0, 0}, treeID, AttributeFilename, []string{"yyy"}, meta)
@ -381,7 +385,8 @@ func testForestTreeAddByPath(t *testing.T, s Forest) {
testMeta(t, s, cid, treeID, oldMove.Child, oldMove.Parent,
Meta{Time: oldMove.Time, Items: []KeyValue{
{AttributeVersion, []byte("SomeValue")},
{AttributeFilename, []byte("another")}}})
{AttributeFilename, []byte("another")},
}})
t.Run("get by path", func(t *testing.T) {
nodes, err := s.TreeGetByPath(context.Background(), cid, treeID, AttributeFilename, []string{"path", "another"}, false)
@ -399,7 +404,8 @@ func testForestTreeAddByPath(t *testing.T, s Forest) {
t.Run("empty component", func(t *testing.T) {
meta := []KeyValue{
{Key: AttributeVersion, Value: []byte("XXX")},
{Key: AttributeFilename, Value: []byte{}}}
{Key: AttributeFilename, Value: []byte{}},
}
lm, err := s.TreeAddByPath(context.Background(), d, treeID, AttributeFilename, []string{"path", "to"}, meta)
require.NoError(t, err)
require.Equal(t, 1, len(lm))

View file

@ -21,7 +21,8 @@ func TestMeta_Bytes(t *testing.T) {
Items: []KeyValue{
{"abc", []byte{1, 2, 3}},
{AttributeFilename, []byte{}},
}}
},
}
data := expected.Bytes()
@ -35,7 +36,8 @@ func TestMeta_Bytes(t *testing.T) {
Items: []KeyValue{
{"abc", []byte{1, 2, 3}},
{"xyz", []byte{5, 6, 7, 8}},
}}
},
}
data := expected.Bytes()

View file

@ -101,7 +101,7 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) {
_, err = sh.Get(context.Background(), getPrm)
require.NoError(t, err, "failed to get")
//inhume
// inhume
var inhumePrm InhumePrm
inhumePrm.MarkAsGarbage(addr)
_, err = sh.Inhume(context.Background(), inhumePrm)
@ -110,13 +110,13 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) {
require.Error(t, err, "get returned error")
require.True(t, client.IsErrObjectNotFound(err), "invalid error type")
//storageID
// storageID
var metaStIDPrm meta.StorageIDPrm
metaStIDPrm.SetAddress(addr)
storageID, err := sh.metaBase.StorageID(context.Background(), metaStIDPrm)
require.NoError(t, err, "failed to get storage ID")
//check existence in blobstore
// check existence in blobstore
var bsExisted common.ExistsPrm
bsExisted.Address = addr
bsExisted.StorageID = storageID.StorageID()
@ -124,19 +124,19 @@ func Test_ObjectNotFoundIfNotDeletedFromMetabase(t *testing.T) {
require.NoError(t, err, "failed to check blobstore existence")
require.True(t, exRes.Exists, "invalid blobstore existence result")
//drop from blobstor
// drop from blobstor
var bsDeletePrm common.DeletePrm
bsDeletePrm.Address = addr
bsDeletePrm.StorageID = storageID.StorageID()
_, err = sh.blobStor.Delete(context.Background(), bsDeletePrm)
require.NoError(t, err, "failed to delete from blobstore")
//check existence in blobstore
// check existence in blobstore
exRes, err = sh.blobStor.Exists(context.Background(), bsExisted)
require.NoError(t, err, "failed to check blobstore existence")
require.False(t, exRes.Exists, "invalid blobstore existence result")
//get should return object not found
// get should return object not found
_, err = sh.Get(context.Background(), getPrm)
require.Error(t, err, "get returned no error")
require.True(t, client.IsErrObjectNotFound(err), "invalid error type")

View file

@ -41,7 +41,8 @@ func TestShardReload(t *testing.T) {
metaOpts := []meta.Option{
meta.WithPath(filepath.Join(p, "meta")),
meta.WithEpochState(epochState{})}
meta.WithEpochState(epochState{}),
}
opts := []Option{
WithID(NewIDFromBytes([]byte{})),
@ -49,7 +50,8 @@ func TestShardReload(t *testing.T) {
WithBlobStorOptions(blobOpts...),
WithMetaBaseOptions(metaOpts...),
WithPiloramaOptions(
pilorama.WithPath(filepath.Join(p, "pilorama")))}
pilorama.WithPath(filepath.Join(p, "pilorama"))),
}
sh := New(opts...)
require.NoError(t, sh.Open(context.Background()))

View file

@ -94,7 +94,8 @@ func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard
WithBlobStorOptions(o.bsOpts...),
WithMetaBaseOptions(
append([]meta.Option{
meta.WithPath(filepath.Join(o.rootPath, "meta")), meta.WithEpochState(epochState{})},
meta.WithPath(filepath.Join(o.rootPath, "meta")), meta.WithEpochState(epochState{}),
},
o.metaOptions...)...,
),
WithPiloramaOptions(pilorama.WithPath(filepath.Join(o.rootPath, "pilorama"))),

View file

@ -55,9 +55,7 @@ const (
defaultMaxCacheSize = 1 << 30 // 1 GiB
)
var (
defaultBucket = []byte{0}
)
var defaultBucket = []byte{0}
// New creates new writecache instance.
func New(opts ...Option) writecache.Cache {

Some files were not shown because too many files have changed in this diff Show more