aboutsummaryrefslogtreecommitdiff
path: root/weed/storage
diff options
context:
space:
mode:
Diffstat (limited to 'weed/storage')
-rw-r--r--weed/storage/disk_location.go31
-rw-r--r--weed/storage/disk_location_ec.go13
-rw-r--r--weed/storage/needle/needle_parse_upload.go5
-rw-r--r--weed/storage/needle/needle_read_write_test.go3
-rw-r--r--weed/storage/needle_map_metric_test.go4
-rw-r--r--weed/storage/volume_info/volume_info.go11
-rw-r--r--weed/storage/volume_vacuum_test.go5
-rw-r--r--weed/storage/volume_write_test.go10
8 files changed, 38 insertions, 44 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go
index c6fceb2c2..a32a0093d 100644
--- a/weed/storage/disk_location.go
+++ b/weed/storage/disk_location.go
@@ -2,8 +2,6 @@ package storage
import (
"fmt"
- "github.com/chrislusf/seaweedfs/weed/storage/types"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -14,6 +12,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
+ "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util"
)
@@ -85,9 +84,9 @@ func getValidVolumeName(basename string) string {
return ""
}
-func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind NeedleMapKind) bool {
- basename := fileInfo.Name()
- if fileInfo.IsDir() {
+func (l *DiskLocation) loadExistingVolume(dirEntry os.DirEntry, needleMapKind NeedleMapKind) bool {
+ basename := dirEntry.Name()
+ if dirEntry.IsDir() {
return false
}
volumeName := getValidVolumeName(basename)
@@ -103,7 +102,7 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
// check for incomplete volume
noteFile := l.Directory + "/" + volumeName + ".note"
if util.FileExists(noteFile) {
- note, _ := ioutil.ReadFile(noteFile)
+ note, _ := os.ReadFile(noteFile)
glog.Warningf("volume %s was not completed: %s", volumeName, string(note))
removeVolumeFiles(l.Directory + "/" + volumeName)
removeVolumeFiles(l.IdxDirectory + "/" + volumeName)
@@ -143,18 +142,18 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
func (l *DiskLocation) concurrentLoadingVolumes(needleMapKind NeedleMapKind, concurrency int) {
- task_queue := make(chan os.FileInfo, 10*concurrency)
+ task_queue := make(chan os.DirEntry, 10*concurrency)
go func() {
foundVolumeNames := make(map[string]bool)
- if fileInfos, err := ioutil.ReadDir(l.Directory); err == nil {
- for _, fi := range fileInfos {
- volumeName := getValidVolumeName(fi.Name())
+ if dirEntries, err := os.ReadDir(l.Directory); err == nil {
+ for _, entry := range dirEntries {
+ volumeName := getValidVolumeName(entry.Name())
if volumeName == "" {
continue
}
if _, found := foundVolumeNames[volumeName]; !found {
foundVolumeNames[volumeName] = true
- task_queue <- fi
+ task_queue <- entry
}
}
}
@@ -332,12 +331,12 @@ func (l *DiskLocation) Close() {
return
}
-func (l *DiskLocation) LocateVolume(vid needle.VolumeId) (os.FileInfo, bool) {
- if fileInfos, err := ioutil.ReadDir(l.Directory); err == nil {
- for _, fileInfo := range fileInfos {
- volId, _, err := volumeIdFromFileName(fileInfo.Name())
+func (l *DiskLocation) LocateVolume(vid needle.VolumeId) (os.DirEntry, bool) {
+ if dirEntries, err := os.ReadDir(l.Directory); err == nil {
+ for _, entry := range dirEntries {
+ volId, _, err := volumeIdFromFileName(entry.Name())
if vid == volId && err == nil {
- return fileInfo, true
+ return entry, true
}
}
}
diff --git a/weed/storage/disk_location_ec.go b/weed/storage/disk_location_ec.go
index 91c7d86a6..3f56d797b 100644
--- a/weed/storage/disk_location_ec.go
+++ b/weed/storage/disk_location_ec.go
@@ -2,7 +2,6 @@ package storage
import (
"fmt"
- "io/ioutil"
"os"
"path"
"regexp"
@@ -118,25 +117,25 @@ func (l *DiskLocation) loadEcShards(shards []string, collection string, vid need
func (l *DiskLocation) loadAllEcShards() (err error) {
- fileInfos, err := ioutil.ReadDir(l.Directory)
+ dirEntries, err := os.ReadDir(l.Directory)
if err != nil {
return fmt.Errorf("load all ec shards in dir %s: %v", l.Directory, err)
}
if l.IdxDirectory != l.Directory {
- indexFileInfos, err := ioutil.ReadDir(l.IdxDirectory)
+ indexDirEntries, err := os.ReadDir(l.IdxDirectory)
if err != nil {
return fmt.Errorf("load all ec shards in dir %s: %v", l.IdxDirectory, err)
}
- fileInfos = append(fileInfos, indexFileInfos...)
+ dirEntries = append(dirEntries, indexDirEntries...)
}
- sort.Slice(fileInfos, func(i, j int) bool {
- return fileInfos[i].Name() < fileInfos[j].Name()
+ sort.Slice(dirEntries, func(i, j int) bool {
+ return dirEntries[i].Name() < dirEntries[j].Name()
})
var sameVolumeShards []string
var prevVolumeId needle.VolumeId
- for _, fileInfo := range fileInfos {
+ for _, fileInfo := range dirEntries {
if fileInfo.IsDir() {
continue
}
diff --git a/weed/storage/needle/needle_parse_upload.go b/weed/storage/needle/needle_parse_upload.go
index bda58fbc3..a1f517b45 100644
--- a/weed/storage/needle/needle_parse_upload.go
+++ b/weed/storage/needle/needle_parse_upload.go
@@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"io"
- "io/ioutil"
"mime"
"net/http"
"path"
@@ -108,7 +107,7 @@ func parsePut(r *http.Request, sizeLimit int64, pu *ParsedUpload) error {
pu.FileName = ""
dataSize, err := pu.bytesBuffer.ReadFrom(io.LimitReader(r.Body, sizeLimit+1))
if err == io.EOF || dataSize == sizeLimit+1 {
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
}
pu.Data = pu.bytesBuffer.Bytes()
r.Body.Close()
@@ -118,7 +117,7 @@ func parsePut(r *http.Request, sizeLimit int64, pu *ParsedUpload) error {
func parseMultipart(r *http.Request, sizeLimit int64, pu *ParsedUpload) (e error) {
defer func() {
if e != nil && r.Body != nil {
- io.Copy(ioutil.Discard, r.Body)
+ io.Copy(io.Discard, r.Body)
r.Body.Close()
}
}()
diff --git a/weed/storage/needle/needle_read_write_test.go b/weed/storage/needle/needle_read_write_test.go
index afcea5a05..20dbc2554 100644
--- a/weed/storage/needle/needle_read_write_test.go
+++ b/weed/storage/needle/needle_read_write_test.go
@@ -1,7 +1,6 @@
package needle
import (
- "io/ioutil"
"os"
"testing"
@@ -31,7 +30,7 @@ func TestAppend(t *testing.T) {
Padding: nil, // Padding []byte `comment:"Aligned to 8 bytes"`
}
- tempFile, err := ioutil.TempFile("", ".dat")
+ tempFile, err := os.CreateTemp("", ".dat")
if err != nil {
t.Errorf("Fail TempFile. %v", err)
return
diff --git a/weed/storage/needle_map_metric_test.go b/weed/storage/needle_map_metric_test.go
index 362659a11..c04fd6c8b 100644
--- a/weed/storage/needle_map_metric_test.go
+++ b/weed/storage/needle_map_metric_test.go
@@ -1,8 +1,8 @@
package storage
import (
- "io/ioutil"
"math/rand"
+ "os"
"testing"
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -11,7 +11,7 @@ import (
func TestFastLoadingNeedleMapMetrics(t *testing.T) {
- idxFile, _ := ioutil.TempFile("", "tmp.idx")
+ idxFile, _ := os.CreateTemp("", "tmp.idx")
nm := NewCompactNeedleMap(idxFile)
for i := 0; i < 10000; i++ {
diff --git a/weed/storage/volume_info/volume_info.go b/weed/storage/volume_info/volume_info.go
index b7ef75171..fa906e1d4 100644
--- a/weed/storage/volume_info/volume_info.go
+++ b/weed/storage/volume_info/volume_info.go
@@ -3,15 +3,14 @@ package volume_info
import (
"bytes"
"fmt"
- "io/ioutil"
-
- _ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
- "github.com/chrislusf/seaweedfs/weed/util"
+ "os"
"github.com/golang/protobuf/jsonpb"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
+ _ "github.com/chrislusf/seaweedfs/weed/storage/backend/s3_backend"
+ "github.com/chrislusf/seaweedfs/weed/util"
)
// MaybeLoadVolumeInfo load the file data as *volume_server_pb.VolumeInfo, the returned volumeInfo will not be nil
@@ -36,7 +35,7 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
hasVolumeInfoFile = true
glog.V(1).Infof("maybeLoadVolumeInfo reads %s", fileName)
- tierData, readErr := ioutil.ReadFile(fileName)
+ tierData, readErr := os.ReadFile(fileName)
if readErr != nil {
glog.Warningf("fail to read %s : %v", fileName, readErr)
err = fmt.Errorf("fail to read %s : %v", fileName, readErr)
@@ -76,7 +75,7 @@ func SaveVolumeInfo(fileName string, volumeInfo *volume_server_pb.VolumeInfo) er
return fmt.Errorf("marshal to %s: %v", fileName, marshalErr)
}
- writeErr := ioutil.WriteFile(fileName, []byte(text), 0755)
+ writeErr := os.WriteFile(fileName, []byte(text), 0755)
if writeErr != nil {
return fmt.Errorf("fail to write %s : %v", fileName, writeErr)
}
diff --git a/weed/storage/volume_vacuum_test.go b/weed/storage/volume_vacuum_test.go
index c9596d11d..64f4b3b60 100644
--- a/weed/storage/volume_vacuum_test.go
+++ b/weed/storage/volume_vacuum_test.go
@@ -1,7 +1,6 @@
package storage
import (
- "io/ioutil"
"math/rand"
"os"
"testing"
@@ -45,7 +44,7 @@ preparing test prerequisite easier )
func TestMakeDiff(t *testing.T) {
v := new(Volume)
- //lastCompactIndexOffset value is the index file size before step 4
+ // lastCompactIndexOffset value is the index file size before step 4
v.lastCompactIndexOffset = 96
v.SuperBlock.Version = 0x2
/*
@@ -63,7 +62,7 @@ func TestMakeDiff(t *testing.T) {
}
func TestCompaction(t *testing.T) {
- dir, err := ioutil.TempDir("", "example")
+ dir, err := os.MkdirTemp("", "example")
if err != nil {
t.Fatalf("temp dir creation: %v", err)
}
diff --git a/weed/storage/volume_write_test.go b/weed/storage/volume_write_test.go
index 309f29657..9f661a27f 100644
--- a/weed/storage/volume_write_test.go
+++ b/weed/storage/volume_write_test.go
@@ -2,17 +2,17 @@ package storage
import (
"fmt"
- "github.com/chrislusf/seaweedfs/weed/storage/needle"
- "github.com/chrislusf/seaweedfs/weed/storage/super_block"
- "github.com/chrislusf/seaweedfs/weed/storage/types"
- "io/ioutil"
"os"
"testing"
"time"
+
+ "github.com/chrislusf/seaweedfs/weed/storage/needle"
+ "github.com/chrislusf/seaweedfs/weed/storage/super_block"
+ "github.com/chrislusf/seaweedfs/weed/storage/types"
)
func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
- dir, err := ioutil.TempDir("", "example")
+ dir, err := os.MkdirTemp("", "example")
if err != nil {
t.Fatalf("temp dir creation: %v", err)
}