github.com/cyverse/go-irodsclient@v0.13.2/fs/config.go (about)

     1  package fs
     2  
     3  import "time"
     4  
     5  const (
     6  	// FileSystemConnectionErrorTimeoutDefault is a default timeout value of connection error
     7  	FileSystemConnectionErrorTimeoutDefault = 1 * time.Minute
     8  	// FileSystemConnectionInitNumberDefault is a default value of connection init number
     9  	FileSystemConnectionInitNumberDefault = 0
    10  	// FileSystemConnectionMaxMin is a minimum number of connection max value
    11  	FileSystemConnectionMaxMin = 5
    12  	// FileSystemConnectionMaxDefault is a default number of connection max value
    13  	FileSystemConnectionMaxDefault = 10
    14  	// FileSystemConnectionMetaDefault is a default number of metadata operation connection
    15  	FileSystemConnectionMetaDefault = 2
    16  	// FileSystemConnectionLifespanDefault is a default lifespan of a connection
    17  	FileSystemConnectionLifespanDefault = 1 * time.Hour
    18  	// FileSystemTimeoutDefault is a default value of timeout
    19  	FileSystemTimeoutDefault = 5 * time.Minute
    20  	// FileSystemTCPBufferSizeDefault is a default value of tcp buffer size
    21  	FileSystemTCPBufferSizeDefault = 4 * 1024 * 1024
    22  )
    23  
    24  // FileSystemConfig is a struct for file system configuration
    25  type FileSystemConfig struct {
    26  	ApplicationName        string
    27  	ConnectionErrorTimeout time.Duration
    28  	ConnectionInitNumber   int
    29  	ConnectionLifespan     time.Duration
    30  	OperationTimeout       time.Duration
    31  	ConnectionIdleTimeout  time.Duration
    32  	ConnectionMax          int
    33  	TCPBufferSize          int
    34  	CacheTimeout           time.Duration
    35  	CacheCleanupTime       time.Duration
    36  	CacheTimeoutSettings   []MetadataCacheTimeoutSetting
    37  	// for mysql iCAT backend, this should be true.
    38  	// for postgresql iCAT backend, this can be false.
    39  	StartNewTransaction bool
    40  	// determine if we will invalidate parent dir's entry cache
    41  	// at subdir/file creation/deletion
    42  	// turn to false to allow short cache inconsistency
    43  	InvalidateParentEntryCacheImmediately bool
    44  }
    45  
    46  // NewFileSystemConfig create a FileSystemConfig
    47  func NewFileSystemConfig(applicationName string, connectionErrorTimeout time.Duration, connectionInitNumber int, connectionLifespan time.Duration, operationTimeout time.Duration, connectionIdleTimeout time.Duration, connectionMax int, tcpBufferSize int, cacheTimeout time.Duration, cacheCleanupTime time.Duration, cacheTimeoutSettings []MetadataCacheTimeoutSetting, startNewTransaction bool, invalidateParentEntryCacheImmediately bool) *FileSystemConfig {
    48  	connMax := connectionMax
    49  	if connMax < FileSystemConnectionMaxMin {
    50  		connMax = FileSystemConnectionMaxMin
    51  	}
    52  
    53  	return &FileSystemConfig{
    54  		ApplicationName:                       applicationName,
    55  		ConnectionErrorTimeout:                connectionErrorTimeout,
    56  		ConnectionInitNumber:                  connectionInitNumber,
    57  		ConnectionLifespan:                    connectionLifespan,
    58  		OperationTimeout:                      operationTimeout,
    59  		ConnectionIdleTimeout:                 connectionIdleTimeout,
    60  		ConnectionMax:                         connMax,
    61  		TCPBufferSize:                         tcpBufferSize,
    62  		CacheTimeout:                          cacheTimeout,
    63  		CacheCleanupTime:                      cacheCleanupTime,
    64  		CacheTimeoutSettings:                  cacheTimeoutSettings,
    65  		StartNewTransaction:                   startNewTransaction,
    66  		InvalidateParentEntryCacheImmediately: invalidateParentEntryCacheImmediately,
    67  	}
    68  }
    69  
    70  // NewFileSystemConfigWithDefault create a FileSystemConfig with a default settings
    71  func NewFileSystemConfigWithDefault(applicationName string) *FileSystemConfig {
    72  	return &FileSystemConfig{
    73  		ApplicationName:                       applicationName,
    74  		ConnectionErrorTimeout:                FileSystemConnectionErrorTimeoutDefault,
    75  		ConnectionInitNumber:                  FileSystemConnectionInitNumberDefault,
    76  		ConnectionLifespan:                    FileSystemConnectionLifespanDefault,
    77  		OperationTimeout:                      FileSystemTimeoutDefault,
    78  		ConnectionIdleTimeout:                 FileSystemTimeoutDefault,
    79  		ConnectionMax:                         FileSystemConnectionMaxDefault,
    80  		TCPBufferSize:                         FileSystemTCPBufferSizeDefault,
    81  		CacheTimeout:                          FileSystemTimeoutDefault,
    82  		CacheTimeoutSettings:                  []MetadataCacheTimeoutSetting{},
    83  		CacheCleanupTime:                      FileSystemTimeoutDefault,
    84  		StartNewTransaction:                   true,
    85  		InvalidateParentEntryCacheImmediately: true,
    86  	}
    87  }