github.com/yandex-cloud/geesefs@v0.40.9/internal/cfg/config.go (about)

     1  // Copyright 2015 - 2019 Ka-Hing Cheung
     2  // Copyright 2015 - 2017 Google Inc. All Rights Reserved.
     3  // Copyright 2019 Databricks
     4  // Copyright 2021 Yandex LLC
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package cfg
    19  
    20  import (
    21  	"mime"
    22  	"net"
    23  	"net/http"
    24  	"os"
    25  	"strings"
    26  	"time"
    27  )
    28  
    29  type PartSizeConfig struct {
    30  	PartSize uint64
    31  	PartCount uint64
    32  }
    33  
    34  type NodeConfig struct {
    35  	Id uint64
    36  	Address string
    37  }
    38  
    39  type FlagStorage struct {
    40  	// File system
    41  	MountOptions      []string
    42  	MountPoint        string
    43  	MountPointArg     string
    44  	MountPointCreated string
    45  
    46  	DirMode  os.FileMode
    47  	FileMode os.FileMode
    48  	Uid      uint32
    49  	Gid      uint32
    50  	Setuid   int
    51  	Setgid   int
    52  
    53  	// Common Backend Config
    54  	UseContentType bool
    55  	Endpoint       string
    56  	Backend        interface{}
    57  
    58  	// Tuning
    59  	MemoryLimit           uint64
    60  	EntryLimit            int
    61  	GCInterval            uint64
    62  	Cheap                 bool
    63  	ExplicitDir           bool
    64  	NoDirObject           bool
    65  	MaxFlushers           int64
    66  	MaxParallelParts      int
    67  	MaxParallelCopy       int
    68  	StatCacheTTL          time.Duration
    69  	HTTPTimeout           time.Duration
    70  	ReadRetryInterval     time.Duration
    71  	ReadRetryMultiplier   float64
    72  	ReadRetryMax          time.Duration
    73  	ReadRetryAttempts     int
    74  	RetryInterval         time.Duration
    75  	ReadAheadKB           uint64
    76  	SmallReadCount        uint64
    77  	SmallReadCutoffKB     uint64
    78  	ReadAheadSmallKB      uint64
    79  	LargeReadCutoffKB     uint64
    80  	ReadAheadLargeKB      uint64
    81  	ReadAheadParallelKB   uint64
    82  	ReadMergeKB           uint64
    83  	SinglePartMB          uint64
    84  	MaxMergeCopyMB        uint64
    85  	IgnoreFsync           bool
    86  	FsyncOnClose          bool
    87  	EnablePerms           bool
    88  	EnableSpecials        bool
    89  	EnableMtime           bool
    90  	DisableXattr          bool
    91  	UidAttr               string
    92  	GidAttr               string
    93  	FileModeAttr          string
    94  	RdevAttr              string
    95  	MtimeAttr             string
    96  	SymlinkAttr           string
    97  	RefreshAttr           string
    98  	RefreshFilename       string
    99  	FlushFilename         string
   100  	CachePath             string
   101  	MaxDiskCacheFD        int64
   102  	CacheFileMode         os.FileMode
   103  	PartSizes             []PartSizeConfig
   104  	UsePatch              bool
   105  	DropPatchConflicts    bool
   106  
   107  	// Debugging
   108  	DebugMain  bool
   109  	DebugFuse  bool
   110  	DebugS3    bool
   111  	PProf      string
   112  	Foreground bool
   113  	LogFile    string
   114  	DebugGrpc  bool
   115  
   116  	StatsInterval time.Duration
   117  
   118  	// Cluster Mode
   119  	ClusterMode    bool
   120  	ClusterGrpcReflection bool
   121  	ClusterMe      *NodeConfig
   122  	ClusterPeers   []*NodeConfig
   123  }
   124  
   125  func (flags *FlagStorage) GetMimeType(fileName string) (retMime *string) {
   126  	if flags.UseContentType {
   127  		dotPosition := strings.LastIndex(fileName, ".")
   128  		if dotPosition == -1 {
   129  			return nil
   130  		}
   131  		mimeType := mime.TypeByExtension(fileName[dotPosition:])
   132  		if mimeType == "" {
   133  			return nil
   134  		}
   135  		semicolonPosition := strings.LastIndex(mimeType, ";")
   136  		if semicolonPosition == -1 {
   137  			return &mimeType
   138  		}
   139  		s := mimeType[:semicolonPosition]
   140  		retMime = &s
   141  	}
   142  
   143  	return
   144  }
   145  
   146  func (flags *FlagStorage) Cleanup() {
   147  	if flags.MountPointCreated != "" && flags.MountPointCreated != flags.MountPointArg {
   148  		err := os.Remove(flags.MountPointCreated)
   149  		if err != nil {
   150  			log.Errorf("rmdir %v = %v", flags.MountPointCreated, err)
   151  		}
   152  	}
   153  }
   154  
   155  var defaultHTTPTransport = http.Transport{
   156  	Proxy: http.ProxyFromEnvironment,
   157  	DialContext: (&net.Dialer{
   158  		Timeout:   30 * time.Second,
   159  		KeepAlive: 30 * time.Second,
   160  		DualStack: true,
   161  	}).DialContext,
   162  	MaxIdleConns:          1000,
   163  	MaxIdleConnsPerHost:   1000,
   164  	IdleConnTimeout:       90 * time.Second,
   165  	TLSHandshakeTimeout:   10 * time.Second,
   166  	ExpectContinueTimeout: 10 * time.Second,
   167  }
   168  
   169  func GetHTTPTransport() *http.Transport {
   170  	return &defaultHTTPTransport
   171  }