storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/config/heal/heal.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package heal
    18  
    19  import (
    20  	"fmt"
    21  	"strconv"
    22  	"time"
    23  
    24  	"storj.io/minio/cmd/config"
    25  	"storj.io/minio/pkg/env"
    26  )
    27  
    28  // Compression environment variables
    29  const (
    30  	Bitrot  = "bitrotscan"
    31  	Sleep   = "max_sleep"
    32  	IOCount = "max_io"
    33  
    34  	EnvBitrot  = "MINIO_HEAL_BITROTSCAN"
    35  	EnvSleep   = "MINIO_HEAL_MAX_SLEEP"
    36  	EnvIOCount = "MINIO_HEAL_MAX_IO"
    37  )
    38  
    39  // Config represents the heal settings.
    40  type Config struct {
    41  	// Bitrot will perform bitrot scan on local disk when checking objects.
    42  	Bitrot bool `json:"bitrotscan"`
    43  	// maximum sleep duration between objects to slow down heal operation.
    44  	Sleep   time.Duration `json:"sleep"`
    45  	IOCount int           `json:"iocount"`
    46  }
    47  
    48  var (
    49  	// DefaultKVS - default KV config for heal settings
    50  	DefaultKVS = config.KVS{
    51  		config.KV{
    52  			Key:   Bitrot,
    53  			Value: config.EnableOff,
    54  		},
    55  		config.KV{
    56  			Key:   Sleep,
    57  			Value: "1s",
    58  		},
    59  		config.KV{
    60  			Key:   IOCount,
    61  			Value: "10",
    62  		},
    63  	}
    64  
    65  	// Help provides help for config values
    66  	Help = config.HelpKVS{
    67  		config.HelpKV{
    68  			Key:         Bitrot,
    69  			Description: `perform bitrot scan on disks when checking objects during scanner`,
    70  			Optional:    true,
    71  			Type:        "on|off",
    72  		},
    73  		config.HelpKV{
    74  			Key:         Sleep,
    75  			Description: `maximum sleep duration between objects to slow down heal operation. eg. 2s`,
    76  			Optional:    true,
    77  			Type:        "duration",
    78  		},
    79  		config.HelpKV{
    80  			Key:         IOCount,
    81  			Description: `maximum IO requests allowed between objects to slow down heal operation. eg. 3`,
    82  			Optional:    true,
    83  			Type:        "int",
    84  		},
    85  	}
    86  )
    87  
    88  // LookupConfig - lookup config and override with valid environment settings if any.
    89  func LookupConfig(kvs config.KVS) (cfg Config, err error) {
    90  	if err = config.CheckValidKeys(config.HealSubSys, kvs, DefaultKVS); err != nil {
    91  		return cfg, err
    92  	}
    93  	cfg.Bitrot, err = config.ParseBool(env.Get(EnvBitrot, kvs.Get(Bitrot)))
    94  	if err != nil {
    95  		return cfg, fmt.Errorf("'heal:bitrotscan' value invalid: %w", err)
    96  	}
    97  	cfg.Sleep, err = time.ParseDuration(env.Get(EnvSleep, kvs.Get(Sleep)))
    98  	if err != nil {
    99  		return cfg, fmt.Errorf("'heal:max_sleep' value invalid: %w", err)
   100  	}
   101  	cfg.IOCount, err = strconv.Atoi(env.Get(EnvIOCount, kvs.Get(IOCount)))
   102  	if err != nil {
   103  		return cfg, fmt.Errorf("'heal:max_io' value invalid: %w", err)
   104  	}
   105  	return cfg, nil
   106  }