-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpoint.html
312 lines (275 loc) · 9.33 KB
/
checkpoint.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MySQL Redo Log with Variable Write Speed</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
h1 {
color: #2c3e50;
margin-bottom: 20px;
}
canvas {
background-color: #fffef5;
display: block;
margin: 20px auto;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
#status {
margin: 15px auto;
font-size: 18px;
color: #333;
min-height: 24px;
font-weight: bold;
}
.control-panel {
background: #ecf0f1;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
display: inline-block;
margin: 10px auto;
text-align: left;
}
.slider-container {
margin: 15px 0;
}
label {
display: inline-block;
width: 200px;
font-weight: bold;
color: #2c3e50;
}
.value-display {
display: inline-block;
width: 60px;
text-align: right;
font-family: monospace;
}
.checkbox-container {
margin: 15px 0;
}
</style>
</head>
<body>
<h1>MySQL Redo Log with Variable Write Speed</h1>
<canvas id="logRing" width="600" height="600"></canvas>
<div id="status">System initialized...</div>
<div class="control-panel">
<div class="slider-container">
<label for="baseSpeedSlider">Base Write Speed:</label>
<input type="range" id="baseSpeedSlider" min="0.001" max="0.05" step="0.001" value="0.015">
<span class="value-display" id="baseSpeedValue">0.015</span>
</div>
<div class="slider-container">
<label for="variationSlider">Speed Variation:</label>
<input type="range" id="variationSlider" min="0" max="0.1" step="0.001" value="0.03">
<span class="value-display" id="variationValue">0.030</span>
</div>
<div class="slider-container">
<label for="checkpointSlider">Checkpoint Speed:</label>
<input type="range" id="checkpointSlider" min="0.001" max="0.05" step="0.001" value="0.01">
<span class="value-display" id="checkpointValue">0.010</span>
</div>
<div class="checkbox-container">
<input type="checkbox" id="randomSpeedCheckbox" checked>
<label for="randomSpeedCheckbox">Enable Random Speed Fluctuation</label>
</div>
</div>
<script>
// Core configuration
const canvas = document.getElementById("logRing");
const ctx = canvas.getContext("2d");
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const radius = 180;
const logFiles = ["ib_logfile0", "ib_logfile1", "ib_logfile2", "ib_logfile3"];
const segments = logFiles.length;
// Pointer states
let writePos = Math.PI * 1.5;
let checkpoint = Math.PI * 1.0;
let baseWriteSpeed = 0.015;
let currentWriteSpeed = baseWriteSpeed;
let speedVariation = 0.03;
let checkpointSpeed = 0.02;
const minGap = Math.PI / 20;
const warningGap = Math.PI / 10;
// Speed fluctuation variables
let speedChangeTimer = 0;
let currentSpeedPhase = 0; // 0=normal, 1=high, 2=low
const phaseDurations = [100, 200, 150]; // In frames
// UI elements
const baseSpeedSlider = document.getElementById('baseSpeedSlider');
const baseSpeedValue = document.getElementById('baseSpeedValue');
const variationSlider = document.getElementById('variationSlider');
const variationValue = document.getElementById('variationValue');
const checkpointSlider = document.getElementById('checkpointSlider');
const checkpointValue = document.getElementById('checkpointValue');
const randomSpeedCheckbox = document.getElementById('randomSpeedCheckbox');
const statusDisplay = document.getElementById('status');
// Initialize UI
baseSpeedValue.textContent = baseWriteSpeed.toFixed(3);
variationValue.textContent = speedVariation.toFixed(3);
checkpointValue.textContent = checkpointSpeed.toFixed(3);
// Event listeners
baseSpeedSlider.addEventListener('input', () => {
baseWriteSpeed = parseFloat(baseSpeedSlider.value);
baseSpeedValue.textContent = baseWriteSpeed.toFixed(3);
if (!randomSpeedCheckbox.checked) {
currentWriteSpeed = baseWriteSpeed;
}
});
variationSlider.addEventListener('input', () => {
speedVariation = parseFloat(variationSlider.value);
variationValue.textContent = speedVariation.toFixed(3);
});
checkpointSlider.addEventListener('input', () => {
checkpointSpeed = parseFloat(checkpointSlider.value);
checkpointValue.textContent = checkpointSpeed.toFixed(3);
});
randomSpeedCheckbox.addEventListener('change', () => {
if (!randomSpeedCheckbox.checked) {
currentWriteSpeed = baseWriteSpeed;
}
});
function angleDiff(from, to) {
return (to - from + 2 * Math.PI) % (2 * Math.PI);
}
function updateSpeedVariation() {
if (!randomSpeedCheckbox.checked) return;
speedChangeTimer++;
// Change phase if duration elapsed
if (speedChangeTimer > phaseDurations[currentSpeedPhase]) {
speedChangeTimer = 0;
currentSpeedPhase = (currentSpeedPhase + 1) % 3;
// Set new speed based on phase
switch(currentSpeedPhase) {
case 0: // Normal phase
currentWriteSpeed = baseWriteSpeed;
break;
case 1: // High activity phase
currentWriteSpeed = baseWriteSpeed + speedVariation * (0.5 + Math.random() * 0.5);
break;
case 2: // Low activity phase
currentWriteSpeed = Math.max(0.001, baseWriteSpeed - speedVariation * (0.3 + Math.random() * 0.3));
break;
}
}
}
function drawRing() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw segments
const segmentAngle = 2 * Math.PI / segments;
for (let i = 0; i < segments; i++) {
const startAngle = i * segmentAngle;
const endAngle = startAngle + segmentAngle;
ctx.beginPath();
ctx.fillStyle = "#ffe0b2";
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY, radius, startAngle, endAngle);
ctx.closePath();
ctx.fill();
ctx.save();
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.lineTo(centerX + radius * Math.cos(startAngle), centerY + radius * Math.sin(startAngle));
ctx.strokeStyle = "#999";
ctx.stroke();
ctx.restore();
ctx.save();
ctx.translate(centerX, centerY);
ctx.rotate(startAngle + segmentAngle / 2);
ctx.textAlign = "center";
ctx.fillStyle = "#4e342e";
ctx.font = "bold 16px Arial";
ctx.fillText(logFiles[i], radius - 60, 8);
ctx.restore();
}
// Calculate available space
const availableSpace = angleDiff(writePos, checkpoint);
const availablePercent = (availableSpace / (2 * Math.PI) * 100).toFixed(1);
// Draw writable area
ctx.beginPath();
if (availableSpace < minGap) {
ctx.fillStyle = "rgba(239, 83, 80, 0.7)";
statusDisplay.innerHTML = `<span style="color:red">WARNING: Only ${availablePercent}% space left!</span>`;
} else if (availableSpace < warningGap) {
ctx.fillStyle = "rgba(255, 167, 38, 0.7)";
statusDisplay.innerHTML = `<span style="color:orange">Notice: ${availablePercent}% space left</span>`;
} else {
ctx.fillStyle = "rgba(139, 195, 74, 0.7)";
let speedInfo = randomSpeedCheckbox.checked ?
` (Current speed: ${currentWriteSpeed.toFixed(3)})` : '';
statusDisplay.innerHTML = `Normal: ${availablePercent}% space available${speedInfo}`;
}
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY, radius, writePos, checkpoint);
ctx.closePath();
ctx.fill();
drawPointer(writePos, "Write Pos", "#1565c0");
drawPointer(checkpoint, "Checkpoint", "#c62828");
}
function drawPointer(angle, label, color) {
const pointerLength = radius + 25;
const labelRadius = radius + 50;
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.lineTo(centerX + pointerLength * Math.cos(angle), centerY + pointerLength * Math.sin(angle));
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.stroke();
ctx.beginPath();
ctx.moveTo(centerX + pointerLength * Math.cos(angle), centerY + pointerLength * Math.sin(angle));
ctx.lineTo(centerX + (pointerLength - 18) * Math.cos(angle - 0.2), centerY + (pointerLength - 18) * Math.sin(angle - 0.2));
ctx.lineTo(centerX + (pointerLength - 18) * Math.cos(angle + 0.2), centerY + (pointerLength - 18) * Math.sin(angle + 0.2));
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();
ctx.fillStyle = color;
ctx.font = "bold 16px Arial";
ctx.textAlign = "center";
ctx.fillText(label, centerX + labelRadius * Math.cos(angle), centerY + labelRadius * Math.sin(angle));
}
function updateCheckpoint() {
checkpoint += checkpointSpeed;
if (checkpoint > 2 * Math.PI) checkpoint -= 2 * Math.PI;
}
function updateWritePosition() {
const currentGap = angleDiff(writePos, checkpoint);
// Dynamic speed adjustment
let effectiveSpeed = currentWriteSpeed;
// Automatically slow down when approaching checkpoint
if (currentGap < warningGap) {
effectiveSpeed = Math.min(currentWriteSpeed, currentGap / 8);
}
// Ensure we never pass the checkpoint
if (currentGap > minGap) {
writePos += effectiveSpeed;
if (writePos > 2 * Math.PI) writePos -= 2 * Math.PI;
}
}
let lastTimestamp = 0;
function animate(timestamp) {
if (!lastTimestamp) lastTimestamp = timestamp;
const deltaTime = timestamp - lastTimestamp;
lastTimestamp = timestamp;
if (deltaTime > 0) {
updateSpeedVariation();
updateCheckpoint();
updateWritePosition();
drawRing();
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>