forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial_rebuild.go
37 lines (32 loc) · 1.47 KB
/
initial_rebuild.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2014, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tabletmanager
import (
log "github.com/golang/glog"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/topotools"
)
// maybeRebuildKeyspace handles the initial rebuild of SrvKeyspace if needed.
// This should be run as a background task: we use the batch context to check
// the SrvKeyspace object. If it is not there, we try to rebuild it
// for the current cell only.
func (agent *ActionAgent) maybeRebuildKeyspace(cell, keyspace string) {
_, err := agent.TopoServer.GetSrvKeyspace(agent.batchCtx, cell, keyspace)
switch err {
case nil:
// SrvKeyspace exists, we're done
log.Infof("SrvKeyspace(%v,%v) exists, not building it", cell, keyspace)
return
case topo.ErrNoNode:
log.Infof("SrvKeyspace(%v,%v) doesn't exist, rebuilding it", cell, keyspace)
// SrvKeyspace doesn't exist, we'll try to rebuild it
default:
log.Warningf("Cannot read SrvKeyspace(%v,%v) (may need to run 'vtctl RebuildKeyspaceGraph %v'), skipping rebuild: %v", cell, keyspace, keyspace, err)
return
}
if err := topotools.RebuildKeyspace(agent.batchCtx, logutil.NewConsoleLogger(), agent.TopoServer, keyspace, []string{cell}); err != nil {
log.Warningf("RebuildKeyspace(%v,%v) failed: %v, may need to run 'vtctl RebuildKeyspaceGraph %v')", cell, keyspace, err, keyspace)
}
}