1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase;
21
22 import java.io.DataInput;
23 import java.io.DataOutput;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Set;
33 import java.util.TreeMap;
34 import java.util.regex.Matcher;
35
36 import org.apache.hadoop.conf.Configuration;
37 import org.apache.hadoop.fs.Path;
38 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
39 import org.apache.hadoop.hbase.security.User;
40 import org.apache.hadoop.hbase.util.Bytes;
41 import org.apache.hadoop.io.WritableComparable;
42
43
44
45
46
47
48
49 public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
50
51
52
53
54
55
56
57 private static final byte TABLE_DESCRIPTOR_VERSION = 5;
58
59 private byte [] name = HConstants.EMPTY_BYTE_ARRAY;
60
61 private String nameAsString = "";
62
63
64
65
66
67
68 protected Map<ImmutableBytesWritable, ImmutableBytesWritable> values =
69 new HashMap<ImmutableBytesWritable, ImmutableBytesWritable>();
70
71 private static final String FAMILIES = "FAMILIES";
72
73 public static final String SPLIT_POLICY = "SPLIT_POLICY";
74
75
76
77
78
79
80
81
82 public static final String MAX_FILESIZE = "MAX_FILESIZE";
83 private static final ImmutableBytesWritable MAX_FILESIZE_KEY =
84 new ImmutableBytesWritable(Bytes.toBytes(MAX_FILESIZE));
85
86 public static final String OWNER = "OWNER";
87 public static final ImmutableBytesWritable OWNER_KEY =
88 new ImmutableBytesWritable(Bytes.toBytes(OWNER));
89
90
91
92
93
94
95
96 public static final String READONLY = "READONLY";
97 private static final ImmutableBytesWritable READONLY_KEY =
98 new ImmutableBytesWritable(Bytes.toBytes(READONLY));
99
100
101
102
103
104
105
106
107 public static final String MEMSTORE_FLUSHSIZE = "MEMSTORE_FLUSHSIZE";
108 private static final ImmutableBytesWritable MEMSTORE_FLUSHSIZE_KEY =
109 new ImmutableBytesWritable(Bytes.toBytes(MEMSTORE_FLUSHSIZE));
110
111
112
113
114
115
116
117 public static final String IS_ROOT = "IS_ROOT";
118 private static final ImmutableBytesWritable IS_ROOT_KEY =
119 new ImmutableBytesWritable(Bytes.toBytes(IS_ROOT));
120
121
122
123
124
125
126
127
128 public static final String IS_META = "IS_META";
129 private static final ImmutableBytesWritable IS_META_KEY =
130 new ImmutableBytesWritable(Bytes.toBytes(IS_META));
131
132
133
134
135
136 public static final String DEFERRED_LOG_FLUSH = "DEFERRED_LOG_FLUSH";
137 private static final ImmutableBytesWritable DEFERRED_LOG_FLUSH_KEY =
138 new ImmutableBytesWritable(Bytes.toBytes(DEFERRED_LOG_FLUSH));
139
140
141
142
143
144
145 private static final ImmutableBytesWritable FALSE =
146 new ImmutableBytesWritable(Bytes.toBytes(Boolean.FALSE.toString()));
147
148 private static final ImmutableBytesWritable TRUE =
149 new ImmutableBytesWritable(Bytes.toBytes(Boolean.TRUE.toString()));
150
151 private static final boolean DEFAULT_DEFERRED_LOG_FLUSH = false;
152
153
154
155
156 public static final boolean DEFAULT_READONLY = false;
157
158
159
160
161
162 public static final long DEFAULT_MEMSTORE_FLUSH_SIZE = 1024*1024*128L;
163
164 private volatile Boolean meta = null;
165 private volatile Boolean root = null;
166 private Boolean isDeferredLog = null;
167
168
169
170
171 private final Map<byte [], HColumnDescriptor> families =
172 new TreeMap<byte [], HColumnDescriptor>(Bytes.BYTES_RAWCOMPARATOR);
173
174
175
176
177
178 protected HTableDescriptor(final byte [] name, HColumnDescriptor[] families) {
179 this.name = name.clone();
180 this.nameAsString = Bytes.toString(this.name);
181 setMetaFlags(name);
182 for(HColumnDescriptor descriptor : families) {
183 this.families.put(descriptor.getName(), descriptor);
184 }
185 }
186
187
188
189
190
191 protected HTableDescriptor(final byte [] name, HColumnDescriptor[] families,
192 Map<ImmutableBytesWritable,ImmutableBytesWritable> values) {
193 this.name = name.clone();
194 this.nameAsString = Bytes.toString(this.name);
195 setMetaFlags(name);
196 for(HColumnDescriptor descriptor : families) {
197 this.families.put(descriptor.getName(), descriptor);
198 }
199 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> entry:
200 values.entrySet()) {
201 this.values.put(entry.getKey(), entry.getValue());
202 }
203 }
204
205
206
207
208
209
210 public HTableDescriptor() {
211 super();
212 }
213
214
215
216
217
218
219
220
221
222 public HTableDescriptor(final String name) {
223 this(Bytes.toBytes(name));
224 }
225
226
227
228
229
230
231
232
233
234 public HTableDescriptor(final byte [] name) {
235 super();
236 setMetaFlags(this.name);
237 this.name = this.isMetaRegion()? name: isLegalTableName(name);
238 this.nameAsString = Bytes.toString(this.name);
239 }
240
241
242
243
244
245
246
247
248 public HTableDescriptor(final HTableDescriptor desc) {
249 super();
250 this.name = desc.name.clone();
251 this.nameAsString = Bytes.toString(this.name);
252 setMetaFlags(this.name);
253 for (HColumnDescriptor c: desc.families.values()) {
254 this.families.put(c.getName(), new HColumnDescriptor(c));
255 }
256 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
257 desc.values.entrySet()) {
258 this.values.put(e.getKey(), e.getValue());
259 }
260 }
261
262
263
264
265
266
267
268
269 private void setMetaFlags(final byte [] name) {
270 setRootRegion(Bytes.equals(name, HConstants.ROOT_TABLE_NAME));
271 setMetaRegion(isRootRegion() ||
272 Bytes.equals(name, HConstants.META_TABLE_NAME));
273 }
274
275
276
277
278
279
280 public boolean isRootRegion() {
281 if (this.root == null) {
282 this.root = isSomething(IS_ROOT_KEY, false)? Boolean.TRUE: Boolean.FALSE;
283 }
284 return this.root.booleanValue();
285 }
286
287
288
289
290
291
292
293
294 protected void setRootRegion(boolean isRoot) {
295
296 values.put(IS_ROOT_KEY, isRoot? TRUE: FALSE);
297 }
298
299
300
301
302
303
304
305
306 public boolean isMetaRegion() {
307 if (this.meta == null) {
308 this.meta = calculateIsMetaRegion();
309 }
310 return this.meta.booleanValue();
311 }
312
313 private synchronized Boolean calculateIsMetaRegion() {
314 byte [] value = getValue(IS_META_KEY);
315 return (value != null)? Boolean.valueOf(Bytes.toString(value)): Boolean.FALSE;
316 }
317
318 private boolean isSomething(final ImmutableBytesWritable key,
319 final boolean valueIfNull) {
320 byte [] value = getValue(key);
321 if (value != null) {
322
323 return Boolean.valueOf(Bytes.toString(value)).booleanValue();
324 }
325 return valueIfNull;
326 }
327
328
329
330
331
332
333
334
335
336 protected void setMetaRegion(boolean isMeta) {
337 values.put(IS_META_KEY, isMeta? TRUE: FALSE);
338 }
339
340
341
342
343
344
345 public boolean isMetaTable() {
346 return isMetaRegion() && !isRootRegion();
347 }
348
349
350
351
352
353
354
355
356 public static boolean isMetaTable(final byte [] tableName) {
357 return Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME) ||
358 Bytes.equals(tableName, HConstants.META_TABLE_NAME);
359 }
360
361
362 public static final String VALID_USER_TABLE_REGEX = "(?:[a-zA-Z_0-9][a-zA-Z_0-9.-]*)";
363
364
365
366
367
368
369
370
371
372 public static byte [] isLegalTableName(final byte [] tableName) {
373 if (tableName == null || tableName.length <= 0) {
374 throw new IllegalArgumentException("Name is null or empty");
375 }
376 if (tableName[0] == '.' || tableName[0] == '-') {
377 throw new IllegalArgumentException("Illegal first character <" + tableName[0] +
378 "> at 0. User-space table names can only start with 'word " +
379 "characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(tableName));
380 }
381 for (int i = 0; i < tableName.length; i++) {
382 if (Character.isLetterOrDigit(tableName[i]) || tableName[i] == '_' ||
383 tableName[i] == '-' || tableName[i] == '.') {
384 continue;
385 }
386 throw new IllegalArgumentException("Illegal character <" + tableName[i] +
387 "> at " + i + ". User-space table names can only contain " +
388 "'word characters': i.e. [a-zA-Z_0-9-.]: " + Bytes.toString(tableName));
389 }
390 return tableName;
391 }
392
393
394
395
396
397
398
399
400 public byte[] getValue(byte[] key) {
401 return getValue(new ImmutableBytesWritable(key));
402 }
403
404 private byte[] getValue(final ImmutableBytesWritable key) {
405 ImmutableBytesWritable ibw = values.get(key);
406 if (ibw == null)
407 return null;
408 return ibw.get();
409 }
410
411
412
413
414
415
416
417
418 public String getValue(String key) {
419 byte[] value = getValue(Bytes.toBytes(key));
420 if (value == null)
421 return null;
422 return Bytes.toString(value);
423 }
424
425
426
427
428
429
430
431 public Map<ImmutableBytesWritable,ImmutableBytesWritable> getValues() {
432 return Collections.unmodifiableMap(values);
433 }
434
435
436
437
438
439
440
441
442 public void setValue(byte[] key, byte[] value) {
443 setValue(new ImmutableBytesWritable(key), value);
444 }
445
446
447
448
449
450 private void setValue(final ImmutableBytesWritable key,
451 final byte[] value) {
452 values.put(key, new ImmutableBytesWritable(value));
453 }
454
455
456
457
458
459 private void setValue(final ImmutableBytesWritable key,
460 final ImmutableBytesWritable value) {
461 values.put(key, value);
462 }
463
464
465
466
467
468
469
470
471 public void setValue(String key, String value) {
472 setValue(Bytes.toBytes(key), Bytes.toBytes(value));
473 }
474
475
476
477
478
479
480
481 public void remove(final byte [] key) {
482 values.remove(new ImmutableBytesWritable(key));
483 }
484
485
486
487
488
489
490
491 public void remove(final String key) {
492 remove(Bytes.toBytes(key));
493 }
494
495
496
497
498
499
500
501 public boolean isReadOnly() {
502 return isSomething(READONLY_KEY, DEFAULT_READONLY);
503 }
504
505
506
507
508
509
510
511
512
513 public void setReadOnly(final boolean readOnly) {
514 setValue(READONLY_KEY, readOnly? TRUE: FALSE);
515 }
516
517
518
519
520
521
522
523
524 public synchronized boolean isDeferredLogFlush() {
525 if(this.isDeferredLog == null) {
526 this.isDeferredLog =
527 isSomething(DEFERRED_LOG_FLUSH_KEY, DEFAULT_DEFERRED_LOG_FLUSH);
528 }
529 return this.isDeferredLog;
530 }
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546 public void setDeferredLogFlush(final boolean isDeferredLogFlush) {
547 setValue(DEFERRED_LOG_FLUSH_KEY, isDeferredLogFlush? TRUE: FALSE);
548 this.isDeferredLog = isDeferredLogFlush;
549 }
550
551
552
553
554
555
556 public byte [] getName() {
557 return name;
558 }
559
560
561
562
563
564
565 public String getNameAsString() {
566 return this.nameAsString;
567 }
568
569
570
571
572
573
574
575
576
577
578
579 public String getRegionSplitPolicyClassName() {
580 return getValue(SPLIT_POLICY);
581 }
582
583
584
585
586
587
588 public void setName(byte[] name) {
589 this.name = name;
590 this.nameAsString = Bytes.toString(this.name);
591 setMetaFlags(this.name);
592 }
593
594
595
596
597
598
599
600
601
602
603 public long getMaxFileSize() {
604 byte [] value = getValue(MAX_FILESIZE_KEY);
605 if (value != null) {
606 return Long.parseLong(Bytes.toString(value));
607 }
608 return -1;
609 }
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626 public void setMaxFileSize(long maxFileSize) {
627 setValue(MAX_FILESIZE_KEY, Bytes.toBytes(Long.toString(maxFileSize)));
628 }
629
630
631
632
633
634
635
636
637 public long getMemStoreFlushSize() {
638 byte [] value = getValue(MEMSTORE_FLUSHSIZE_KEY);
639 if (value != null) {
640 return Long.parseLong(Bytes.toString(value));
641 }
642 return -1;
643 }
644
645
646
647
648
649
650
651 public void setMemStoreFlushSize(long memstoreFlushSize) {
652 setValue(MEMSTORE_FLUSHSIZE_KEY,
653 Bytes.toBytes(Long.toString(memstoreFlushSize)));
654 }
655
656
657
658
659
660 public void addFamily(final HColumnDescriptor family) {
661 if (family.getName() == null || family.getName().length <= 0) {
662 throw new NullPointerException("Family name cannot be null or empty");
663 }
664 this.families.put(family.getName(), family);
665 }
666
667
668
669
670
671
672 public boolean hasFamily(final byte [] familyName) {
673 return families.containsKey(familyName);
674 }
675
676
677
678
679
680
681 @Override
682 public String toString() {
683 StringBuilder s = new StringBuilder();
684 s.append('{');
685 s.append(HConstants.NAME);
686 s.append(" => '");
687 s.append(Bytes.toString(name));
688 s.append("'");
689 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
690 values.entrySet()) {
691 String key = Bytes.toString(e.getKey().get());
692 String value = Bytes.toString(e.getValue().get());
693 if (key == null) {
694 continue;
695 }
696 String upperCase = key.toUpperCase();
697 if (upperCase.equals(IS_ROOT) || upperCase.equals(IS_META)) {
698
699 if (value.toLowerCase().equals(Boolean.FALSE.toString())) {
700 continue;
701 }
702 }
703 s.append(", ");
704 s.append(Bytes.toString(e.getKey().get()));
705 s.append(" => '");
706 s.append(Bytes.toString(e.getValue().get()));
707 s.append("'");
708 }
709 s.append(", ");
710 s.append(FAMILIES);
711 s.append(" => ");
712 s.append(families.values());
713 s.append('}');
714 return s.toString();
715 }
716
717
718
719
720
721 public String toStringCustomizedValues() {
722 StringBuilder s = new StringBuilder();
723 s.append('{');
724 s.append(HConstants.NAME);
725 s.append(" => '");
726 s.append(Bytes.toString(name));
727 s.append("'");
728 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
729 values.entrySet()) {
730 String key = Bytes.toString(e.getKey().get());
731 String value = Bytes.toString(e.getValue().get());
732 if (key == null) {
733 continue;
734 }
735 String upperCase = key.toUpperCase();
736 if (upperCase.equals(IS_ROOT) || upperCase.equals(IS_META)) {
737
738 if (value.toLowerCase().equals(Boolean.FALSE.toString())) {
739 continue;
740 }
741 }
742 s.append(", ");
743 s.append(Bytes.toString(e.getKey().get()));
744 s.append(" => '");
745 s.append(Bytes.toString(e.getValue().get()));
746 s.append("'");
747 }
748 s.append(", ");
749 s.append(FAMILIES);
750 s.append(" => [");
751 int size = families.values().size();
752 int i = 0;
753 for(HColumnDescriptor hcd : families.values()) {
754 s.append(hcd.toStringCustomizedValues());
755 i++;
756 if( i != size)
757 s.append(", ");
758 }
759 s.append("]}");
760 return s.toString();
761 }
762
763
764
765
766
767
768
769
770
771
772 @Override
773 public boolean equals(Object obj) {
774 if (this == obj) {
775 return true;
776 }
777 if (obj == null) {
778 return false;
779 }
780 if (!(obj instanceof HTableDescriptor)) {
781 return false;
782 }
783 return compareTo((HTableDescriptor)obj) == 0;
784 }
785
786
787
788
789 @Override
790 public int hashCode() {
791 int result = Bytes.hashCode(this.name);
792 result ^= Byte.valueOf(TABLE_DESCRIPTOR_VERSION).hashCode();
793 if (this.families != null && this.families.size() > 0) {
794 for (HColumnDescriptor e: this.families.values()) {
795 result ^= e.hashCode();
796 }
797 }
798 result ^= values.hashCode();
799 return result;
800 }
801
802
803
804
805
806
807 @Override
808 public void readFields(DataInput in) throws IOException {
809 int version = in.readInt();
810 if (version < 3)
811 throw new IOException("versions < 3 are not supported (and never existed!?)");
812
813 name = Bytes.readByteArray(in);
814 nameAsString = Bytes.toString(this.name);
815 setRootRegion(in.readBoolean());
816 setMetaRegion(in.readBoolean());
817 values.clear();
818 int numVals = in.readInt();
819 for (int i = 0; i < numVals; i++) {
820 ImmutableBytesWritable key = new ImmutableBytesWritable();
821 ImmutableBytesWritable value = new ImmutableBytesWritable();
822 key.readFields(in);
823 value.readFields(in);
824 values.put(key, value);
825 }
826 families.clear();
827 int numFamilies = in.readInt();
828 for (int i = 0; i < numFamilies; i++) {
829 HColumnDescriptor c = new HColumnDescriptor();
830 c.readFields(in);
831 families.put(c.getName(), c);
832 }
833 if (version < 4) {
834 return;
835 }
836 }
837
838
839
840
841
842 @Override
843 public void write(DataOutput out) throws IOException {
844 out.writeInt(TABLE_DESCRIPTOR_VERSION);
845 Bytes.writeByteArray(out, name);
846 out.writeBoolean(isRootRegion());
847 out.writeBoolean(isMetaRegion());
848 out.writeInt(values.size());
849 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
850 values.entrySet()) {
851 e.getKey().write(out);
852 e.getValue().write(out);
853 }
854 out.writeInt(families.size());
855 for(Iterator<HColumnDescriptor> it = families.values().iterator();
856 it.hasNext(); ) {
857 HColumnDescriptor family = it.next();
858 family.write(out);
859 }
860 }
861
862
863
864
865
866
867
868
869
870
871 @Override
872 public int compareTo(final HTableDescriptor other) {
873 int result = Bytes.compareTo(this.name, other.name);
874 if (result == 0) {
875 result = families.size() - other.families.size();
876 }
877 if (result == 0 && families.size() != other.families.size()) {
878 result = Integer.valueOf(families.size()).compareTo(
879 Integer.valueOf(other.families.size()));
880 }
881 if (result == 0) {
882 for (Iterator<HColumnDescriptor> it = families.values().iterator(),
883 it2 = other.families.values().iterator(); it.hasNext(); ) {
884 result = it.next().compareTo(it2.next());
885 if (result != 0) {
886 break;
887 }
888 }
889 }
890 if (result == 0) {
891
892 result = this.values.hashCode() - other.values.hashCode();
893 if (result < 0)
894 result = -1;
895 else if (result > 0)
896 result = 1;
897 }
898 return result;
899 }
900
901
902
903
904
905
906
907
908 public Collection<HColumnDescriptor> getFamilies() {
909 return Collections.unmodifiableCollection(this.families.values());
910 }
911
912
913
914
915
916
917
918
919
920 public Set<byte[]> getFamiliesKeys() {
921 return Collections.unmodifiableSet(this.families.keySet());
922 }
923
924
925
926
927
928
929
930
931
932 public HColumnDescriptor[] getColumnFamilies() {
933 return getFamilies().toArray(new HColumnDescriptor[0]);
934 }
935
936
937
938
939
940
941
942
943
944
945 public HColumnDescriptor getFamily(final byte [] column) {
946 return this.families.get(column);
947 }
948
949
950
951
952
953
954
955
956
957
958 public HColumnDescriptor removeFamily(final byte [] column) {
959 return this.families.remove(column);
960 }
961
962
963
964
965
966
967
968
969
970
971
972
973 public void addCoprocessor(String className) throws IOException {
974 addCoprocessor(className, null, Coprocessor.PRIORITY_USER, null);
975 }
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992 public void addCoprocessor(String className, Path jarFilePath,
993 int priority, final Map<String, String> kvs)
994 throws IOException {
995 if (hasCoprocessor(className)) {
996 throw new IOException("Coprocessor " + className + " already exists.");
997 }
998
999 StringBuilder kvString = new StringBuilder();
1000 if (kvs != null) {
1001 for (Map.Entry<String, String> e: kvs.entrySet()) {
1002 if (!e.getKey().matches(HConstants.CP_HTD_ATTR_VALUE_PARAM_KEY_PATTERN)) {
1003 throw new IOException("Illegal parameter key = " + e.getKey());
1004 }
1005 if (!e.getValue().matches(HConstants.CP_HTD_ATTR_VALUE_PARAM_VALUE_PATTERN)) {
1006 throw new IOException("Illegal parameter (" + e.getKey() +
1007 ") value = " + e.getValue());
1008 }
1009 if (kvString.length() != 0) {
1010 kvString.append(',');
1011 }
1012 kvString.append(e.getKey());
1013 kvString.append('=');
1014 kvString.append(e.getValue());
1015 }
1016 }
1017
1018
1019 int maxCoprocessorNumber = 0;
1020 Matcher keyMatcher;
1021 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
1022 this.values.entrySet()) {
1023 keyMatcher =
1024 HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(
1025 Bytes.toString(e.getKey().get()));
1026 if (!keyMatcher.matches()) {
1027 continue;
1028 }
1029 maxCoprocessorNumber = Math.max(Integer.parseInt(keyMatcher.group(1)),
1030 maxCoprocessorNumber);
1031 }
1032 maxCoprocessorNumber++;
1033
1034 String key = "coprocessor$" + Integer.toString(maxCoprocessorNumber);
1035 String value = ((jarFilePath == null)? "" : jarFilePath.toString()) +
1036 "|" + className + "|" + Integer.toString(priority) + "|" +
1037 kvString.toString();
1038 setValue(key, value);
1039 }
1040
1041
1042
1043
1044
1045
1046
1047
1048 public boolean hasCoprocessor(String className) {
1049 Matcher keyMatcher;
1050 Matcher valueMatcher;
1051 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
1052 this.values.entrySet()) {
1053 keyMatcher =
1054 HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(
1055 Bytes.toString(e.getKey().get()));
1056 if (!keyMatcher.matches()) {
1057 continue;
1058 }
1059 valueMatcher =
1060 HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(
1061 Bytes.toString(e.getValue().get()));
1062 if (!valueMatcher.matches()) {
1063 continue;
1064 }
1065
1066 String clazz = valueMatcher.group(2).trim();
1067 if (clazz.equals(className.trim())) {
1068 return true;
1069 }
1070 }
1071 return false;
1072 }
1073
1074
1075
1076
1077
1078
1079 public List<String> getCoprocessors() {
1080 List<String> result = new ArrayList<String>();
1081 Matcher keyMatcher;
1082 Matcher valueMatcher;
1083 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : this.values.entrySet()) {
1084 keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e.getKey().get()));
1085 if (!keyMatcher.matches()) {
1086 continue;
1087 }
1088 valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes
1089 .toString(e.getValue().get()));
1090 if (!valueMatcher.matches()) {
1091 continue;
1092 }
1093 result.add(valueMatcher.group(2).trim());
1094 }
1095 return result;
1096 }
1097
1098
1099
1100
1101
1102 public void removeCoprocessor(String className) {
1103 ImmutableBytesWritable match = null;
1104 Matcher keyMatcher;
1105 Matcher valueMatcher;
1106 for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e : this.values
1107 .entrySet()) {
1108 keyMatcher = HConstants.CP_HTD_ATTR_KEY_PATTERN.matcher(Bytes.toString(e
1109 .getKey().get()));
1110 if (!keyMatcher.matches()) {
1111 continue;
1112 }
1113 valueMatcher = HConstants.CP_HTD_ATTR_VALUE_PATTERN.matcher(Bytes
1114 .toString(e.getValue().get()));
1115 if (!valueMatcher.matches()) {
1116 continue;
1117 }
1118
1119 String clazz = valueMatcher.group(2).trim();
1120
1121 if (clazz.equals(className.trim())) {
1122 match = e.getKey();
1123 break;
1124 }
1125 }
1126
1127 if (match != null)
1128 this.values.remove(match);
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139 public static Path getTableDir(Path rootdir, final byte [] tableName) {
1140 return new Path(rootdir, Bytes.toString(tableName));
1141 }
1142
1143
1144 public static final HTableDescriptor ROOT_TABLEDESC = new HTableDescriptor(
1145 HConstants.ROOT_TABLE_NAME,
1146 new HColumnDescriptor[] {
1147 new HColumnDescriptor(HConstants.CATALOG_FAMILY)
1148
1149 .setMaxVersions(10)
1150 .setInMemory(true)
1151 .setBlocksize(8 * 1024)
1152 .setTimeToLive(HConstants.FOREVER)
1153 .setScope(HConstants.REPLICATION_SCOPE_LOCAL)
1154 });
1155
1156
1157 public static final HTableDescriptor META_TABLEDESC = new HTableDescriptor(
1158 HConstants.META_TABLE_NAME, new HColumnDescriptor[] {
1159 new HColumnDescriptor(HConstants.CATALOG_FAMILY)
1160
1161 .setMaxVersions(10)
1162 .setInMemory(true)
1163 .setBlocksize(8 * 1024)
1164 .setScope(HConstants.REPLICATION_SCOPE_LOCAL)
1165 });
1166
1167 @Deprecated
1168 public void setOwner(User owner) {
1169 setOwnerString(owner != null ? owner.getShortName() : null);
1170 }
1171
1172
1173 @Deprecated
1174 public void setOwnerString(String ownerString) {
1175 if (ownerString != null) {
1176 setValue(OWNER_KEY, Bytes.toBytes(ownerString));
1177 } else {
1178 values.remove(OWNER_KEY);
1179 }
1180 }
1181
1182 @Deprecated
1183 public String getOwnerString() {
1184 if (getValue(OWNER_KEY) != null) {
1185 return Bytes.toString(getValue(OWNER_KEY));
1186 }
1187
1188
1189
1190 return null;
1191 }
1192 }