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
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).
  • Loading branch information
NamanJain8 authored and Harshil Goel committed Feb 2, 2023
1 parent da459d2 commit 656cef2
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,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 @@ -77,7 +77,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 @@ -92,9 +92,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
Original file line number Diff line number Diff line change
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 656cef2

Please sign in to comment.