2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-17 14:36:33 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-08-17 14:36:33 -04:00
|
|
|
|
2017-09-20 12:50:27 -04:00
|
|
|
import (
|
2018-04-05 18:04:40 -04:00
|
|
|
"context"
|
2018-08-06 18:14:08 -04:00
|
|
|
"io"
|
2017-11-25 14:58:29 -05:00
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2021-05-04 13:12:08 -04:00
|
|
|
"github.com/minio/minio/pkg/bpool"
|
2021-05-11 12:18:37 -04:00
|
|
|
xioutil "github.com/minio/minio/pkg/ioutil"
|
2017-09-20 12:50:27 -04:00
|
|
|
)
|
|
|
|
|
2018-08-24 02:35:37 -04:00
|
|
|
// Heal heals the shard files on non-nil writers. Note that the quorum passed is 1
|
2018-08-06 18:14:08 -04:00
|
|
|
// as healing should continue even if it has been successful healing only one shard file.
|
2021-05-04 13:12:08 -04:00
|
|
|
func (e Erasure) Heal(ctx context.Context, readers []io.ReaderAt, writers []io.Writer, size int64, bp *bpool.BytePoolCap) error {
|
2021-05-11 12:18:37 -04:00
|
|
|
r, w := xioutil.WaitPipe()
|
2018-08-06 18:14:08 -04:00
|
|
|
go func() {
|
2021-05-04 13:12:08 -04:00
|
|
|
_, err := e.Decode(ctx, w, readers, 0, size, size, nil)
|
|
|
|
w.CloseWithError(err)
|
2018-08-06 18:14:08 -04:00
|
|
|
}()
|
2021-05-04 13:12:08 -04:00
|
|
|
|
|
|
|
// Fetch buffer for I/O, returns from the pool if not allocates a new one and returns.
|
|
|
|
var buffer []byte
|
|
|
|
switch {
|
|
|
|
case size == 0:
|
|
|
|
buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF
|
|
|
|
case size >= e.blockSize:
|
|
|
|
buffer = bp.Get()
|
|
|
|
defer bp.Put(buffer)
|
|
|
|
case size < e.blockSize:
|
|
|
|
// No need to allocate fully blockSizeV1 buffer if the incoming data is smaller.
|
|
|
|
buffer = make([]byte, size, 2*size+int64(e.parityBlocks+e.dataBlocks-1))
|
2016-08-17 14:36:33 -04:00
|
|
|
}
|
2021-05-04 13:12:08 -04:00
|
|
|
|
|
|
|
// quorum is 1 because CreateFile should continue writing as long as we are writing to even 1 disk.
|
|
|
|
n, err := e.Encode(ctx, r, writers, buffer, 1)
|
|
|
|
if err == nil && n != size {
|
2018-08-06 18:14:08 -04:00
|
|
|
logger.LogIf(ctx, errLessData)
|
2021-05-04 13:12:08 -04:00
|
|
|
err = errLessData
|
2017-09-28 18:57:19 -04:00
|
|
|
}
|
2021-05-04 13:12:08 -04:00
|
|
|
r.CloseWithError(err)
|
|
|
|
return err
|
2017-09-28 18:57:19 -04:00
|
|
|
}
|