From f1b6449abf7b10f2369a7211782cc62df3171600 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Thu, 14 Mar 2019 07:22:41 -0700 Subject: [PATCH] Ensure reserved predicates cannot be moved. This change ensures reserved predicates cannot be moved, either by calls to the /movePred endpoint or during rebalancing of predicates. --- dgraph/cmd/zero/http.go | 3 +++ dgraph/cmd/zero/tablet.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/dgraph/cmd/zero/http.go b/dgraph/cmd/zero/http.go index e4eddf9be32..d993c480636 100644 --- a/dgraph/cmd/zero/http.go +++ b/dgraph/cmd/zero/http.go @@ -155,6 +155,9 @@ func (st *state) moveTablet(w http.ResponseWriter, r *http.Request) { groupId, ok := intFromQueryParam(w, r, "group") if !ok { + w.WriteHeader(http.StatusBadRequest) + x.SetStatus(w, x.ErrorInvalidRequest, fmt.Sprintf( + "Query parameter 'group' should contain a valid integer.")) return } dstGroup := uint32(groupId) diff --git a/dgraph/cmd/zero/tablet.go b/dgraph/cmd/zero/tablet.go index 5f5a21fcf7e..034260c1a92 100644 --- a/dgraph/cmd/zero/tablet.go +++ b/dgraph/cmd/zero/tablet.go @@ -89,6 +89,11 @@ func (s *Server) movePredicate(predicate string, srcGroup, dstGroup uint32) erro ctx, span := otrace.StartSpan(ctx, "Zero.MovePredicate") defer span.End() + // Ensure that reserved predicates cannot be moved. + if x.IsReservedPredicate(predicate) { + return x.Errorf("Unable to move reserved predicate %s", predicate) + } + // Ensure that I'm connected to the rest of the Zero group, and am the leader. if _, err := s.latestMembershipState(ctx); err != nil { return x.Errorf("Unable to reach quorum: %v", err) @@ -216,6 +221,11 @@ func (s *Server) chooseTablet() (predicate string, srcGroup uint32, dstGroup uin size := int64(0) group := s.state.Groups[srcGroup] for _, tab := range group.Tablets { + // Reserved predicates should always be in group 1 so do not re-balance them. + if x.IsReservedPredicate(tab.Predicate) { + continue + } + // Finds a tablet as big a possible such that on moving it dstGroup's size is // less than or equal to srcGroup. if tab.Space <= sizeDiff/2 && tab.Space > size {