add additional fdatasync before close() on writes (#9947)

This commit is contained in:
Harshavardhana 2020-07-01 10:57:23 -07:00 committed by GitHub
parent 5388ae4acb
commit 174f428571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 134 additions and 42 deletions

View File

@ -9,7 +9,7 @@ function _init() {
export CGO_ENABLED=0 export CGO_ENABLED=0
## List of architectures and OS to test coss compilation. ## List of architectures and OS to test coss compilation.
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386" SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386 netbsd/amd64"
} }
function _build() { function _build() {

View File

@ -27,7 +27,6 @@ import (
"github.com/minio/minio/pkg/disk" "github.com/minio/minio/pkg/disk"
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
cpuhw "github.com/shirou/gopsutil/cpu" cpuhw "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
memhw "github.com/shirou/gopsutil/mem" memhw "github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/process" "github.com/shirou/gopsutil/process"
) )
@ -369,36 +368,3 @@ func getLocalProcOBD(ctx context.Context, r *http.Request) madmin.ServerProcOBDI
Processes: sysProcs, Processes: sysProcs,
} }
} }
func getLocalOsInfoOBD(ctx context.Context, r *http.Request) madmin.ServerOsOBDInfo {
addr := r.Host
if globalIsDistErasure {
addr = GetLocalPeer(globalEndpoints)
}
info, err := host.InfoWithContext(ctx)
if err != nil {
return madmin.ServerOsOBDInfo{
Addr: addr,
Error: err.Error(),
}
}
sensors, err := host.SensorsTemperaturesWithContext(ctx)
if err != nil {
return madmin.ServerOsOBDInfo{
Addr: addr,
Error: err.Error(),
}
}
// ignore user err, as it cannot be obtained reliably inside containers
users, _ := host.UsersWithContext(ctx)
return madmin.ServerOsOBDInfo{
Addr: addr,
Info: info,
Sensors: sensors,
Users: users,
}
}

View File

@ -1,4 +1,4 @@
// +build !freebsd // +build !freebsd,!netbsd,!openbsd,!solaris
/* /*
* MinIO Cloud Storage, (C) 2020 MinIO, Inc. * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
@ -26,8 +26,42 @@ import (
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
diskhw "github.com/shirou/gopsutil/disk" diskhw "github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host"
) )
func getLocalOsInfoOBD(ctx context.Context, r *http.Request) madmin.ServerOsOBDInfo {
addr := r.Host
if globalIsDistErasure {
addr = GetLocalPeer(globalEndpoints)
}
info, err := host.InfoWithContext(ctx)
if err != nil {
return madmin.ServerOsOBDInfo{
Addr: addr,
Error: err.Error(),
}
}
sensors, err := host.SensorsTemperaturesWithContext(ctx)
if err != nil {
return madmin.ServerOsOBDInfo{
Addr: addr,
Error: err.Error(),
}
}
// ignore user err, as it cannot be obtained reliably inside containers
users, _ := host.UsersWithContext(ctx)
return madmin.ServerOsOBDInfo{
Addr: addr,
Info: info,
Sensors: sensors,
Users: users,
}
}
func getLocalDiskHwOBD(ctx context.Context, r *http.Request) madmin.ServerDiskHwOBDInfo { func getLocalDiskHwOBD(ctx context.Context, r *http.Request) madmin.ServerDiskHwOBDInfo {
addr := r.Host addr := r.Host
if globalIsDistErasure { if globalIsDistErasure {

View File

@ -1,3 +1,5 @@
// +build freebsd netbsd openbsd solaris
/* /*
* MinIO Cloud Storage, (C) 2020 MinIO, Inc. * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
* *
@ -20,6 +22,7 @@ package cmd
import ( import (
"context" "context"
"net/http" "net/http"
"runtime"
"github.com/minio/minio/pkg/madmin" "github.com/minio/minio/pkg/madmin"
) )
@ -32,6 +35,18 @@ func getLocalDiskHwOBD(ctx context.Context, r *http.Request) madmin.ServerDiskHw
return madmin.ServerDiskHwOBDInfo{ return madmin.ServerDiskHwOBDInfo{
Addr: addr, Addr: addr,
Error: "unsupported platform", Error: "unsupported platform: " + runtime.GOOS,
}
}
func getLocalOsInfoOBD(ctx context.Context, r *http.Request) madmin.ServerOsOBDInfo {
addr := r.Host
if globalIsDistErasure {
addr = GetLocalPeer(globalEndpoints)
}
return madmin.ServerOsOBDInfo{
Addr: addr,
Error: "unsupported platform: " + runtime.GOOS,
} }
} }

View File

@ -1694,7 +1694,10 @@ func (s *xlStorage) CreateFile(volume, path string, fileSize int64, r io.Reader)
return err return err
} }
defer w.Close() defer func() {
disk.Fdatasync(w) // Only interested in flushing the size_t not mtime/atime
w.Close()
}()
bufp := s.pool.Get().(*[]byte) bufp := s.pool.Get().(*[]byte)
defer s.pool.Put(bufp) defer s.pool.Put(bufp)

View File

@ -1,4 +1,4 @@
// +build !linux,!netbsd,!freebsd,!darwin // +build !linux,!netbsd,!freebsd,!darwin,!openbsd
/* /*
* Minio Cloud Storage, (C) 2019-2020 Minio, Inc. * Minio Cloud Storage, (C) 2019-2020 Minio, Inc.
@ -47,16 +47,23 @@ import (
// see this ZFS-on-Linux commit message: // see this ZFS-on-Linux commit message:
// https://github.com/openzfs/zfs/commit/a584ef26053065f486d46a7335bea222cb03eeea // https://github.com/openzfs/zfs/commit/a584ef26053065f486d46a7335bea222cb03eeea
// OpenFileDirectIO wrapper around os.OpenFile nothing special
func OpenFileDirectIO(filePath string, flag int, perm os.FileMode) (*os.File, error) { func OpenFileDirectIO(filePath string, flag int, perm os.FileMode) (*os.File, error) {
return os.OpenFile(filePath, flag, perm) return os.OpenFile(filePath, flag, perm)
} }
// DisableDirectIO is a no-op
func DisableDirectIO(f *os.File) error { func DisableDirectIO(f *os.File) error {
return nil return nil
} }
// AlignedBlock simply returns an unaligned buffer for systems that do not // AlignedBlock simply returns an unaligned buffer
// support DirectIO. // for systems that do not support DirectIO.
func AlignedBlock(BlockSize int) []byte { func AlignedBlock(BlockSize int) []byte {
return make([]byte, BlockSize) return make([]byte, BlockSize)
} }
// Fdatasync is a no-op
func Fdatasync(f *os.File) error {
return nil
}

View File

@ -0,0 +1,38 @@
// +build linux
/*
* Minio Cloud Storage, (C) 2020 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package disk
import (
"os"
"syscall"
)
// Fdatasync - fdatasync() is similar to fsync(), but does not flush modified metadata
// unless that metadata is needed in order to allow a subsequent data retrieval
// to be correctly handled. For example, changes to st_atime or st_mtime
// (respectively, time of last access and time of last modification; see inode(7))
// do not require flushing because they are not necessary for a subsequent data
// read to be handled correctly. On the other hand, a change to the file size
// (st_size, as made by say ftruncate(2)), would require a metadata flush.
//
// The aim of fdatasync() is to reduce disk activity for applications that
// do not require all metadata to be synchronized with the disk.
func Fdatasync(f *os.File) error {
return syscall.Fdatasync(int(f.Fd()))
}

View File

@ -0,0 +1,29 @@
// +build freebsd netbsd openbsd darwin
/*
* Minio Cloud Storage, (C) 2020 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package disk
import (
"os"
"syscall"
)
// Fdatasync is fsync on freebsd/darwin
func Fdatasync(f *os.File) error {
return syscall.Fsync(int(f.Fd()))
}

View File

@ -1,5 +1,5 @@
/* /*
* MinIO Cloud Storage, (C) 2017, 2018 MinIO, Inc. * MinIO Cloud Storage, (C) 2017-2020 MinIO, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.