Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure reserved predicates cannot be moved. #3137

Merged
merged 2 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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