Skip to content

Commit

Permalink
fix: migrate bucket charged quota and list events
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryTong65 committed May 9, 2024
1 parent ec154a1 commit 0afaf67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
12 changes: 11 additions & 1 deletion modular/metadata/metadata_bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,25 @@ func (r *MetadataModular) GfSpGetLatestBucketReadQuota(
", bucket_id: " + util.Uint64ToString(req.GetBucketId()) + ", error: " + err.Error())}, nil
}
}

// if the traffic table has been created, return the db info from meta service
var chargedQuotaSize uint64
bucketInfo, err := r.baseApp.Consensus().QueryBucketInfoById(ctx, req.BucketId)
if err != nil {
log.Errorw("failed to get bucketInfo on chain",
"bucket_id", req.GetBucketId(), "error", err)
chargedQuotaSize = bucketTraffic.ChargedQuotaSize
} else {
chargedQuotaSize = bucketInfo.ChargedReadQuota
}
quota := &gfsptask.GfSpBucketQuotaInfo{
BucketName: bucketTraffic.BucketName,
BucketId: bucketTraffic.BucketID,
Month: bucketTraffic.YearMonth,
ReadConsumedSize: bucketTraffic.ReadConsumedSize,
FreeQuotaConsumedSize: bucketTraffic.FreeQuotaConsumedSize,
FreeQuotaSize: bucketTraffic.FreeQuotaSize,
ChargedQuotaSize: bucketTraffic.ChargedQuotaSize,
ChargedQuotaSize: chargedQuotaSize,
MonthlyFreeQuotaSize: bucketTraffic.MonthlyFreeQuotaSize,
MonthlyFreeQuotaConsumedSize: bucketTraffic.MonthlyFreeQuotaConsumedSize,
}
Expand Down
18 changes: 17 additions & 1 deletion modular/metadata/metadata_bucket_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"testing"

"cosmossdk.io/math"
"github.com/forbole/juno/v4/common"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -656,6 +657,7 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {
a.baseApp.SetGfBsDB(m)
spDBMocker := spdb.NewMockSPDB(ctrl)

consensusChargedQuotaSize := uint64(100)
bucketTraffic := &spdb.BucketTraffic{
BucketID: 1,
YearMonth: "2024-01",
Expand All @@ -670,6 +672,20 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {

consensusMock := consensus.NewMockConsensus(ctrl)
consensusMock.EXPECT().QuerySPFreeQuota(gomock.Any(), gomock.Any()).Return(uint64(10000), nil).Times(0)
consensusMock.EXPECT().QueryBucketInfoById(gomock.Any(), gomock.Any()).Return(&storagetypes.BucketInfo{
Owner: "0x11E0A11A7A01E2E757447B52FBD7152004AC699D",
BucketName: "",
Visibility: 0,
Id: math.NewUint(1),
SourceType: 0,
CreateAt: 0,
PaymentAddress: "",
GlobalVirtualGroupFamilyId: 0,
ChargedReadQuota: consensusChargedQuotaSize,
BucketStatus: 0,
Tags: nil,
SpAsDelegatedAgentDisabled: false,
}, nil).AnyTimes()
a.baseApp.SetConsensus(consensusMock)

resp, err := a.GfSpGetLatestBucketReadQuota(context.Background(), &types.GfSpGetLatestBucketReadQuotaRequest{
Expand All @@ -684,7 +700,7 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {
ReadConsumedSize: bucketTraffic.ReadConsumedSize,
FreeQuotaConsumedSize: bucketTraffic.FreeQuotaConsumedSize,
FreeQuotaSize: bucketTraffic.FreeQuotaSize,
ChargedQuotaSize: bucketTraffic.ChargedQuotaSize,
ChargedQuotaSize: consensusChargedQuotaSize,
},
}, resp)
}
Expand Down
4 changes: 2 additions & 2 deletions modular/metadata/metadata_sp_exit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ func (r *MetadataModular) GfSpListMigrateBucketEvents(ctx context.Context, req *
GlobalVirtualGroupFamilyId: complete.GlobalVirtualGroupFamilyId,
}
}
if cancel != nil && cancel.CreateAt >= event.CreateAt && complete == nil {
if cancel != nil && cancel.CreateAt >= event.CreateAt && (complete == nil || cancel.CreateAt > complete.CreateAt) {
spCancelEvent = &storage_types.EventCancelMigrationBucket{
Operator: cancel.Operator.String(),
BucketName: cancel.BucketName,
BucketId: math.NewUintFromBigInt(cancel.BucketID.Big()),
}
}
if reject != nil && reject.CreateAt >= event.CreateAt && complete == nil {
if reject != nil && reject.CreateAt >= event.CreateAt && (complete == nil || reject.CreateAt > complete.CreateAt) {
spRejectEvent = &storage_types.EventRejectMigrateBucket{
Operator: reject.Operator.String(),
BucketName: reject.BucketName,
Expand Down

0 comments on commit 0afaf67

Please sign in to comment.