Skip to content

Commit

Permalink
fix: migrate bucket status
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryTong65 committed May 10, 2024
1 parent 66f2b77 commit 6c5294c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modular/blocksyncer/modules/bucket/bucket_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
EventDeleteBucket = proto.MessageName(&storagetypes.EventDeleteBucket{})
EventUpdateBucketInfo = proto.MessageName(&storagetypes.EventUpdateBucketInfo{})
EventDiscontinueBucket = proto.MessageName(&storagetypes.EventDiscontinueBucket{})
EventMigrationBucket = proto.MessageName(&storagetypes.EventMigrationBucket{})
EventCompleteMigrationBucket = proto.MessageName(&storagetypes.EventCompleteMigrationBucket{})
EventToggleSPAsDelegatedAgent = proto.MessageName(&storagetypes.EventToggleSPAsDelegatedAgent{})
)
Expand All @@ -31,6 +32,7 @@ var BucketEvents = map[string]bool{
EventDeleteBucket: true,
EventUpdateBucketInfo: true,
EventDiscontinueBucket: true,
EventMigrationBucket: true,
EventCompleteMigrationBucket: true,
EventToggleSPAsDelegatedAgent: true,
}
Expand Down Expand Up @@ -100,6 +102,13 @@ func (m *Module) ExtractEventStatements(ctx context.Context, block *tmctypes.Res
return nil, errors.New("discontinue bucket event assert error")
}
return m.handleDiscontinueBucket(ctx, block, txHash, discontinueBucket), nil
case EventMigrationBucket:
migrationBucket, ok := typedEvent.(*storagetypes.EventMigrationBucket)
if !ok {
log.Errorw("type assert error", "type", "EventMigrationBucket", "event", typedEvent)
return nil, errors.New("migration bucket event assert error")
}
return m.handleEventMigrationBucket(ctx, block, txHash, migrationBucket), nil
case EventCompleteMigrationBucket:
completeMigrationBucket, ok := typedEvent.(*storagetypes.EventCompleteMigrationBucket)
if !ok {
Expand Down Expand Up @@ -208,11 +217,29 @@ func (m *Module) handleUpdateBucketInfo(ctx context.Context, block *tmctypes.Res
}
}

func (m *Module) handleEventMigrationBucket(ctx context.Context, block *tmctypes.ResultBlock, txHash common.Hash, migrationBucket *storagetypes.EventMigrationBucket) map[string][]interface{} {
bucket := &models.Bucket{
BucketID: common.BigToHash(migrationBucket.BucketId.BigInt()),
BucketName: migrationBucket.BucketName,
Status: storagetypes.BUCKET_STATUS_MIGRATING.String(),

UpdateAt: block.Block.Height,
UpdateTxHash: txHash,
UpdateTime: block.Block.Time.UTC().Unix(),
}

k, v := m.db.UpdateBucketToSQL(ctx, bucket)
return map[string][]interface{}{
k: v,
}
}

func (m *Module) handleCompleteMigrationBucket(ctx context.Context, block *tmctypes.ResultBlock, txHash common.Hash, completeMigrationBucket *storagetypes.EventCompleteMigrationBucket) map[string][]interface{} {
bucket := &models.Bucket{
BucketID: common.BigToHash(completeMigrationBucket.BucketId.BigInt()),
BucketName: completeMigrationBucket.BucketName,
GlobalVirtualGroupFamilyId: completeMigrationBucket.GlobalVirtualGroupFamilyId,
Status: storagetypes.BUCKET_STATUS_CREATED.String(),

UpdateAt: block.Block.Height,
UpdateTxHash: txHash,
Expand Down

0 comments on commit 6c5294c

Please sign in to comment.