Skip to content

Commit

Permalink
Merge remote-tracking branch 'couchbase/unstable' into HEAD
Browse files Browse the repository at this point in the history
http: //ci2i-unstable.northscale.in/gsi-09.02.2021-05.30.pass.html
Change-Id: Ic9c1b2fa3152d2b13e7976fde44a7b46ae8a5929
  • Loading branch information
jeelanp2003 committed Feb 9, 2021
2 parents ed98844 + cb1c439 commit 0570473
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 243 deletions.
65 changes: 65 additions & 0 deletions secondary/indexer/ddl_service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func NewDDLServiceMgr(indexerId common.IndexerId, supvCmdch MsgChannel, supvMsgc
mux.HandleFunc("/listMetadataTokens", mgr.handleListMetadataTokens)
mux.HandleFunc("/listCreateTokens", mgr.handleListCreateTokens)
mux.HandleFunc("/listDeleteTokens", mgr.handleListDeleteTokens)
mux.HandleFunc("/listDeleteTokenPaths", mgr.handleListDeleteTokenPaths)
mux.HandleFunc("/listDropInstanceTokens", mgr.handleListDropInstanceTokens)
mux.HandleFunc("/listDropInstanceTokenPaths", mgr.handleListDropInstanceTokenPaths)
mux.HandleFunc("/listScheduleCreateTokens", mgr.handleListScheduleCreateTokens)
mux.HandleFunc("/listStopScheduleCreateTokens", mgr.handleListStopScheduleCreateTokens)
mux.HandleFunc("/transferScheduleCreateTokens", mgr.handleTransferScheduleCreateTokens)
Expand Down Expand Up @@ -1312,6 +1314,8 @@ func (m *DDLServiceMgr) handleListCreateTokens(w http.ResponseWriter, r *http.Re
}
}

// handleListDeleteTokens responds to /listDeleteTokens REST endpoint
// with a list of all delete tokens in metakv on this indexer host.
func (m *DDLServiceMgr) handleListDeleteTokens(w http.ResponseWriter, r *http.Request) {

if !m.validateAuth(w, r) {
Expand Down Expand Up @@ -1351,6 +1355,60 @@ func (m *DDLServiceMgr) handleListDeleteTokens(w http.ResponseWriter, r *http.Re
}
}

// handleListGenericTokenPaths is a helper for all handlers that need only a
// list of token paths rather than the tokens themselves. callerName is used
// for logging. listerFunc is the function in token.go to get the path list
// from metakv for the specific token type desired.
func (m *DDLServiceMgr) handleListGenericTokenPaths(w http.ResponseWriter,
r *http.Request, callerName string, listerFunc func()([]string, error)) {

if !m.validateAuth(w, r) {
logging.Errorf("DDLServiceMgr::handleListGenericTokenPaths Validation Failure caller: %v, req: %v", callerName, common.GetHTTPReqInfo(r))
return
}

if r.Method == "GET" {

logging.Infof("DDLServiceMgr::handleListGenericTokenPaths Processing Request caller: %v, req: %v", callerName, common.GetHTTPReqInfo(r))

tokenPaths, err := listerFunc()
if err != nil {
logging.Errorf("DDLServiceMgr::handleListGenericTokenPaths caller %v, error %v", callerName, err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error() + "\n"))
return
}

list := &mc.TokenPathList{}
list.Paths = make([]string, 0, len(tokenPaths))

for _, path := range tokenPaths {
list.Paths = append(list.Paths, path)
}

buf, err := mc.MarshallTokenPathList(list)
if err != nil {
logging.Errorf("DDLServiceMgr::handleListGenericTokenPaths caller %v, error %v", callerName, err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error() + "\n"))
return
}

w.WriteHeader(http.StatusOK)
w.Write(buf)
}
}

// handleListDeleteTokenPaths responds to /listDeleteTokenPaths REST endpoint with
// a list of the paths (keys) of all delete tokens in metakv on this indexer host.
func (m *DDLServiceMgr) handleListDeleteTokenPaths(w http.ResponseWriter, r *http.Request) {

m.handleListGenericTokenPaths(w, r,
"handleListDeleteTokenPaths", mc.ListDeleteCommandTokenPaths)
}

// handleListDropInstanceTokens responds to /listDropInstanceTokens REST endpoint
// with a list of all drop instance tokens in metakv on this indexer host.
func (m *DDLServiceMgr) handleListDropInstanceTokens(w http.ResponseWriter, r *http.Request) {

if !m.validateAuth(w, r) {
Expand Down Expand Up @@ -1390,6 +1448,13 @@ func (m *DDLServiceMgr) handleListDropInstanceTokens(w http.ResponseWriter, r *h
}
}

// handleListDropInstanceTokenPaths responds to /listDropInstanceTokenPaths REST endpoint
// with a list of the paths (keys) of all drop instance tokens in metakv on this indexer host.
func (m *DDLServiceMgr) handleListDropInstanceTokenPaths(w http.ResponseWriter, r *http.Request) {
m.handleListGenericTokenPaths(w, r,
"handleListDropInstanceTokenPaths", mc.ListDropInstanceCommandTokenPaths)
}

func (m *DDLServiceMgr) handleListScheduleCreateTokens(w http.ResponseWriter, r *http.Request) {

if !m.validateAuth(w, r) {
Expand Down
50 changes: 47 additions & 3 deletions secondary/manager/common/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ type StopScheduleCreateTokenList struct {
Tokens []StopScheduleCreateToken
}

// TokenPathList holds a slice of string token keys as stored
// in metakv. It is used for JSON un/marshalling.
type TokenPathList struct {
Paths []string
}

type CommandListener struct {
doCreate bool
hasNewCreate bool
Expand Down Expand Up @@ -442,11 +448,11 @@ func DeleteCommandTokenExist(defnId c.IndexDefnId) (bool, error) {
}

//
// Return the list of delete token
// ListDeleteCommandToken returns all delete tokens for this indexer host.
//
func ListDeleteCommandToken() ([]*DeleteCommandToken, error) {

paths, err := c.MetakvList(DeleteDDLCommandTokenPath)
paths, err := ListDeleteCommandTokenPaths()
if err != nil {
return nil, err
}
Expand All @@ -471,6 +477,14 @@ func ListDeleteCommandToken() ([]*DeleteCommandToken, error) {
return result, nil
}

//
// ListDeleteCommandTokenPaths returns the metakv paths (keys)
// of all delete tokens for this indexer host.
//
func ListDeleteCommandTokenPaths() ([]string, error) {
return c.MetakvList(DeleteDDLCommandTokenPath)
}

//
// Unmarshall
//
Expand Down Expand Up @@ -514,6 +528,28 @@ func MarshallDeleteCommandTokenList(r *DeleteCommandTokenList) ([]byte, error) {
return buf, nil
}

// UnmarshallTokenPathList unmarshalls a generic list of token paths.
func UnmarshallTokenPathList(data []byte) (*TokenPathList, error) {

r := new(TokenPathList)
if err := json.Unmarshal(data, r); err != nil {
return nil, err
}

return r, nil
}

// MarshallTokenPathList marshalls a generic list of token paths.
func MarshallTokenPathList(r *TokenPathList) ([]byte, error) {

buf, err := json.Marshal(&r)
if err != nil {
return nil, err
}

return buf, nil
}

func FetchIndexDefnToDeleteCommandTokensMap() (map[c.IndexDefnId]*DeleteCommandToken, error) {
paths, err := c.MetakvList(DeleteDDLCommandTokenPath)
if err != nil {
Expand Down Expand Up @@ -686,9 +722,11 @@ func ListAndFetchDropInstanceCommandToken(defnId c.IndexDefnId) ([]*DropInstance
return result, nil
}

// ListAndFetchAllDropInstanceCommandToken returns all drop instance
// tokens for this indexer host.
func ListAndFetchAllDropInstanceCommandToken() ([]*DropInstanceCommandToken, error) {

paths, err := c.MetakvBigValueList(DropInstanceDDLCommandTokenPath)
paths, err := ListDropInstanceCommandTokenPaths()
if err != nil {
return nil, err
}
Expand All @@ -713,6 +751,12 @@ func ListAndFetchAllDropInstanceCommandToken() ([]*DropInstanceCommandToken, err
return result, nil
}

// ListDropInstanceCommandTokenPaths returns the metakv paths (keys)
// of all drop instance tokens for this indexer host.
func ListDropInstanceCommandTokenPaths() ([]string, error) {
return c.MetakvBigValueList(DropInstanceDDLCommandTokenPath)
}

// FetchIndexDefnToDropInstanceCommandTokenMap will get a map of all Index Definition & CreateCommand
// tokens present in metakv
func FetchIndexDefnToDropInstanceCommandTokenMap() (map[c.IndexDefnId][]*DropInstanceCommandToken, error) {
Expand Down
Loading

0 comments on commit 0570473

Please sign in to comment.