Skip to content

Commit

Permalink
Ensure reserved predicates cannot be moved. (dgraph-io#3137)
Browse files Browse the repository at this point in the history
This change ensures reserved predicates cannot be moved, either by calls
to the /movePred endpoint or during rebalancing of predicates.
  • Loading branch information
martinmr authored and dna2github committed Jul 19, 2019
1 parent 2259dec commit 3a74a4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dgraph/cmd/zero/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions dgraph/cmd/zero/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3a74a4b

Please sign in to comment.