1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import java.io.DataInput;
21 import java.io.DataOutput;
22 import java.io.IOException;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.TreeMap;
28 import java.util.TreeSet;
29
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.apache.hadoop.hbase.util.Strings;
32 import org.apache.hadoop.io.VersionedWritable;
33 import org.apache.hadoop.io.WritableComparable;
34
35
36
37
38
39 public class HServerLoad092 extends VersionedWritable
40 implements WritableComparable<HServerLoad092> {
41 private static final byte VERSION = 2;
42
43 public static final HServerLoad092 EMPTY_HSERVERLOAD = new HServerLoad092();
44
45
46
47
48 private int numberOfRequests = 0;
49
50
51
52 private int totalNumberOfRequests = 0;
53
54
55 private int usedHeapMB = 0;
56
57
58 private int maxHeapMB = 0;
59
60
61
62
63 private Set<String> coprocessors =
64 new TreeSet<String>();
65
66
67
68
69
70
71
72
73
74
75
76
77 public String[] getCoprocessors() {
78 TreeSet<String> returnValue = new TreeSet<String>(coprocessors);
79 for (Map.Entry<byte[], RegionLoad> rls: getRegionsLoad().entrySet()) {
80 for (String coprocessor: rls.getValue().getCoprocessors()) {
81 returnValue.add(coprocessor);
82 }
83 }
84 return returnValue.toArray(new String[0]);
85 }
86
87
88 private Map<byte[], RegionLoad> regionLoad =
89 new TreeMap<byte[], RegionLoad>(Bytes.BYTES_COMPARATOR);
90
91
92 public byte getVersion() {
93 return VERSION;
94 }
95
96
97
98
99 public static class RegionLoad extends VersionedWritable {
100 private static final byte VERSION = 1;
101
102
103 public byte getVersion() {
104 return VERSION;
105 }
106
107
108 private byte[] name;
109
110 private int stores;
111
112 private int storefiles;
113
114 private int storeUncompressedSizeMB;
115
116 private int storefileSizeMB;
117
118 private int memstoreSizeMB;
119
120
121
122
123
124 private int storefileIndexSizeMB;
125
126 private int readRequestsCount;
127
128 private int writeRequestsCount;
129
130 private long totalCompactingKVs;
131
132 private long currentCompactedKVs;
133
134
135 private int rootIndexSizeKB;
136
137
138 private int totalStaticIndexSizeKB;
139
140
141
142
143
144 private int totalStaticBloomSizeKB;
145
146
147 Set<String> coprocessors =
148 new TreeSet<String>();
149
150
151
152
153 public RegionLoad() {
154 super();
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 public RegionLoad(final byte[] name, final int stores,
172 final int storefiles, final int storeUncompressedSizeMB,
173 final int storefileSizeMB,
174 final int memstoreSizeMB, final int storefileIndexSizeMB,
175 final int rootIndexSizeKB, final int totalStaticIndexSizeKB,
176 final int totalStaticBloomSizeKB,
177 final int readRequestsCount, final int writeRequestsCount,
178 final long totalCompactingKVs, final long currentCompactedKVs,
179 final Set<String> coprocessors) {
180 this.name = name;
181 this.stores = stores;
182 this.storefiles = storefiles;
183 this.storeUncompressedSizeMB = storeUncompressedSizeMB;
184 this.storefileSizeMB = storefileSizeMB;
185 this.memstoreSizeMB = memstoreSizeMB;
186 this.storefileIndexSizeMB = storefileIndexSizeMB;
187 this.rootIndexSizeKB = rootIndexSizeKB;
188 this.totalStaticIndexSizeKB = totalStaticIndexSizeKB;
189 this.totalStaticBloomSizeKB = totalStaticBloomSizeKB;
190 this.readRequestsCount = readRequestsCount;
191 this.writeRequestsCount = writeRequestsCount;
192 this.totalCompactingKVs = totalCompactingKVs;
193 this.currentCompactedKVs = currentCompactedKVs;
194 this.coprocessors = coprocessors;
195 }
196
197
198 private String[] getCoprocessors() {
199 return coprocessors.toArray(new String[0]);
200 }
201
202
203
204
205 public byte[] getName() {
206 return name;
207 }
208
209
210
211
212 public String getNameAsString() {
213 return Bytes.toString(name);
214 }
215
216
217
218
219 public int getStores() {
220 return stores;
221 }
222
223
224
225
226 public int getStorefiles() {
227 return storefiles;
228 }
229
230
231
232
233 public int getStorefileSizeMB() {
234 return storefileSizeMB;
235 }
236
237
238
239
240 public int getMemStoreSizeMB() {
241 return memstoreSizeMB;
242 }
243
244
245
246
247 public int getStorefileIndexSizeMB() {
248 return storefileIndexSizeMB;
249 }
250
251
252
253
254 public long getRequestsCount() {
255 return readRequestsCount + writeRequestsCount;
256 }
257
258
259
260
261 public long getReadRequestsCount() {
262 return readRequestsCount;
263 }
264
265
266
267
268 public long getWriteRequestsCount() {
269 return writeRequestsCount;
270 }
271
272
273
274
275 public long getTotalCompactingKVs() {
276 return totalCompactingKVs;
277 }
278
279
280
281
282 public long getCurrentCompactedKVs() {
283 return currentCompactedKVs;
284 }
285
286
287
288
289
290
291 public void setName(byte[] name) {
292 this.name = name;
293 }
294
295
296
297
298 public void setStores(int stores) {
299 this.stores = stores;
300 }
301
302
303
304
305 public void setStorefiles(int storefiles) {
306 this.storefiles = storefiles;
307 }
308
309
310
311
312 public void setMemStoreSizeMB(int memstoreSizeMB) {
313 this.memstoreSizeMB = memstoreSizeMB;
314 }
315
316
317
318
319
320 public void setStorefileIndexSizeMB(int storefileIndexSizeMB) {
321 this.storefileIndexSizeMB = storefileIndexSizeMB;
322 }
323
324
325
326
327 public void setReadRequestsCount(int requestsCount) {
328 this.readRequestsCount = requestsCount;
329 }
330
331
332
333
334 public void setWriteRequestsCount(int requestsCount) {
335 this.writeRequestsCount = requestsCount;
336 }
337
338
339
340
341 public void setTotalCompactingKVs(long totalCompactingKVs) {
342 this.totalCompactingKVs = totalCompactingKVs;
343 }
344
345
346
347
348
349 public void setCurrentCompactedKVs(long currentCompactedKVs) {
350 this.currentCompactedKVs = currentCompactedKVs;
351 }
352
353
354 public void readFields(DataInput in) throws IOException {
355 super.readFields(in);
356 int version = in.readByte();
357 if (version > VERSION) throw new IOException("Version mismatch; " + version);
358 int namelen = in.readInt();
359 this.name = new byte[namelen];
360 in.readFully(this.name);
361 this.stores = in.readInt();
362 this.storefiles = in.readInt();
363 this.storeUncompressedSizeMB = in.readInt();
364 this.storefileSizeMB = in.readInt();
365 this.memstoreSizeMB = in.readInt();
366 this.storefileIndexSizeMB = in.readInt();
367 this.readRequestsCount = in.readInt();
368 this.writeRequestsCount = in.readInt();
369 this.rootIndexSizeKB = in.readInt();
370 this.totalStaticIndexSizeKB = in.readInt();
371 this.totalStaticBloomSizeKB = in.readInt();
372 this.totalCompactingKVs = in.readLong();
373 this.currentCompactedKVs = in.readLong();
374 int coprocessorsSize = in.readInt();
375 coprocessors = new TreeSet<String>();
376 for (int i = 0; i < coprocessorsSize; i++) {
377 coprocessors.add(in.readUTF());
378 }
379 }
380
381 public void write(DataOutput out) throws IOException {
382 super.write(out);
383 out.writeByte(VERSION);
384 out.writeInt(name.length);
385 out.write(name);
386 out.writeInt(stores);
387 out.writeInt(storefiles);
388 out.writeInt(storeUncompressedSizeMB);
389 out.writeInt(storefileSizeMB);
390 out.writeInt(memstoreSizeMB);
391 out.writeInt(storefileIndexSizeMB);
392 out.writeInt(readRequestsCount);
393 out.writeInt(writeRequestsCount);
394 out.writeInt(rootIndexSizeKB);
395 out.writeInt(totalStaticIndexSizeKB);
396 out.writeInt(totalStaticBloomSizeKB);
397 out.writeLong(totalCompactingKVs);
398 out.writeLong(currentCompactedKVs);
399 out.writeInt(coprocessors.size());
400 for (String coprocessor: coprocessors) {
401 out.writeUTF(coprocessor);
402 }
403 }
404
405
406
407
408 @Override
409 public String toString() {
410 StringBuilder sb = Strings.appendKeyValue(new StringBuilder(), "numberOfStores",
411 Integer.valueOf(this.stores));
412 sb = Strings.appendKeyValue(sb, "numberOfStorefiles",
413 Integer.valueOf(this.storefiles));
414 sb = Strings.appendKeyValue(sb, "storefileUncompressedSizeMB",
415 Integer.valueOf(this.storeUncompressedSizeMB));
416 sb = Strings.appendKeyValue(sb, "storefileSizeMB",
417 Integer.valueOf(this.storefileSizeMB));
418 if (this.storeUncompressedSizeMB != 0) {
419 sb = Strings.appendKeyValue(sb, "compressionRatio",
420 String.format("%.4f", (float)this.storefileSizeMB/
421 (float)this.storeUncompressedSizeMB));
422 }
423 sb = Strings.appendKeyValue(sb, "memstoreSizeMB",
424 Integer.valueOf(this.memstoreSizeMB));
425 sb = Strings.appendKeyValue(sb, "storefileIndexSizeMB",
426 Integer.valueOf(this.storefileIndexSizeMB));
427 sb = Strings.appendKeyValue(sb, "readRequestsCount",
428 Long.valueOf(this.readRequestsCount));
429 sb = Strings.appendKeyValue(sb, "writeRequestsCount",
430 Long.valueOf(this.writeRequestsCount));
431 sb = Strings.appendKeyValue(sb, "rootIndexSizeKB",
432 Integer.valueOf(this.rootIndexSizeKB));
433 sb = Strings.appendKeyValue(sb, "totalStaticIndexSizeKB",
434 Integer.valueOf(this.totalStaticIndexSizeKB));
435 sb = Strings.appendKeyValue(sb, "totalStaticBloomSizeKB",
436 Integer.valueOf(this.totalStaticBloomSizeKB));
437 sb = Strings.appendKeyValue(sb, "totalCompactingKVs",
438 Long.valueOf(this.totalCompactingKVs));
439 sb = Strings.appendKeyValue(sb, "currentCompactedKVs",
440 Long.valueOf(this.currentCompactedKVs));
441 float compactionProgressPct = Float.NaN;
442 if( this.totalCompactingKVs > 0 ) {
443 compactionProgressPct = Float.valueOf(
444 this.currentCompactedKVs / this.totalCompactingKVs);
445 }
446 sb = Strings.appendKeyValue(sb, "compactionProgressPct",
447 compactionProgressPct);
448 String coprocessors = Arrays.toString(getCoprocessors());
449 if (coprocessors != null) {
450 sb = Strings.appendKeyValue(sb, "coprocessors",
451 Arrays.toString(getCoprocessors()));
452 }
453 return sb.toString();
454 }
455 }
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 public HServerLoad092() {
472 super();
473 }
474
475
476
477
478
479
480
481
482 public HServerLoad092(final int totalNumberOfRequests,
483 final int numberOfRequests, final int usedHeapMB, final int maxHeapMB,
484 final Map<byte[], RegionLoad> regionLoad,
485 final Set<String> coprocessors) {
486 this.numberOfRequests = numberOfRequests;
487 this.usedHeapMB = usedHeapMB;
488 this.maxHeapMB = maxHeapMB;
489 this.regionLoad = regionLoad;
490 this.totalNumberOfRequests = totalNumberOfRequests;
491 this.coprocessors = coprocessors;
492 }
493
494
495
496
497
498 public HServerLoad092(final HServerLoad092 hsl) {
499 this(hsl.totalNumberOfRequests, hsl.numberOfRequests, hsl.usedHeapMB,
500 hsl.maxHeapMB, hsl.getRegionsLoad(), hsl.coprocessors);
501 for (Map.Entry<byte[], RegionLoad> e : hsl.regionLoad.entrySet()) {
502 this.regionLoad.put(e.getKey(), e.getValue());
503 }
504 }
505
506
507
508
509
510
511
512
513
514
515 public int getLoad() {
516
517
518
519 return this.regionLoad.size();
520 }
521
522
523
524
525 @Override
526 public String toString() {
527 return toString(1);
528 }
529
530
531
532
533
534
535
536 public String toString(int msgInterval) {
537 int numberOfRegions = this.regionLoad.size();
538 StringBuilder sb = new StringBuilder();
539 sb = Strings.appendKeyValue(sb, "requestsPerSecond",
540 Integer.valueOf(numberOfRequests/msgInterval));
541 sb = Strings.appendKeyValue(sb, "numberOfOnlineRegions",
542 Integer.valueOf(numberOfRegions));
543 sb = Strings.appendKeyValue(sb, "usedHeapMB",
544 Integer.valueOf(this.usedHeapMB));
545 sb = Strings.appendKeyValue(sb, "maxHeapMB", Integer.valueOf(maxHeapMB));
546 return sb.toString();
547 }
548
549
550
551
552 @Override
553 public boolean equals(Object o) {
554 if (this == o) {
555 return true;
556 }
557 if (o == null) {
558 return false;
559 }
560 if (getClass() != o.getClass()) {
561 return false;
562 }
563 return compareTo((HServerLoad092)o) == 0;
564 }
565
566
567
568
569
570
571 public int getNumberOfRegions() {
572 return this.regionLoad.size();
573 }
574
575
576
577
578 public int getNumberOfRequests() {
579 return numberOfRequests;
580 }
581
582
583
584
585 public int getTotalNumberOfRequests() {
586 return totalNumberOfRequests;
587 }
588
589
590
591
592 public int getUsedHeapMB() {
593 return usedHeapMB;
594 }
595
596
597
598
599 public int getMaxHeapMB() {
600 return maxHeapMB;
601 }
602
603
604
605
606 public Map<byte[], RegionLoad> getRegionsLoad() {
607 return Collections.unmodifiableMap(regionLoad);
608 }
609
610
611
612
613 public int getStorefiles() {
614 int count = 0;
615 for (RegionLoad info: regionLoad.values())
616 count += info.getStorefiles();
617 return count;
618 }
619
620
621
622
623 public int getStorefileSizeInMB() {
624 int count = 0;
625 for (RegionLoad info: regionLoad.values())
626 count += info.getStorefileSizeMB();
627 return count;
628 }
629
630
631
632
633 public int getMemStoreSizeInMB() {
634 int count = 0;
635 for (RegionLoad info: regionLoad.values())
636 count += info.getMemStoreSizeMB();
637 return count;
638 }
639
640
641
642
643 public int getStorefileIndexSizeInMB() {
644 int count = 0;
645 for (RegionLoad info: regionLoad.values())
646 count += info.getStorefileIndexSizeMB();
647 return count;
648 }
649
650
651
652 public void readFields(DataInput in) throws IOException {
653 super.readFields(in);
654 int version = in.readByte();
655 if (version > VERSION) throw new IOException("Version mismatch; " + version);
656 numberOfRequests = in.readInt();
657 usedHeapMB = in.readInt();
658 maxHeapMB = in.readInt();
659 int numberOfRegions = in.readInt();
660 for (int i = 0; i < numberOfRegions; i++) {
661 RegionLoad rl = new RegionLoad();
662 rl.readFields(in);
663 regionLoad.put(rl.getName(), rl);
664 }
665 totalNumberOfRequests = in.readInt();
666 int coprocessorsSize = in.readInt();
667 for(int i = 0; i < coprocessorsSize; i++) {
668 coprocessors.add(in.readUTF());
669 }
670 }
671
672 public void write(DataOutput out) throws IOException {
673 super.write(out);
674 out.writeByte(VERSION);
675 out.writeInt(numberOfRequests);
676 out.writeInt(usedHeapMB);
677 out.writeInt(maxHeapMB);
678 out.writeInt(this.regionLoad.size());
679 for (RegionLoad rl: regionLoad.values())
680 rl.write(out);
681 out.writeInt(totalNumberOfRequests);
682 out.writeInt(coprocessors.size());
683 for (String coprocessor: coprocessors) {
684 out.writeUTF(coprocessor);
685 }
686 }
687
688
689
690 public int compareTo(HServerLoad092 o) {
691 return this.getLoad() - o.getLoad();
692 }
693 }