forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshard.js
133 lines (111 loc) · 4.18 KB
/
shard.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
app.controller('ShardCtrl', function($scope, $routeParams, $timeout, $route,
shards, tablets, tabletinfo, actions) {
var keyspace = $routeParams.keyspace;
var shard = $routeParams.shard;
$scope.keyspace = {name: keyspace};
$scope.shard = {name: shard};
$scope.actions = actions;
$scope.shardActions = [
{name: 'ValidateShard', title: 'Validate Shard'},
{name: 'ValidateSchemaShard', title: 'Validate Schema'},
{name: 'ValidateVersionShard', title: 'Validate Version'},
{name: 'ValidatePermissionsShard', title: 'Validate Permissions'},
];
$scope.tabletActions = [
{name: 'Ping', title: 'Ping'},
{name: 'RefreshState', title: 'Refresh State', confirm: 'This will tell the tablet to re-read its topology record and adjust its state accordingly.'},
{name: 'ReloadSchema', title: 'Reload Schema', confirm: 'This will tell the tablet to refresh its schema cache by querying mysqld.'},
{name: 'DeleteTablet', title: 'Delete', confirm: 'This will delete the tablet record from topology.'},
];
$scope.tabletType = function(tablet) {
// Use streaming health result if present.
if (tablet.streamHealth && tablet.streamHealth.$resolved) {
if (!tablet.streamHealth.target)
return 'spare';
if (tablet.streamHealth.target.tablet_type)
return vtTabletTypes[tablet.streamHealth.target.tablet_type];
}
return vtTabletTypes[tablet.type];
};
$scope.tabletHealthError = function(tablet) {
if (tablet.streamHealth && tablet.streamHealth.realtime_stats
&& tablet.streamHealth.realtime_stats.health_error) {
return tablet.streamHealth.realtime_stats.health_error;
}
return '';
};
$scope.tabletAccent = function(tablet) {
if ($scope.tabletHealthError(tablet))
return 'md-warn md-hue-2';
switch ($scope.tabletType(tablet)) {
case 'master': return 'md-hue-2';
case 'replica': return 'md-hue-3';
default: return 'md-hue-1';
}
};
$scope.refreshData = function() {
// Get the shard data.
shards.get({keyspace: keyspace, shard: shard}, function(shardData) {
shardData.name = shard;
$scope.shard = shardData;
});
// Get a list of tablet aliases in the shard, in all cells.
tablets.query({shard: keyspace+'/'+shard}, function(tabletAliases) {
// Group them by cell.
var cellMap = {};
tabletAliases.forEach(function(tabletAlias) {
if (cellMap[tabletAlias.cell] === undefined)
cellMap[tabletAlias.cell] = [];
cellMap[tabletAlias.cell].push(tabletAlias);
});
// Turn the cell map into a list, sorted by cell name.
var cellList = [];
Object.keys(cellMap).sort().forEach(function(cellName) {
// Sort the tablets within each cell.
var tabletAliases = cellMap[cellName];
tabletAliases.sort(function(a, b) { return a.uid - b.uid; });
// Fetch tablet data.
var tabletData = [];
tabletAliases.forEach(function(tabletAlias) {
var alias = tabletAlias.cell+'-'+tabletAlias.uid;
var tablet = tablets.get({tablet: alias}, function(tablet) {
// Annotate result with some extra stuff.
tablet.links = vtconfig.tabletLinks(tablet);
});
tablet.alias = tabletAlias;
tabletData.push(tablet);
});
// Add tablet data to the cell list.
cellList.push({
name: cellName,
tablets: tabletData
});
});
$scope.cells = cellList;
});
};
var selectedCell;
$scope.setSelectedCell = function(cell) {
selectedCell = cell;
refreshStreamHealth();
};
function refreshStreamHealth() {
if (selectedCell) {
selectedCell.tablets.forEach(function (tablet) {
if (tablet.alias) {
// Get latest streaming health result.
tabletinfo.get({tablet: tablet.alias.cell+'-'+tablet.alias.uid, info: 'health'}, function(health) {
tablet.streamHealth = health;
});
}
});
}
};
$scope.refreshData();
function periodicRefresh() {
if ($route.current.name != 'shard') return;
refreshStreamHealth();
$timeout(periodicRefresh, 3000);
}
periodicRefresh();
});