Skip to content

Commit

Permalink
Optimized List objects v2 for metadata (#1175)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
  • Loading branch information
dvaldivia committed Nov 2, 2021
1 parent dfd0d08 commit 2f91713
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
21 changes: 16 additions & 5 deletions portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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/>.

import React, { useEffect, useState, Fragment } from "react";
import React, { Fragment, useEffect, useState } from "react";
import Grid from "@mui/material/Grid";
import {
Button,
Expand Down Expand Up @@ -74,6 +74,9 @@ const styles = (theme: Theme) =>
},
error: {
color: "#b53b4b",
border: "1px solid #b53b4b",
padding: 8,
borderRadius: 3,
},
...modalBasic,
});
Expand Down Expand Up @@ -298,10 +301,18 @@ const AddBucket = ({
<br />
{!distributedSetup && (
<Fragment>
<small className={classes.error}>
Some these features are disabled as server is running in
non-erasure coded mode.
</small>
<div className={classes.error}>
These features are unavailable in a single-disk setup.
<br />
Please deploy a server in{" "}
<a
href="https://docs.min.io/minio/baremetal/installation/deploy-minio-distributed.html?ref=con"
target="_blank"
>
Distributed Mode
</a>{" "}
to use these features.
</div>
<br />
<br />
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const ObjectDetails = ({
const [versions, setVersions] = useState<IFileInfo[]>([]);
const [filterVersion, setFilterVersion] = useState<string>("");
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
const [metadataLoad, setMetadataLoad] = useState<boolean>(false);
const [metadataLoad, setMetadataLoad] = useState<boolean>(true);
const [metadata, setMetadata] = useState<any>({});
const [selectedTab, setSelectedTab] = useState<number>(0);

Expand Down Expand Up @@ -292,7 +292,6 @@ const ObjectDetails = ({
}

setLoadObjectData(false);
setMetadataLoad(true);
})
.catch((error: ErrorResponseHandler) => {
setErrorSnackMessage(error);
Expand Down
3 changes: 0 additions & 3 deletions restapi/user_bucket_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ func setBucketQuota(ctx context.Context, ac *AdminClient, bucket *string, bucket
}

func getBucketQuotaResponse(session *models.Principal, params user_api.GetBucketQuotaParams) (*models.BucketQuota, *models.Error) {
if !isErasureBackend() {
return &models.BucketQuota{}, nil
}

mAdmin, err := NewMinioAdminClient(session)
if err != nil {
Expand Down
23 changes: 0 additions & 23 deletions restapi/user_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
"encoding/json"
"fmt"
"strings"
"sync"
"time"

"github.com/minio/madmin-go"
"github.com/minio/mc/cmd"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio-go/v7"
Expand Down Expand Up @@ -202,10 +200,6 @@ func setBucketVersioningResponse(session *models.Principal, bucketName string, p
}

func getBucketReplicationResponse(session *models.Principal, bucketName string) (*models.BucketReplicationResponse, error) {
if !isErasureBackend() {
return &models.BucketReplicationResponse{}, nil
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()

Expand Down Expand Up @@ -256,12 +250,6 @@ func getBucketReplicationResponse(session *models.Principal, bucketName string)
}

func getBucketVersionedResponse(session *models.Principal, bucketName string) (*models.BucketVersioningResponse, error) {
if !isErasureBackend() {
return &models.BucketVersioningResponse{
IsVersioned: false,
}, nil
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()

Expand All @@ -288,24 +276,13 @@ func getBucketVersionedResponse(session *models.Principal, bucketName string) (*
return bucketVResponse, nil
}

var serverBackendType madmin.BackendType
var serverBackendOnce sync.Once

func isErasureBackend() bool {
return serverBackendType == madmin.Erasure
}

// getAccountInfo fetches a list of all buckets allowed to that particular client from MinIO Servers
func getAccountInfo(ctx context.Context, client MinioAdmin) ([]*models.Bucket, error) {
info, err := client.AccountInfo(ctx)
if err != nil {
return []*models.Bucket{}, err
}

serverBackendOnce.Do(func() {
serverBackendType = info.Server.Type
})

var bucketInfos []*models.Bucket
for _, bucket := range info.Buckets {

Expand Down
13 changes: 11 additions & 2 deletions restapi/user_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func getListObjectsResponse(session *models.Principal, params user_api.ListObjec
if params.Recursive != nil {
recursive = *params.Recursive
}
if isErasureBackend() && params.WithVersions != nil {
if params.WithVersions != nil {
withVersions = *params.WithVersions
}
if params.WithMetadata != nil {
Expand Down Expand Up @@ -230,7 +230,16 @@ func getListObjectsResponse(session *models.Principal, params user_api.ListObjec
// listBucketObjects gets an array of objects in a bucket
func listBucketObjects(ctx context.Context, client MinioClient, bucketName string, prefix string, recursive, withVersions bool, withMetadata bool) ([]*models.BucketObject, error) {
var objects []*models.BucketObject
for lsObj := range client.listObjects(ctx, bucketName, minio.ListObjectsOptions{Prefix: prefix, Recursive: recursive, WithVersions: withVersions, WithMetadata: withMetadata}) {
opts := minio.ListObjectsOptions{
Prefix: prefix,
Recursive: recursive,
WithVersions: withVersions,
WithMetadata: withMetadata,
}
if withMetadata {
opts.MaxKeys = 1
}
for lsObj := range client.listObjects(ctx, bucketName, opts) {
if lsObj.Err != nil {
return nil, lsObj.Err
}
Expand Down

0 comments on commit 2f91713

Please sign in to comment.