Skip to content

Commit

Permalink
fix(state): fix hex to uint64 response of list of namespaces (#8091) (#…
Browse files Browse the repository at this point in the history
…8101)

There is an issue in ExtractNamespaceFromPredicate. The issue is the parsing was done assuming ns in <ns>-<attr> to be decimal (actually it is hexadecimal). This leads to the following issues.

A predicate a-name, it was skipped.
A predicate 11-name was parsed as namespace 11, actually it is namespace 17 (0x11).

(cherry picked from commit 0c9f601)
  • Loading branch information
NamanJain8 committed Nov 30, 2021
1 parent 1667973 commit 683885a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
13 changes: 6 additions & 7 deletions graphql/admin/state.go
Expand Up @@ -46,13 +46,13 @@ func resolveState(ctx context.Context, q schema.Query) *resolve.Resolved {
u := jsonpb.Unmarshaler{}
var ms pb.MembershipState
err = u.Unmarshal(bytes.NewReader(resp.GetJson()), &ms)

if err != nil {
return resolve.EmptyResult(q, err)
}

// map to graphql response structure
state := convertToGraphQLResp(ms)
ns, _ := x.ExtractNamespace(ctx)
// map to graphql response structure. Only guardian of galaxy can list the namespaces.
state := convertToGraphQLResp(ms, ns == x.GalaxyNamespace)
b, err := json.Marshal(state)
if err != nil {
return resolve.EmptyResult(q, err)
Expand All @@ -76,7 +76,7 @@ func resolveState(ctx context.Context, q schema.Query) *resolve.Resolved {
// values and not the keys. For pb.MembershipState.Group, the keys are the group IDs
// and pb.Group didn't contain this ID, so we are creating a custom clusterGroup type,
// which is same as pb.Group and also contains the ID for the group.
func convertToGraphQLResp(ms pb.MembershipState) membershipState {
func convertToGraphQLResp(ms pb.MembershipState, listNs bool) membershipState {
var state membershipState

// namespaces stores set of namespaces
Expand All @@ -91,9 +91,8 @@ func convertToGraphQLResp(ms pb.MembershipState) membershipState {
var tablets = make([]*pb.Tablet, 0, len(v.Tablets))
for name, v1 := range v.Tablets {
tablets = append(tablets, v1)
val, err := x.ExtractNamespaceFromPredicate(name)
if err == nil {
namespaces[val] = struct{}{}
if listNs {
namespaces[x.ParseNamespace(name)] = struct{}{}
}
}
state.Groups = append(state.Groups, clusterGroup{
Expand Down
13 changes: 0 additions & 13 deletions x/keys.go
Expand Up @@ -143,19 +143,6 @@ func IsReverseAttr(attr string) bool {
return pred[0] == '~'
}

func ExtractNamespaceFromPredicate(predicate string) (uint64, error) {
splitString := strings.Split(predicate, "-")
if len(splitString) <= 1 {
return 0, errors.Errorf("predicate does not contain namespace name")
}
uintVal, err := strconv.ParseUint(splitString[0], 0, 64)
if err != nil {
return 0, errors.Wrapf(err, "while parsing %s as uint64", splitString[0])
}
return uintVal, nil

}

func writeAttr(buf []byte, attr string) []byte {
AssertTrue(len(attr) < math.MaxUint16)
binary.BigEndian.PutUint16(buf[:2], uint16(len(attr)))
Expand Down

0 comments on commit 683885a

Please sign in to comment.