diff --git a/model/const.go b/model/const.go index e105d1cc7..1cec8487a 100644 --- a/model/const.go +++ b/model/const.go @@ -218,6 +218,10 @@ const ( ListObjectsDelimiterQuery = "delimiter" // ListObjectsPrefixQuery defines limits the response to keys that begin with the specified prefix ListObjectsPrefixQuery = "prefix" + // GetBucketMetaByNameQuery defines get bucket metadata query, which is used to route request + GetBucketMetaByNameQuery = "bucket-meta" + // GetObjectMetaByNameQuery defines get object metadata query, which is used to route request + GetObjectMetaByNameQuery = "object-meta" // StartTimestampUs defines start timestamp in microsecond, which is used by list read record, [start_ts,end_ts) StartTimestampUs = "start-timestamp" // EndTimestampUs defines end timestamp in microsecond, which is used by list read record, [start_ts,end_ts) diff --git a/proto/service/metadata/types/metadata.proto b/proto/service/metadata/types/metadata.proto index 751b254e0..3537077ff 100644 --- a/proto/service/metadata/types/metadata.proto +++ b/proto/service/metadata/types/metadata.proto @@ -147,16 +147,16 @@ message GetPaymentByBucketIDRequest { bool is_full_list = 2; } -// GetBucketWithPaymentRequest is request type for the GetBucketWithPayment RPC method -message GetBucketWithPaymentRequest { +// GetBucketMetaByNameRequest is request type for the GetBucketMetaByName RPC method +message GetBucketMetaByNameRequest { // bucket_name is the name of the bucket string bucket_name = 1; // is_full_list indicates whether this request can get the private buckets information bool is_full_list = 2; } -// GetBucketWithPaymentResponse is response type for the GetBucketWithPayment RPC method -message GetBucketWithPaymentResponse { +// GetBucketMetaByNameResponse is response type for the GetBucketMetaByName RPC method +message GetBucketMetaByNameResponse { // bucket defines the information of a bucket Bucket bucket = 1; // stream_record defines stream payment record of a stream account @@ -267,6 +267,6 @@ service MetadataService { rpc GetPaymentByBucketID(GetPaymentByBucketIDRequest) returns (GetPaymentByBucketIDResponse) {}; // VerifyPermission Verify the input items permission. rpc VerifyPermission(bnbchain.greenfield.storage.QueryVerifyPermissionRequest) returns (bnbchain.greenfield.storage.QueryVerifyPermissionResponse) {}; - // GetBucketWithPayment get bucket info with payment info by a bucket name - rpc GetBucketWithPayment(GetBucketWithPaymentRequest) returns (GetBucketWithPaymentResponse) {}; + // GetBucketMetaByName get bucket info with related info such as payment by name + rpc GetBucketMetaByName(GetBucketMetaByNameRequest) returns (GetBucketMetaByNameResponse) {}; } \ No newline at end of file diff --git a/service/gateway/metadata_handler.go b/service/gateway/metadata_handler.go index db54ef436..14cbf4a55 100644 --- a/service/gateway/metadata_handler.go +++ b/service/gateway/metadata_handler.go @@ -201,8 +201,8 @@ func (gateway *Gateway) listObjectsByBucketNameHandler(w http.ResponseWriter, r w.Write(b.Bytes()) } -// getObjectMetaByNameHandler handle get object info by name request -func (gateway *Gateway) getObjectByNameHandler(w http.ResponseWriter, r *http.Request) { +// getObjectMetaByNameHandler handle get object metadata by name request +func (gateway *Gateway) getObjectMetaByNameHandler(w http.ResponseWriter, r *http.Request) { var ( err error b bytes.Buffer @@ -216,9 +216,9 @@ func (gateway *Gateway) getObjectByNameHandler(w http.ResponseWriter, r *http.Re _ = errDescription.errorJSONResponse(w, reqContext) } if errDescription != nil && errDescription.statusCode != http.StatusOK { - log.Errorf("action(%v) statusCode(%v) %v", getObjectByNameRouterName, errDescription.statusCode, reqContext.generateRequestDetail()) + log.Errorf("action(%v) statusCode(%v) %v", getObjectMetaByNameRouterName, errDescription.statusCode, reqContext.generateRequestDetail()) } else { - log.Infof("action(%v) statusCode(200) %v", getObjectByNameRouterName, reqContext.generateRequestDetail()) + log.Infof("action(%v) statusCode(200) %v", getObjectMetaByNameRouterName, reqContext.generateRequestDetail()) } }() @@ -265,8 +265,8 @@ func (gateway *Gateway) getObjectByNameHandler(w http.ResponseWriter, r *http.Re w.Write(b.Bytes()) } -// getBucketWithPaymentHandler handle get bucket info with payment request -func (gateway *Gateway) getBucketWithPaymentHandler(w http.ResponseWriter, r *http.Request) { +// getBucketMetaByNameHandler handle get bucket metadata by name request +func (gateway *Gateway) getBucketMetaByNameHandler(w http.ResponseWriter, r *http.Request) { var ( err error b bytes.Buffer @@ -280,14 +280,14 @@ func (gateway *Gateway) getBucketWithPaymentHandler(w http.ResponseWriter, r *ht _ = errDescription.errorJSONResponse(w, reqContext) } if errDescription != nil && errDescription.statusCode != http.StatusOK { - log.Errorf("action(%v) statusCode(%v) %v", getBucketAndPaymentRouterName, errDescription.statusCode, reqContext.generateRequestDetail()) + log.Errorf("action(%v) statusCode(%v) %v", getBucketMetaByNameRouterName, errDescription.statusCode, reqContext.generateRequestDetail()) } else { - log.Infof("action(%v) statusCode(200) %v", getBucketAndPaymentRouterName, reqContext.generateRequestDetail()) + log.Infof("action(%v) statusCode(200) %v", getBucketMetaByNameRouterName, reqContext.generateRequestDetail()) } }() if gateway.metadata == nil { - log.Error("failed to get bucket and payment info due to not config metadata") + log.Error("failed to get bucket info due to not config metadata") errDescription = NotExistComponentError return } @@ -298,22 +298,22 @@ func (gateway *Gateway) getBucketWithPaymentHandler(w http.ResponseWriter, r *ht return } - req := &metatypes.GetBucketWithPaymentRequest{ + req := &metatypes.GetBucketMetaByNameRequest{ BucketName: reqContext.bucketName, IsFullList: true, } ctx := log.Context(context.Background(), req) - resp, err := gateway.metadata.GetBucketWithPayment(ctx, req) + resp, err := gateway.metadata.GetBucketMetaByName(ctx, req) if err != nil { - log.Errorf("failed to get bucket with payment", "error", err) + log.Errorf("failed to get bucket metadata", "error", err) errDescription = makeErrorDescription(err) return } m := jsonpb.Marshaler{EmitDefaults: true, OrigName: true, EnumsAsInts: true} if err = m.Marshal(&b, resp); err != nil { - log.Errorf("failed to get bucket with payment", "error", err) + log.Errorf("failed to get bucket metadata", "error", err) errDescription = makeErrorDescription(err) return } diff --git a/service/gateway/router.go b/service/gateway/router.go index 856235f89..ed1e55c4c 100644 --- a/service/gateway/router.go +++ b/service/gateway/router.go @@ -26,8 +26,8 @@ const ( queryUploadProgressRouterName = "queryUploadProgress" downloadObjectByUniversalEndpointName = "DownloadObjectByUniversalEndpoint" viewObjectByUniversalEndpointName = "ViewObjectByUniversalEndpoint" - getObjectByNameRouterName = "getObjectByName" - getBucketAndPaymentRouterName = "getBucketAndPayment" + getObjectMetaByNameRouterName = "getObjectMetaByName" + getBucketMetaByNameRouterName = "getBucketMetaByName" ) const ( @@ -62,15 +62,16 @@ func (g *Gateway) registerHandler(r *mux.Router) { Queries(model.UploadProgressQuery, ""). HandlerFunc(g.queryUploadProgressHandler) hostBucketRouter.NewRoute(). - Name(getBucketAndPaymentRouterName). + Name(getBucketMetaByNameRouterName). Methods(http.MethodGet). - Path("/bucket/payment"). - HandlerFunc(g.getBucketWithPaymentHandler) + Queries(model.GetBucketMetaByNameQuery, ""). + HandlerFunc(g.getBucketMetaByNameHandler) hostBucketRouter.NewRoute(). - Name(getObjectByNameRouterName). + Name(getObjectMetaByNameRouterName). Methods(http.MethodGet). - Path("/{object:.+}/metadata"). - HandlerFunc(g.getObjectByNameHandler) + Path("/{object:.+}"). + Queries(model.GetObjectMetaByNameQuery, ""). + HandlerFunc(g.getObjectMetaByNameHandler) hostBucketRouter.NewRoute(). Name(getObjectRouterName). Methods(http.MethodGet). @@ -98,11 +99,9 @@ func (g *Gateway) registerHandler(r *mux.Router) { hostBucketRouter.NotFoundHandler = http.HandlerFunc(g.notFoundHandler) // bucket list router, path style - bucketListRouter := r.Host(g.config.Domain).Subrouter() - bucketListRouter.NewRoute(). + r.Path("/"). Name(getUserBucketsRouterName). Methods(http.MethodGet). - Path("/"). HandlerFunc(g.getUserBucketsHandler) // admin router, path style @@ -157,15 +156,16 @@ func (g *Gateway) registerHandler(r *mux.Router) { Queries(model.UploadProgressQuery, ""). HandlerFunc(g.queryUploadProgressHandler) pathBucketRouter.NewRoute(). - Name(getBucketAndPaymentRouterName). + Name(getBucketMetaByNameRouterName). Methods(http.MethodGet). - Path("/bucket/payment"). - HandlerFunc(g.getBucketWithPaymentHandler) + Queries(model.GetBucketMetaByNameQuery, ""). + HandlerFunc(g.getBucketMetaByNameHandler) pathBucketRouter.NewRoute(). - Name(getObjectByNameRouterName). + Name(getObjectMetaByNameRouterName). Methods(http.MethodGet). - Path("/{object:.+}/metadata"). - HandlerFunc(g.getObjectByNameHandler) + Path("/{object:.+}"). + Queries(model.GetObjectMetaByNameQuery, ""). + HandlerFunc(g.getObjectMetaByNameHandler) pathBucketRouter.NewRoute(). Name(getObjectRouterName). Methods(http.MethodGet). diff --git a/service/metadata/client/metadata_client.go b/service/metadata/client/metadata_client.go index b3e4a58e5..ff20050ad 100644 --- a/service/metadata/client/metadata_client.go +++ b/service/metadata/client/metadata_client.go @@ -165,12 +165,12 @@ func (client *MetadataClient) VerifyPermission(ctx context.Context, in *storaget return resp, nil } -// GetBucketWithPayment get bucket info with its related payment info -func (client *MetadataClient) GetBucketWithPayment(ctx context.Context, in *metatypes.GetBucketWithPaymentRequest, opts ...grpc.CallOption) (*metatypes.GetBucketWithPaymentResponse, error) { - resp, err := client.metadata.GetBucketWithPayment(ctx, in, opts...) +// GetBucketMetaByName get bucket info along with its related info such as payment +func (client *MetadataClient) GetBucketMetaByName(ctx context.Context, in *metatypes.GetBucketMetaByNameRequest, opts ...grpc.CallOption) (*metatypes.GetBucketMetaByNameResponse, error) { + resp, err := client.metadata.GetBucketMetaByName(ctx, in, opts...) ctx = log.Context(ctx, resp) if err != nil { - log.CtxErrorw(ctx, "failed to send get bucket with payment rpc by bucket name", "error", err) + log.CtxErrorw(ctx, "failed to send get bucket meta rpc by bucket name", "error", err) return nil, err } return resp, nil diff --git a/service/metadata/service/bucket.go b/service/metadata/service/bucket.go index 3e97dc87c..79b6886d8 100644 --- a/service/metadata/service/bucket.go +++ b/service/metadata/service/bucket.go @@ -213,7 +213,7 @@ func (metadata *Metadata) ListExpiredBucketsBySp(ctx context.Context, req *metat return resp, nil } -func (metadata *Metadata) GetBucketWithPayment(ctx context.Context, req *metatypes.GetBucketWithPaymentRequest) (resp *metatypes.GetBucketWithPaymentResponse, err error) { +func (metadata *Metadata) GetBucketMetaByName(ctx context.Context, req *metatypes.GetBucketMetaByNameRequest) (resp *metatypes.GetBucketMetaByNameResponse, err error) { var ( bucket *model.Bucket bucketRes *metatypes.Bucket @@ -223,11 +223,13 @@ func (metadata *Metadata) GetBucketWithPayment(ctx context.Context, req *metatyp ) ctx = log.Context(ctx, req) - bucket, streamRecord, err = metadata.bsDB.GetBucketWithPayment(req.GetBucketName(), req.GetIsFullList()) + bucketFullMeta, err := metadata.bsDB.GetBucketMetaByName(req.GetBucketName(), req.GetIsFullList()) if err != nil { - log.CtxErrorw(ctx, "failed to get bucket info with payment info", "error", err) + log.CtxErrorw(ctx, "failed to get bucket meta by name", "error", err) return } + bucket = &bucketFullMeta.Bucket + streamRecord = &bucketFullMeta.StreamRecord if bucket != nil { bucketRes = &metatypes.Bucket{ @@ -278,7 +280,7 @@ func (metadata *Metadata) GetBucketWithPayment(ctx context.Context, req *metatyp } } - resp = &metatypes.GetBucketWithPaymentResponse{Bucket: bucketRes, StreamRecord: streamRecordRes} - log.CtxInfow(ctx, "succeed to get bucket info with payment info") + resp = &metatypes.GetBucketMetaByNameResponse{Bucket: bucketRes, StreamRecord: streamRecordRes} + log.CtxInfow(ctx, "succeed to get bucket meta by name") return resp, nil } diff --git a/store/bsdb/bucket.go b/store/bsdb/bucket.go index 7320a0b86..984c3fcc8 100644 --- a/store/bsdb/bucket.go +++ b/store/bsdb/bucket.go @@ -103,10 +103,10 @@ func (b *BsDBImpl) ListExpiredBucketsBySp(createAt int64, primarySpAddress strin return buckets, err } -func (b *BsDBImpl) GetBucketWithPayment(bucketName string, isFullList bool) (*Bucket, *StreamRecord, error) { +func (b *BsDBImpl) GetBucketMetaByName(bucketName string, isFullList bool) (*BucketFullMeta, error) { var ( - bucketWithPayment *BucketWithPayment - err error + bucketFullMeta *BucketFullMeta + err error ) if isFullList { @@ -114,15 +114,15 @@ func (b *BsDBImpl) GetBucketWithPayment(bucketName string, isFullList bool) (*Bu Select("*"). Joins("left join stream_records on buckets.payment_address = stream_records.account"). Where("buckets.bucket_name = ?", bucketName). - Take(&bucketWithPayment).Error + Take(&bucketFullMeta).Error } else { err = b.db.Table((&Bucket{}).TableName()). Select("*"). Joins("left join stream_records on buckets.payment_address = stream_records.account"). Where("buckets.bucket_name = ? and "+ "buckets.visibility='VISIBILITY_TYPE_PUBLIC_READ'", bucketName). - Take(&bucketWithPayment).Error + Take(&bucketFullMeta).Error } - return &bucketWithPayment.Bucket, &bucketWithPayment.StreamRecord, err + return bucketFullMeta, err } diff --git a/store/bsdb/bucket_schema.go b/store/bsdb/bucket_schema.go index 6cdc6e0d8..b1c4b7700 100644 --- a/store/bsdb/bucket_schema.go +++ b/store/bsdb/bucket_schema.go @@ -56,8 +56,8 @@ func (b *Bucket) TableName() string { return BucketTableName } -// BucketWithPayment is the structure for user bucket with its related payment info -type BucketWithPayment struct { +// BucketFullMeta is the structure for user bucket with its related info +type BucketFullMeta struct { Bucket StreamRecord } diff --git a/store/bsdb/database.go b/store/bsdb/database.go index f1e57f3eb..a3ba825c0 100644 --- a/store/bsdb/database.go +++ b/store/bsdb/database.go @@ -40,8 +40,8 @@ type Metadata interface { GetObjectByName(objectName string, bucketName string, isFullList bool) (*Object, error) // GetSwitchDBSignal check if there is a signal to switch the database GetSwitchDBSignal() (*MasterDB, error) - // GetBucketWithPayment get bucket info with its related payment info - GetBucketWithPayment(bucketName string, isFullList bool) (*Bucket, *StreamRecord, error) + // GetBucketMetaByName get bucket info with its related info + GetBucketMetaByName(bucketName string, isFullList bool) (*BucketFullMeta, error) } // BSDB contains all the methods required by block syncer database