From b9b353db4be5b78da8d89909904f4ca8638c24f8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 11 Dec 2018 16:22:56 -0800 Subject: [PATCH] Add env to support synchronous ops for all calls (#6877) --- cmd/posix.go | 20 ++++++++++++++++++-- docs/config/README.md | 17 ++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cmd/posix.go b/cmd/posix.go index 6eb6ac267..004684c86 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -71,6 +71,7 @@ type posix struct { connected bool diskMount bool // indicates if the path is an actual mount. + driveSync bool // indicates if the backend is synchronous. // Disk usage metrics stopUsageCh chan struct{} @@ -191,6 +192,15 @@ func newPosix(path string) (*posix, error) { diskMount: mountinfo.IsLikelyMountPoint(path), } + var pf BoolFlag + if driveSync := os.Getenv("MINIO_DRIVE_SYNC"); driveSync != "" { + pf, err = ParseBoolFlag(driveSync) + if err != nil { + return nil, err + } + p.driveSync = bool(pf) + } + if !p.diskMount { go p.diskUsage(globalServiceDoneCh) } @@ -1013,8 +1023,14 @@ func (s *posix) AppendFile(volume, path string, buf []byte) (err error) { return errFaultyDisk } - // Create file if not found - w, err := s.openFile(volume, path, os.O_CREATE|os.O_APPEND|os.O_WRONLY) + var w *os.File + // Create file if not found, additionally also enables synchronous + // operation if asked by the user. + if s.driveSync { + w, err = s.openFile(volume, path, os.O_CREATE|os.O_SYNC|os.O_APPEND|os.O_WRONLY) + } else { + w, err = s.openFile(volume, path, os.O_CREATE|os.O_APPEND|os.O_WRONLY) + } if err != nil { return err } diff --git a/docs/config/README.md b/docs/config/README.md index 742c64af5..40232d505 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -132,9 +132,9 @@ By default, parity for objects with standard storage class is set to `N/2`, and ## Environment only settings -#### Browser +### Browser -Enable or disable access to web UI. By default it is set to `on`. You may override this field with ``MINIO_BROWSER`` environment variable. +Enable or disable access to web UI. By default it is set to `on`. You may override this field with `MINIO_BROWSER` environment variable. Example: @@ -145,7 +145,7 @@ minio server /data ### Domain -By default, Minio supports path-style requests that are of the format http://mydomain.com/bucket/object. MINIO_DOMAIN environment variable is used to enable virtual-host-style requests. If the request `Host` header matches with `(.+).mydomain.com` then the matched pattern `$1` is used as bucket and the path is used as object. More information on path-style and virtual-host-style [here](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAPI.html) +By default, Minio supports path-style requests that are of the format http://mydomain.com/bucket/object. `MINIO_DOMAIN` environment variable is used to enable virtual-host-style requests. If the request `Host` header matches with `(.+).mydomain.com` then the matched pattern `$1` is used as bucket and the path is used as object. More information on path-style and virtual-host-style [here](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAPI.html) Example: ```sh @@ -153,6 +153,17 @@ export MINIO_DOMAIN=mydomain.com minio server /data ``` +### Drive Sync + +By default, Minio writes to disk in synchronous mode for all metadata operations. Set `MINIO_DRIVE_SYNC` environment variable to enable synchronous mode for all data operations as well. + +Example: + +```sh +export MINIO_DRIVE_SYNC=on +minio server /data +``` + ## Explore Further * [Minio Quickstart Guide](https://docs.minio.io/docs/minio-quickstart-guide)