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

     1  /*
     2   * MinIO Cloud Storage, (C) 2016-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 cmd
    18  
    19  import (
    20  	"context"
    21  	"io"
    22  
    23  	"storj.io/minio/cmd/logger"
    24  )
    25  
    26  // Heal heals the shard files on non-nil writers. Note that the quorum passed is 1
    27  // as healing should continue even if it has been successful healing only one shard file.
    28  func (e Erasure) Heal(ctx context.Context, readers []io.ReaderAt, writers []io.Writer, size int64) error {
    29  	r, w := io.Pipe()
    30  	go func() {
    31  		if _, err := e.Decode(ctx, w, readers, 0, size, size, nil); err != nil {
    32  			w.CloseWithError(err)
    33  			return
    34  		}
    35  		w.Close()
    36  	}()
    37  	buf := make([]byte, e.blockSize)
    38  	// quorum is 1 because CreateFile should continue writing as long as we are writing to even 1 disk.
    39  	n, err := e.Encode(ctx, r, writers, buf, 1)
    40  	if err != nil {
    41  		return err
    42  	}
    43  	if n != size {
    44  		logger.LogIf(ctx, errLessData)
    45  		return errLessData
    46  	}
    47  	return nil
    48  }