Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions manager/rpcserver/manager_server_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,27 @@ func (s *managerServerV1) ListSchedulers(ctx context.Context, req *managerv1.Lis

// Cache miss and search scheduler cluster.
var schedulerClusters []models.SchedulerCluster
if err := s.db.WithContext(ctx).Preload("SeedPeerClusters.SeedPeers", "state = ?", "active").
Preload("Schedulers", "state = ?", "active").Find(&schedulerClusters).Error; err != nil {
return nil, status.Error(codes.Internal, err.Error())

// Check if the requesting host is a seedpeer to restrict scheduler clusters accordingly
var seedPeer models.SeedPeer
isSeedPeer := s.db.WithContext(ctx).Preload("SeedPeerCluster.SchedulerClusters.Schedulers", "state = ?", "active").
Preload("SeedPeerCluster.SchedulerClusters.SeedPeerClusters.SeedPeers", "state = ?", "active").
First(&seedPeer, models.SeedPeer{
Hostname: req.Hostname,
IP: req.Ip,
State: models.SeedPeerStateActive,
}).Error == nil

if isSeedPeer {
// If requesting host is a seedpeer, only return scheduler clusters associated with its seedpeer cluster
log.Debugf("requesting host %s is a seedpeer in cluster %d, filtering scheduler clusters", req.Hostname, seedPeer.SeedPeerClusterID)
schedulerClusters = seedPeer.SeedPeerCluster.SchedulerClusters
} else {
// If not a seedpeer (regular peer), load all scheduler clusters
if err := s.db.WithContext(ctx).Preload("SeedPeerClusters.SeedPeers", "state = ?", "active").
Preload("Schedulers", "state = ?", "active").Find(&schedulerClusters).Error; err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}

// Remove schedulers which not have schedule feature. As OceanBase does not support JSON type,
Expand Down
22 changes: 20 additions & 2 deletions manager/rpcserver/manager_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,26 @@ func (s *managerServerV2) listSchedulersBySearcher(ctx context.Context, req *man

// Cache miss and search scheduler cluster.
var schedulerClusters []models.SchedulerCluster
if err := s.db.WithContext(ctx).Preload("SeedPeerClusters.SeedPeers", "state = ?", "active").Preload("Schedulers", "state = ?", "active").Find(&schedulerClusters).Error; err != nil {
return nil, status.Error(codes.Internal, err.Error())

// Check if the requesting host is a seedpeer to restrict scheduler clusters accordingly
var seedPeer models.SeedPeer
isSeedPeer := s.db.WithContext(ctx).Preload("SeedPeerCluster.SchedulerClusters.Schedulers", "state = ?", "active").
Preload("SeedPeerCluster.SchedulerClusters.SeedPeerClusters.SeedPeers", "state = ?", "active").
First(&seedPeer, models.SeedPeer{
Hostname: req.Hostname,
IP: req.Ip,
State: models.SeedPeerStateActive,
}).Error == nil

if isSeedPeer {
// If requesting host is a seedpeer, only return scheduler clusters associated with its seedpeer cluster
log.Debugf("requesting host %s is a seedpeer in cluster %d, filtering scheduler clusters", req.Hostname, seedPeer.SeedPeerClusterID)
schedulerClusters = seedPeer.SeedPeerCluster.SchedulerClusters
} else {
// If not a seedpeer (regular peer), load all scheduler clusters
if err := s.db.WithContext(ctx).Preload("SeedPeerClusters.SeedPeers", "state = ?", "active").Preload("Schedulers", "state = ?", "active").Find(&schedulerClusters).Error; err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}

// Remove schedulers which not have schedule feature. As OceanBase does not support JSON type,
Expand Down
Loading