]> Cypherpunks.ru repositories - nncp.git/commitdiff
NNCPNOSYNC environment variable
authorSergey Matveev <stargrave@stargrave.org>
Mon, 28 Feb 2022 14:14:39 +0000 (17:14 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 2 Mar 2022 08:17:43 +0000 (11:17 +0300)
doc/cmd/index.texi
doc/news.ru.texi
doc/news.texi
src/cfg.go
src/cmd/nncp-bundle/main.go
src/cmd/nncp-reass/main.go
src/cmd/nncp-xfer/main.go
src/sp.go
src/tmp.go
src/toss.go

index 56ea8e90b001c5c4e6f03b451033779cb260b45f..9f3c887bfc316a6122ca9869ed4e45d58d3e4e89 100644 (file)
@@ -49,6 +49,12 @@ Nearly all commands have the following common options:
 @vindex TMPDIR
 All commands respect @env{$TMPDIR} environment variable.
 
+@vindex NNCPNOSYNC
+If you set @env{$NNCPNOSYNC=1}, then all @code{fsync} operations will be
+skipped. That is dangerous option, but if there there are abilities to
+rollback possibly corrupted state to some stable snapshot, then disabled
+@code{fsync} can give considerable increase in performance.
+
 @menu
 Configuration file commands
 
index 161708e66a7d5cc1d950edcfb0014656dd2b24f5..76ebe57484300dc7bddccbe57c05cbd7f626e9e3 100644 (file)
@@ -1,6 +1,20 @@
 @node Новости
 @section Новости
 
+@node Релиз 8.6.0
+@subsection Релиз 8.6.0
+@itemize
+
+@item
+Появилась возможность отключения @code{fsync} операции
+@env{$NNCPNOSYNC=1} переменной окружения.
+
+@item
+Добавлены разнообразные индексы в документации, что должно помочь при
+поиске в ней.
+
+@end itemize
+
 @node Релиз 8.5.0
 @subsection Релиз 8.5.0
 @itemize
@@ -303,7 +317,7 @@ NNCP собирается на NetBSD.
 @itemize
 
 @item
-Исправлено падение при fsync директорий после создания @file{.seen} файлов.
+Исправлено падение при @code{fsync} директорий после создания @file{.seen} файлов.
 
 @end itemize
 
@@ -717,7 +731,7 @@ SP протокол порождает меньше вызовов записе
 невозможности online аутентификации нод.
 
 @item
-Явная синхронизация (fsync) директорий для гарантированного
+Явная синхронизация (@code{fsync}) директорий для гарантированного
 переименования файлов.
 
 @end itemize
index 861ba7fed8a08402053876edbcbe33a9dc395451..93edf29690d745168e9a56e4148dd3a7075241a0 100644 (file)
@@ -4,6 +4,19 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 8_6_0
+@section Release 8.6.0
+@itemize
+
+@item
+Ability to turn @code{fsync} operation off using @env{$NNCPNOSYNC=1}
+environment variable.
+
+@item
+Added various indices in documentation, that should help searching in it.
+
+@end itemize
+
 @node Release 8_5_0
 @section Release 8.5.0
 @itemize
@@ -298,7 +311,7 @@ command.
 @itemize
 
 @item
-Fixed failing directories fsync after @file{.seen} file creation.
+Fixed failing directories @code{fsync} after @file{.seen} file creation.
 
 @end itemize
 
@@ -700,7 +713,7 @@ Bugfix: private and public Noise keys were swapped in newly created
 configuration files, that lead to inability to authenticate online peers.
 
 @item
-Explicit directories fsync-ing for guaranteed files renaming.
+Explicit directories @code{fsync}-ing for guaranteed files renaming.
 
 @end itemize
 
index 0937ab0f4f51d5eef96e6f2dd9d2b0d54cd57e7a..98bc80c1a4c35c249f91d2cfa1e2488c9daed480 100644 (file)
@@ -38,6 +38,7 @@ const (
        CfgPathEnv  = "NNCPCFG"
        CfgSpoolEnv = "NNCPSPOOL"
        CfgLogEnv   = "NNCPLOG"
+       CfgNoSync   = "NNCPNOSYNC"
 )
 
 var (
index d5603a99b1ab8cc2082cc219f46a3fb065321c14..071ecea039f4ff0fb5af801710790d4fa56f794c 100644 (file)
@@ -483,8 +483,10 @@ func main() {
                                        if err = bufTmp.Flush(); err != nil {
                                                log.Fatalln("Error during flushing:", err)
                                        }
-                                       if err = tmp.Sync(); err != nil {
-                                               log.Fatalln("Error during syncing:", err)
+                                       if !nncp.NoSync {
+                                               if err = tmp.Sync(); err != nil {
+                                                       log.Fatalln("Error during syncing:", err)
+                                               }
                                        }
                                        if err = tmp.Close(); err != nil {
                                                log.Fatalln("Error during closing:", err)
index 0882d285c597262f637e7b9bbc3c6d53f44da201..d095f95d041ba4b1c99cc2513828f2e2cce057b7 100644 (file)
@@ -237,8 +237,10 @@ func process(ctx *nncp.Ctx, path string, keep, dryRun, stdout, dumpMeta bool) bo
                log.Fatalln("Can not flush:", err)
        }
        if tmp != nil {
-               if err = tmp.Sync(); err != nil {
-                       log.Fatalln("Can not sync:", err)
+               if !nncp.NoSync {
+                       if err = tmp.Sync(); err != nil {
+                               log.Fatalln("Can not sync:", err)
+                       }
                }
                if err = tmp.Close(); err != nil {
                        log.Fatalln("Can not close:", err)
index 41e8c61c8e157f087d9fa5096990d92231bf316d..68aa102aa68970c117444499bf51b90951f75b31 100644 (file)
@@ -477,13 +477,15 @@ Tx:
                                isBad = true
                                continue
                        }
-                       if err = tmp.Sync(); err != nil {
-                               tmp.Close()
-                               ctx.LogE("xfer-tx-sync", les, err, func(les nncp.LEs) string {
-                                       return logMsg(les) + ": syncing"
-                               })
-                               isBad = true
-                               continue
+                       if !nncp.NoSync {
+                               if err = tmp.Sync(); err != nil {
+                                       tmp.Close()
+                                       ctx.LogE("xfer-tx-sync", les, err, func(les nncp.LEs) string {
+                                               return logMsg(les) + ": syncing"
+                                       })
+                                       isBad = true
+                                       continue
+                               }
                        }
                        if err = tmp.Close(); err != nil {
                                ctx.LogE("xfer-tx-close", les, err, func(les nncp.LEs) string {
index e8e477cff9da8b5aa83b5ef75697142bd5c28cb8..772d92c4d729bb4fbec8ba066ae67a3438e45807 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -1461,13 +1461,15 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) {
                                        humanize.IBytes(uint64(fullsize)),
                                )
                        }
-                       err = fd.Sync()
-                       if err != nil {
-                               state.Ctx.LogE("sp-file-sync", lesp, err, func(les LEs) string {
-                                       return logMsg(les) + ": syncing"
-                               })
-                               state.closeFd(filePathPart)
-                               continue
+                       if !NoSync {
+                               err = fd.Sync()
+                               if err != nil {
+                                       state.Ctx.LogE("sp-file-sync", lesp, err, func(les LEs) string {
+                                               return logMsg(les) + ": syncing"
+                                       })
+                                       state.closeFd(filePathPart)
+                                       continue
+                               }
                        }
                        if hasherAndOffset != nil {
                                delete(state.fileHashers, filePath)
index aee58677518a562c55d7be7c56931061b2dbf83c..4a43eaa41a2675969f0d7109fe362f5304c93866 100644 (file)
@@ -28,6 +28,12 @@ import (
        "time"
 )
 
+var NoSync bool
+
+func init() {
+       NoSync = os.Getenv(CfgNoSync) != ""
+}
+
 func TempFile(dir, prefix string) (*os.File, error) {
        // Assume that probability of suffix collision is negligible
        suffix := strconv.FormatInt(time.Now().UnixNano()+int64(os.Getpid()), 16)
@@ -77,6 +83,9 @@ func (tmp *TmpFileWHash) Cancel() {
 }
 
 func DirSync(dirPath string) error {
+       if NoSync {
+               return nil
+       }
        fd, err := os.Open(dirPath)
        if err != nil {
                return err
@@ -102,9 +111,11 @@ func (tmp *TmpFileWHash) Commit(dir string) error {
                tmp.Fd.Close()
                return err
        }
-       if err = tmp.Fd.Sync(); err != nil {
-               tmp.Fd.Close()
-               return err
+       if !NoSync {
+               if err = tmp.Fd.Sync(); err != nil {
+                       tmp.Fd.Close()
+                       return err
+               }
        }
        if err = tmp.Fd.Close(); err != nil {
                return err
index bdfcb31aad6d4ec44b0cc18dd17df32ce0ad4dde..e383257db77c43e31ddd8127160276526376983e 100644 (file)
@@ -329,16 +329,18 @@ func jobProcess(
                                })
                                return err
                        }
-                       if err = tmp.Sync(); err != nil {
-                               tmp.Close()
-                               ctx.LogE("rx-sync", les, err, func(les LEs) string {
-                                       return fmt.Sprintf(
-                                               "Tossing file %s/%s (%s): %s: syncing",
-                                               sender.Name, pktName,
-                                               humanize.IBytes(pktSize), dst,
-                                       )
-                               })
-                               return err
+                       if !NoSync {
+                               if err = tmp.Sync(); err != nil {
+                                       tmp.Close()
+                                       ctx.LogE("rx-sync", les, err, func(les LEs) string {
+                                               return fmt.Sprintf(
+                                                       "Tossing file %s/%s (%s): %s: syncing",
+                                                       sender.Name, pktName,
+                                                       humanize.IBytes(pktSize), dst,
+                                               )
+                                       })
+                                       return err
+                               }
                        }
                        if err = tmp.Close(); err != nil {
                                ctx.LogE("rx-close", les, err, func(les LEs) string {