зеркало из https://github.com/github/vitess-gh.git
worker: SplitClone: Display correct list of used tablets during online clone phase.
Before the shown list was empty.
This commit is contained in:
Родитель
0a153875a3
Коммит
c42f1ef49a
|
@ -168,6 +168,14 @@ func (scw *SplitCloneWorker) setErrorState(err error) {
|
|||
event.DispatchUpdate(scw.ev, "error: "+err.Error())
|
||||
}
|
||||
|
||||
func (scw *SplitCloneWorker) formatOnlineSources() string {
|
||||
aliases := scw.tabletTracker.TabletsInUse()
|
||||
if aliases == "" {
|
||||
return "no online source tablets currently in use"
|
||||
}
|
||||
return aliases
|
||||
}
|
||||
|
||||
func (scw *SplitCloneWorker) setFormattedOfflineSources(aliases []*topodatapb.TabletAlias) {
|
||||
scw.formattedOfflineSourcesMu.Lock()
|
||||
defer scw.formattedOfflineSourcesMu.Unlock()
|
||||
|
@ -200,7 +208,7 @@ func (scw *SplitCloneWorker) StatusAsHTML() template.HTML {
|
|||
switch state {
|
||||
case WorkerStateCloneOnline:
|
||||
result += "<b>Running:</b></br>\n"
|
||||
result += "<b>Copying from:</b> " + scw.FormattedOfflineSources() + "</br>\n"
|
||||
result += "<b>Copying from:</b> " + scw.formatOnlineSources() + "</br>\n"
|
||||
statuses, eta := scw.tableStatusListOnline.format()
|
||||
result += "<b>ETA:</b> " + eta.String() + "</br>\n"
|
||||
result += strings.Join(statuses, "</br>\n")
|
||||
|
@ -244,7 +252,7 @@ func (scw *SplitCloneWorker) StatusAsText() string {
|
|||
switch state {
|
||||
case WorkerStateCloneOnline:
|
||||
result += "Running:\n"
|
||||
result += "Copying from: " + scw.FormattedOfflineSources() + "\n"
|
||||
result += "Copying from: " + scw.formatOnlineSources() + "\n"
|
||||
statuses, eta := scw.tableStatusListOffline.format()
|
||||
result += "ETA: " + eta.String() + "\n"
|
||||
result += strings.Join(statuses, "\n")
|
||||
|
|
|
@ -7,6 +7,7 @@ package worker
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/youtube/vitess/go/vt/discovery"
|
||||
|
@ -84,6 +85,20 @@ func (t *TabletTracker) Untrack(alias *topodata.TabletAlias) {
|
|||
}
|
||||
}
|
||||
|
||||
// TabletsInUse returns a string of all tablet aliases currently in use.
|
||||
// The tablets are separated by a space.
|
||||
func (t *TabletTracker) TabletsInUse() string {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
|
||||
var aliases []string
|
||||
for alias := range t.usedTablets {
|
||||
aliases = append(aliases, alias)
|
||||
}
|
||||
sort.Strings(aliases)
|
||||
return strings.Join(aliases, " ")
|
||||
}
|
||||
|
||||
func (t *TabletTracker) tabletsByUsage() []string {
|
||||
sorted := sortMapByValue(t.usedTablets)
|
||||
var tablets []string
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright 2016, 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 worker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/youtube/vitess/go/vt/discovery"
|
||||
"github.com/youtube/vitess/go/vt/topo"
|
||||
|
||||
querypb "github.com/youtube/vitess/go/vt/proto/query"
|
||||
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
)
|
||||
|
||||
var ts1 = discovery.TabletStats{
|
||||
Tablet: topo.NewTablet(10, "cell", "host1"),
|
||||
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_REPLICA},
|
||||
}
|
||||
var ts2 = discovery.TabletStats{
|
||||
Tablet: topo.NewTablet(20, "cell", "host1"),
|
||||
Target: &querypb.Target{Keyspace: "k", Shard: "s", TabletType: topodatapb.TabletType_REPLICA},
|
||||
}
|
||||
var allTs = []discovery.TabletStats{ts1, ts2}
|
||||
|
||||
func TestTabletsInUse(t *testing.T) {
|
||||
tt := NewTabletTracker()
|
||||
|
||||
tt.Track([]discovery.TabletStats{ts1})
|
||||
if got, want := tt.TabletsInUse(), "cell-0000000010"; got != want {
|
||||
t.Fatalf("TabletsInUse() = %v, want = %v", got, want)
|
||||
}
|
||||
|
||||
tt.Track([]discovery.TabletStats{ts2})
|
||||
if got, want := tt.TabletsInUse(), "cell-0000000010 cell-0000000020"; got != want {
|
||||
t.Fatalf("TabletsInUse() = %v, want = %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackUntrack(t *testing.T) {
|
||||
tt := NewTabletTracker()
|
||||
// ts1 will be used because no tablet is in use yet and ts1 is the first.
|
||||
if got, want := tt.Track(allTs), ts1.Tablet.Alias; !proto.Equal(got, want) {
|
||||
t.Fatalf("Track(%v) = %v, want = %v", allTs, got, want)
|
||||
}
|
||||
|
||||
// ts1 is already in use once, use ts2 now.
|
||||
if got, want := tt.Track(allTs), ts2.Tablet.Alias; !proto.Equal(got, want) {
|
||||
t.Fatalf("Track(%v) = %v, want = %v", allTs, got, want)
|
||||
}
|
||||
|
||||
// ts2 is no longer in use after Untrack().
|
||||
tt.Untrack(ts2.Tablet.Alias)
|
||||
// ts2 instead of ts1 will be used because ts1 has a higher use count.
|
||||
if got, want := tt.Track(allTs), ts2.Tablet.Alias; !proto.Equal(got, want) {
|
||||
t.Fatalf("Track(%v) = %v, want = %v", allTs, got, want)
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче