You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.6 KiB
81 lines
2.6 KiB
9 years ago
|
/*
|
||
4 years ago
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
||
9 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
7 years ago
|
import (
|
||
7 years ago
|
"context"
|
||
7 years ago
|
"path"
|
||
5 years ago
|
|
||
|
"github.com/minio/minio/pkg/sync/errgroup"
|
||
7 years ago
|
)
|
||
9 years ago
|
|
||
8 years ago
|
// getLoadBalancedDisks - fetches load balanced (sufficiently randomized) disk slice.
|
||
4 years ago
|
func (er erasureObjects) getLoadBalancedDisks() (newDisks []StorageAPI) {
|
||
|
disks := er.getDisks()
|
||
9 years ago
|
// Based on the random shuffling return back randomized disks.
|
||
5 years ago
|
for _, i := range hashOrder(UTCNow().String(), len(disks)) {
|
||
|
newDisks = append(newDisks, disks[i-1])
|
||
9 years ago
|
}
|
||
5 years ago
|
return newDisks
|
||
9 years ago
|
}
|
||
|
|
||
|
// This function does the following check, suppose
|
||
|
// object is "a/b/c/d", stat makes sure that objects ""a/b/c""
|
||
|
// "a/b" and "a" do not exist.
|
||
4 years ago
|
func (er erasureObjects) parentDirIsObject(ctx context.Context, bucket, parent string) bool {
|
||
9 years ago
|
var isParentDirObject func(string) bool
|
||
|
isParentDirObject = func(p string) bool {
|
||
5 years ago
|
if p == "." || p == SlashSeparator {
|
||
9 years ago
|
return false
|
||
|
}
|
||
4 years ago
|
if er.isObject(ctx, bucket, p) {
|
||
7 years ago
|
// If there is already a file at prefix "p", return true.
|
||
9 years ago
|
return true
|
||
|
}
|
||
|
// Check if there is a file as one of the parent paths.
|
||
|
return isParentDirObject(path.Dir(p))
|
||
|
}
|
||
|
return isParentDirObject(parent)
|
||
|
}
|
||
|
|
||
9 years ago
|
// isObject - returns `true` if the prefix is an object i.e if
|
||
4 years ago
|
// `xl.meta` exists at the leaf, false otherwise.
|
||
|
func (er erasureObjects) isObject(ctx context.Context, bucket, prefix string) (ok bool) {
|
||
|
storageDisks := er.getDisks()
|
||
5 years ago
|
|
||
|
g := errgroup.WithNErrs(len(storageDisks))
|
||
|
|
||
5 years ago
|
for index := range storageDisks {
|
||
|
index := index
|
||
5 years ago
|
g.Go(func() error {
|
||
5 years ago
|
if storageDisks[index] == nil {
|
||
|
return errDiskNotFound
|
||
|
}
|
||
6 years ago
|
// Check if 'prefix' is an object on this 'disk', else continue the check the next disk
|
||
4 years ago
|
return storageDisks[index].CheckFile(bucket, prefix)
|
||
5 years ago
|
}, index)
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
// NOTE: Observe we are not trying to read `xl.meta` and figure out the actual
|
||
6 years ago
|
// quorum intentionally, but rely on the default case scenario. Actual quorum
|
||
|
// verification will happen by top layer by using getObjectInfo() and will be
|
||
|
// ignored if necessary.
|
||
5 years ago
|
readQuorum := getReadQuorum(len(storageDisks))
|
||
6 years ago
|
|
||
4 years ago
|
return reduceReadQuorumErrs(ctx, g.Wait(), objectOpIgnoredErrs, readQuorum) == nil
|
||
9 years ago
|
}
|