Skip to content

Commit

Permalink
Merge 7c54307 into aba6622
Browse files Browse the repository at this point in the history
  • Loading branch information
carpawell authored Aug 15, 2023
2 parents aba6622 + 7c54307 commit 688773c
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ minor release, the component will be purged, so be prepared (see `Updating` sect
- Stored payload metric per container (#2116)
- Stored payload metric per shard (#2023)
- Histogram metrics for RPC and engine operations (#2351)
- SN's version is announced via the attributes automatically but can be overwritten explicitly (#2455)
- New storage component for small objects named Peapod (#2453)
- New `blobovnicza-to-peapod` tool providing blobovnicza-to-peapod data migration (#2453)
- SN's version and capacity is announced via the attributes automatically but can be overwritten explicitly (#2455, #602)

### Fixed
- `neo-go` RPC connection loss handling (#1337)
Expand Down
44 changes: 36 additions & 8 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,17 @@ var persistateSideChainLastBlockKey = []byte("side_chain_last_processed_block")
func initCfg(appCfg *config.Config) *cfg {
c := &cfg{}

// attaching version to the node's attributes; do not
// move it anywhere below reading the other attributes
// since a user should be able to overwrite it.
writeAppVersion(c)

err := c.readConfig(appCfg)
if err != nil {
panic(fmt.Errorf("config reading: %w", err))
}

// filling system attributes; do not move it anywhere
// below applying the other attributes since a user
// should be able to overwrite it.
err = writeSystemAttributes(c)
fatalOnErr(err)

Check warning on line 554 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L553-L554

Added lines #L553 - L554 were not covered by tests

key := nodeconfig.Key(appCfg)

var netAddr network.AddressGroup
Expand Down Expand Up @@ -986,8 +987,35 @@ func (c *cfg) configWatcher(ctx context.Context) {
}
}

// writeAppVersion writes app version as defined at compilation
// step to the node's attributes.
func writeAppVersion(c *cfg) {
// writeSystemAttributes writes app version as defined at compilation
// step to the node's attributes and an aggregated disk capacity
// according to the all space on the all configured disks.
func writeSystemAttributes(c *cfg) error {

Check warning on line 993 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L993

Added line #L993 was not covered by tests
// `Version` attribute

c.cfgNodeInfo.localInfo.SetAttribute("Version", misc.Version)

// `Capacity` attribute

var paths []string
for _, sh := range c.applicationConfiguration.EngineCfg.shards {
for _, storage := range sh.subStorages {
path := storage.path
paths = append(paths, path)

Check warning on line 1004 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L1000-L1004

Added lines #L1000 - L1004 were not covered by tests

err := util.MkdirAllX(path, storage.perm)
if err != nil {
return fmt.Errorf("can not create (ensure it exists) dir by '%s' path: %w", path, err)

Check warning on line 1008 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L1006-L1008

Added lines #L1006 - L1008 were not covered by tests
}
}
}

total, err := totalBytes(paths)
if err != nil {
return fmt.Errorf("calculating capacity on every shard: %w", err)

Check warning on line 1015 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L1013-L1015

Added lines #L1013 - L1015 were not covered by tests
}

c.cfgNodeInfo.localInfo.SetCapacity(total / (1 << 30))

Check warning on line 1018 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L1018

Added line #L1018 was not covered by tests

return nil

Check warning on line 1020 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L1020

Added line #L1020 was not covered by tests
}
31 changes: 31 additions & 0 deletions cmd/neofs-node/fs_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build !windows

package main

import (
"fmt"

"golang.org/x/sys/unix"
)

func totalBytes(paths []string) (uint64, error) {
var stat unix.Statfs_t
var total uint64 // bytes
fsIDMap := make(map[unix.Fsid]struct{})

Check warning on line 14 in cmd/neofs-node/fs_unix.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/fs_unix.go#L11-L14

Added lines #L11 - L14 were not covered by tests

for _, path := range paths {
err := unix.Statfs(path, &stat)
if err != nil {
return 0, fmt.Errorf("get FS stat by '%s' path: %w", path, err)

Check warning on line 19 in cmd/neofs-node/fs_unix.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/fs_unix.go#L16-L19

Added lines #L16 - L19 were not covered by tests
}

if _, handled := fsIDMap[stat.Fsid]; handled {
continue

Check warning on line 23 in cmd/neofs-node/fs_unix.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/fs_unix.go#L22-L23

Added lines #L22 - L23 were not covered by tests
}

total += stat.Blocks * uint64(stat.Bsize)
fsIDMap[stat.Fsid] = struct{}{}

Check warning on line 27 in cmd/neofs-node/fs_unix.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/fs_unix.go#L26-L27

Added lines #L26 - L27 were not covered by tests
}

return total, nil

Check warning on line 30 in cmd/neofs-node/fs_unix.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/fs_unix.go#L30

Added line #L30 was not covered by tests
}
37 changes: 37 additions & 0 deletions cmd/neofs-node/fs_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build windows

package main

import (
"fmt"
"path/filepath"

"golang.org/x/sys/windows"
)

func totalBytes(paths []string) (uint64, error) {
var total uint64 // bytes
diskMap := make(map[string]struct{}, len(paths))

for _, path := range paths {
disk := filepath.VolumeName(path)
if _, handled := diskMap[disk]; handled {
continue
}

var availB uint64
var totalB uint64
var freeTotalB uint64
var pathP = windows.StringToUTF16Ptr(path)

err := windows.GetDiskFreeSpaceEx(pathP, &availB, &totalB, &freeTotalB)
if err != nil {
return 0, fmt.Errorf("get disk stat by '%s' path: %w", path, err)
}

total += totalB
diskMap[disk] = struct{}{}
}

return total, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
go.etcd.io/bbolt v1.3.7
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.24.0
golang.org/x/sys v0.8.0
golang.org/x/term v0.5.0
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -97,7 +98,6 @@ require (
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.2.0 // indirect
Expand Down

0 comments on commit 688773c

Please sign in to comment.