Skip to content

Commit

Permalink
MB-52121 Add ServerlessManager interface support
Browse files Browse the repository at this point in the history
Implements the service.ServerlessManager interface

Change-Id: If76bd4a5f1a1a37c43ad2bd1faf86512a9cc1d26
  • Loading branch information
deepkaran committed Nov 15, 2022
1 parent 4c7a1eb commit 098d1fa
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
4 changes: 3 additions & 1 deletion secondary/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,12 @@ func NewIndexer(config common.Config) (Indexer, Message) {
idx.wrkrRecvCh, idx.wrkrPrioRecvCh, idx.config, idx.nodeInfo, idx.rebalanceRunning,
idx.rebalanceToken, idx.statsMgr)

serverlessMgr := NewServerlessManager(httpAddr)

// Register service managers with ns_server for RCP callbacks. This returns a single
// MasterServiceManager object that implements all the interfaces we want callbacks for via
// delegation to the API-specific objects passed to it.
idx.masterMgr = NewMasterServiceManager(autofailoverMgr, genericMgr, pauseMgr, rebalMgr)
idx.masterMgr = NewMasterServiceManager(autofailoverMgr, genericMgr, pauseMgr, rebalMgr, serverlessMgr)

go idx.monitorKVNodes()

Expand Down
34 changes: 24 additions & 10 deletions secondary/indexer/master_service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import (
// GSI: GenericServiceManager (generic_service_manager.go)
// GSI: PauseServiceManager (pause_service_manager.go)
// GSI: RebalanceServiceManager (rebalance_service_manager.go)
// ServerlessManager
// GSI: ServerlessManager (serverless_manager.go)
type MasterServiceManager struct {
autofailMgr *AutofailoverServiceManager
genericMgr *GenericServiceManager
pauseMgr *PauseServiceManager
rebalMgr *RebalanceServiceManager
autofailMgr *AutofailoverServiceManager
genericMgr *GenericServiceManager
pauseMgr *PauseServiceManager
rebalMgr *RebalanceServiceManager
serverlessMgr *ServerlessManager
}

// NewMasterServiceManager is the constructor for the MasterServiceManager class. The service
Expand All @@ -44,12 +47,14 @@ func NewMasterServiceManager(
genericMgr *GenericServiceManager,
pauseMgr *PauseServiceManager,
rebalMgr *RebalanceServiceManager,
serverlessMgr *ServerlessManager,
) *MasterServiceManager {
this := &MasterServiceManager{
autofailMgr: autofailMgr,
genericMgr: genericMgr,
pauseMgr: pauseMgr,
rebalMgr: rebalMgr,
autofailMgr: autofailMgr,
genericMgr: genericMgr,
pauseMgr: pauseMgr,
rebalMgr: rebalMgr,
serverlessMgr: serverlessMgr,
}
go this.registerWithServer() // register for ns_server RPC calls from cbauth
return this
Expand All @@ -63,8 +68,9 @@ func (this *MasterServiceManager) registerWithServer() {

// Ensure this class implements the interfaces we intend. The type assertions will panic if not.
var iface interface{} = this
logging.Infof("%v %T implements service.AutofailoverManager; %T implements service.Manager",
method, iface.(service.AutofailoverManager), iface.(service.Manager))
logging.Infof("%v %T implements service.AutofailoverManager; %T implements service.Manager; "+
"%T implements service.ServerlessManager", method, iface.(service.AutofailoverManager),
iface.(service.Manager), iface.(service.ServerlessManager))

// Unless it returns an error, RegisterManager will actually run forever instead of returning
err := service.RegisterManager(this, nil)
Expand Down Expand Up @@ -146,3 +152,11 @@ func (this *MasterServiceManager) PrepareTopologyChange(change service.TopologyC
func (this *MasterServiceManager) StartTopologyChange(change service.TopologyChange) error {
return this.rebalMgr.StartTopologyChange(change)
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// ns_server ServerlessManager interface methods
////////////////////////////////////////////////////////////////////////////////////////////////////

func (this *MasterServiceManager) GetDefragmentedUtilization() (*service.DefragmentedUtilizationInfo, error) {
return this.serverlessManager.GetDefragmentedUtilization()
}
43 changes: 43 additions & 0 deletions secondary/indexer/serverless_service_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// @copyright 2021-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package indexer

import (
"github.com/couchbase/cbauth/service"
)

////////////////////////////////////////////////////////////////////////////////////////////////////
// ServerlessManager class
////////////////////////////////////////////////////////////////////////////////////////////////////

// ServerlessManager provides the implementation of the ns_server RPC interface
// ServerlessManager(defined in cbauth/service/interface.go).
type ServerlessManager struct {
httpAddr string
}

// NewServerlessManager is the constructor for the ServerlessManager class.
// httpAddr gives the host:port of the local node for Index Service HTTP calls.
func NewServerlessManager(httpAddr string) *ServerlessManager {
m := &ServerlessManager{
httpAddr: httpAddr,
}
return m
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// service.ServerlessManager interface implementation
// Interface defined in cbauth/service/interface.go
//
////////////////////////////////////////////////////////////////////////////////////////////////////

func (m *ServerlessManager) GetDefragmentedUtilization() (*service.DefragmentedUtilizationInfo, error) {
return nil, nil

}

0 comments on commit 098d1fa

Please sign in to comment.