1 /**
2 * Copyright 2010 The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package org.apache.hadoop.hbase;
21
22 import org.apache.hadoop.hbase.ipc.HRegionInterface;
23 import org.apache.hadoop.hbase.util.Bytes;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.UUID;
29 import java.util.regex.Pattern;
30
31 /**
32 * HConstants holds a bunch of HBase-related constants
33 */
34 public final class HConstants {
35 /**
36 * Status codes used for return values of bulk operations.
37 */
38 public enum OperationStatusCode {
39 NOT_RUN,
40 SUCCESS,
41 BAD_FAMILY,
42 FAILURE;
43 }
44
45 /** long constant for zero */
46 public static final Long ZERO_L = Long.valueOf(0L);
47 public static final String NINES = "99999999999999";
48 public static final String ZEROES = "00000000000000";
49
50 // For migration
51
52 /** name of version file */
53 public static final String VERSION_FILE_NAME = "hbase.version";
54
55 /**
56 * Current version of file system.
57 * Version 4 supports only one kind of bloom filter.
58 * Version 5 changes versions in catalog table regions.
59 * Version 6 enables blockcaching on catalog tables.
60 * Version 7 introduces hfile -- hbase 0.19 to 0.20..
61 */
62 // public static final String FILE_SYSTEM_VERSION = "6";
63 public static final String FILE_SYSTEM_VERSION = "7";
64
65 // Configuration parameters
66
67 //TODO: Is having HBase homed on port 60k OK?
68
69 /** Cluster is in distributed mode or not */
70 public static final String CLUSTER_DISTRIBUTED = "hbase.cluster.distributed";
71
72 /** Cluster is standalone or pseudo-distributed */
73 public static final String CLUSTER_IS_LOCAL = "false";
74
75 /** Cluster is fully-distributed */
76 public static final String CLUSTER_IS_DISTRIBUTED = "true";
77
78 /** default host address */
79 public static final String DEFAULT_HOST = "0.0.0.0";
80
81 /** Parameter name for port master listens on. */
82 public static final String MASTER_PORT = "hbase.master.port";
83
84 /** default port that the master listens on */
85 public static final int DEFAULT_MASTER_PORT = 60000;
86
87 /** default port for master web api */
88 public static final int DEFAULT_MASTER_INFOPORT = 60010;
89
90 /** Parameter name for the master type being backup (waits for primary to go inactive). */
91 public static final String MASTER_TYPE_BACKUP = "hbase.master.backup";
92
93 /** by default every master is a possible primary master unless the conf explicitly overrides it */
94 public static final boolean DEFAULT_MASTER_TYPE_BACKUP = false;
95
96 /** Name of ZooKeeper quorum configuration parameter. */
97 public static final String ZOOKEEPER_QUORUM = "hbase.zookeeper.quorum";
98
99 /** Name of ZooKeeper config file in conf/ directory. */
100 public static final String ZOOKEEPER_CONFIG_NAME = "zoo.cfg";
101
102 /** Parameter name for the client port that the zookeeper listens on */
103 public static final String ZOOKEEPER_CLIENT_PORT = "hbase.zookeeper.property.clientPort";
104
105 /** Default client port that the zookeeper listens on */
106 public static final int DEFAULT_ZOOKEPER_CLIENT_PORT = 2181;
107
108 /** Parameter name for the wait time for the recoverable zookeeper */
109 public static final String ZOOKEEPER_RECOVERABLE_WAITTIME = "hbase.zookeeper.recoverable.waittime";
110
111 /** Default wait time for the recoverable zookeeper */
112 public static final long DEFAULT_ZOOKEPER_RECOVERABLE_WAITIME = 10000;
113
114 /** Parameter name for the root dir in ZK for this cluster */
115 public static final String ZOOKEEPER_ZNODE_PARENT = "zookeeper.znode.parent";
116
117 public static final String DEFAULT_ZOOKEEPER_ZNODE_PARENT = "/hbase";
118
119 /** Parameter name for the limit on concurrent client-side zookeeper connections */
120 public static final String ZOOKEEPER_MAX_CLIENT_CNXNS = "hbase.zookeeper.property.maxClientCnxns";
121
122 /** Default limit on concurrent client-side zookeeper connections */
123 public static final int DEFAULT_ZOOKEPER_MAX_CLIENT_CNXNS = 30;
124
125 /** Parameter name for port region server listens on. */
126 public static final String REGIONSERVER_PORT = "hbase.regionserver.port";
127
128 /** Default port region server listens on. */
129 public static final int DEFAULT_REGIONSERVER_PORT = 60020;
130
131 /** default port for region server web api */
132 public static final int DEFAULT_REGIONSERVER_INFOPORT = 60030;
133
134 /** Parameter name for what region server interface to use. */
135 public static final String REGION_SERVER_CLASS = "hbase.regionserver.class";
136
137 /** Parameter name for what region server implementation to use. */
138 public static final String REGION_SERVER_IMPL= "hbase.regionserver.impl";
139
140 /** Default region server interface class name. */
141 public static final String DEFAULT_REGION_SERVER_CLASS = HRegionInterface.class.getName();
142
143 /** Parameter name for what master implementation to use. */
144 public static final String MASTER_IMPL= "hbase.master.impl";
145
146 /** Parameter name for how often threads should wake up */
147 public static final String THREAD_WAKE_FREQUENCY = "hbase.server.thread.wakefrequency";
148
149 /** Default value for thread wake frequency */
150 public static final int DEFAULT_THREAD_WAKE_FREQUENCY = 10 * 1000;
151
152 /** Parameter name for how often a region should should perform a major compaction */
153 public static final String MAJOR_COMPACTION_PERIOD = "hbase.hregion.majorcompaction";
154
155 /** Parameter name for HBase instance root directory */
156 public static final String HBASE_DIR = "hbase.rootdir";
157
158 /** Parameter name for HBase client IPC pool type */
159 public static final String HBASE_CLIENT_IPC_POOL_TYPE = "hbase.client.ipc.pool.type";
160
161 /** Parameter name for HBase client IPC pool size */
162 public static final String HBASE_CLIENT_IPC_POOL_SIZE = "hbase.client.ipc.pool.size";
163
164 /** Parameter name for HBase client operation timeout, which overrides RPC timeout */
165 public static final String HBASE_CLIENT_OPERATION_TIMEOUT = "hbase.client.operation.timeout";
166
167 /** Default HBase client operation timeout, which is tantamount to a blocking call */
168 public static final int DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT = Integer.MAX_VALUE;
169
170 /** Used to construct the name of the log directory for a region server
171 * Use '.' as a special character to seperate the log files from table data */
172 public static final String HREGION_LOGDIR_NAME = ".logs";
173
174 /** Used to construct the name of the splitlog directory for a region server */
175 public static final String SPLIT_LOGDIR_NAME = "splitlog";
176
177 public static final String CORRUPT_DIR_NAME = ".corrupt";
178
179 /** Like the previous, but for old logs that are about to be deleted */
180 public static final String HREGION_OLDLOGDIR_NAME = ".oldlogs";
181
182 /** Used to construct the name of the compaction directory during compaction */
183 public static final String HREGION_COMPACTIONDIR_NAME = "compaction.dir";
184
185 /** Default maximum file size */
186 public static final long DEFAULT_MAX_FILE_SIZE = 256 * 1024 * 1024;
187
188 /** Default size of a reservation block */
189 public static final int DEFAULT_SIZE_RESERVATION_BLOCK = 1024 * 1024 * 5;
190
191 /** Maximum value length, enforced on KeyValue construction */
192 public static final int MAXIMUM_VALUE_LENGTH = Integer.MAX_VALUE;
193
194 /** name of the file for unique cluster ID */
195 public static final String CLUSTER_ID_FILE_NAME = "hbase.id";
196
197 /** Configuration key storing the cluster ID */
198 public static final String CLUSTER_ID = "hbase.cluster.id";
199
200 // Always store the location of the root table's HRegion.
201 // This HRegion is never split.
202
203 // region name = table + startkey + regionid. This is the row key.
204 // each row in the root and meta tables describes exactly 1 region
205 // Do we ever need to know all the information that we are storing?
206
207 // Note that the name of the root table starts with "-" and the name of the
208 // meta table starts with "." Why? it's a trick. It turns out that when we
209 // store region names in memory, we use a SortedMap. Since "-" sorts before
210 // "." (and since no other table name can start with either of these
211 // characters, the root region will always be the first entry in such a Map,
212 // followed by all the meta regions (which will be ordered by their starting
213 // row key as well), followed by all user tables. So when the Master is
214 // choosing regions to assign, it will always choose the root region first,
215 // followed by the meta regions, followed by user regions. Since the root
216 // and meta regions always need to be on-line, this ensures that they will
217 // be the first to be reassigned if the server(s) they are being served by
218 // should go down.
219
220 /** The root table's name.*/
221 public static final byte [] ROOT_TABLE_NAME = Bytes.toBytes("-ROOT-");
222
223 /** The META table's name. */
224 public static final byte [] META_TABLE_NAME = Bytes.toBytes(".META.");
225
226 /** delimiter used between portions of a region name */
227 public static final int META_ROW_DELIMITER = ',';
228
229 /** The catalog family as a string*/
230 public static final String CATALOG_FAMILY_STR = "info";
231
232 /** The catalog family */
233 public static final byte [] CATALOG_FAMILY = Bytes.toBytes(CATALOG_FAMILY_STR);
234
235 /** The regioninfo column qualifier */
236 public static final byte [] REGIONINFO_QUALIFIER = Bytes.toBytes("regioninfo");
237
238 /** The server column qualifier */
239 public static final byte [] SERVER_QUALIFIER = Bytes.toBytes("server");
240
241 /** The startcode column qualifier */
242 public static final byte [] STARTCODE_QUALIFIER = Bytes.toBytes("serverstartcode");
243
244 /** The lower-half split region column qualifier */
245 public static final byte [] SPLITA_QUALIFIER = Bytes.toBytes("splitA");
246
247 /** The upper-half split region column qualifier */
248 public static final byte [] SPLITB_QUALIFIER = Bytes.toBytes("splitB");
249
250 /**
251 * The meta table version column qualifier.
252 * We keep current version of the meta table in this column in <code>-ROOT-</code>
253 * table: i.e. in the 'info:v' column.
254 */
255 public static final byte [] META_VERSION_QUALIFIER = Bytes.toBytes("v");
256
257 /**
258 * The current version of the meta table.
259 * Before this the meta had HTableDescriptor serialized into the HRegionInfo;
260 * i.e. pre-hbase 0.92. There was no META_VERSION column in the root table
261 * in this case. The presence of a version and its value being zero indicates
262 * meta is up-to-date.
263 */
264 public static final short META_VERSION = 0;
265
266 // Other constants
267
268 /**
269 * An empty instance.
270 */
271 public static final byte [] EMPTY_BYTE_ARRAY = new byte [0];
272
273 /**
274 * Used by scanners, etc when they want to start at the beginning of a region
275 */
276 public static final byte [] EMPTY_START_ROW = EMPTY_BYTE_ARRAY;
277
278 /**
279 * Last row in a table.
280 */
281 public static final byte [] EMPTY_END_ROW = EMPTY_START_ROW;
282
283 /**
284 * Used by scanners and others when they're trying to detect the end of a
285 * table
286 */
287 public static final byte [] LAST_ROW = EMPTY_BYTE_ARRAY;
288
289 /**
290 * Max length a row can have because of the limitation in TFile.
291 */
292 public static final int MAX_ROW_LENGTH = Short.MAX_VALUE;
293
294 /** When we encode strings, we always specify UTF8 encoding */
295 public static final String UTF8_ENCODING = "UTF-8";
296
297 /**
298 * Timestamp to use when we want to refer to the latest cell.
299 * This is the timestamp sent by clients when no timestamp is specified on
300 * commit.
301 */
302 public static final long LATEST_TIMESTAMP = Long.MAX_VALUE;
303
304 /**
305 * Timestamp to use when we want to refer to the oldest cell.
306 */
307 public static final long OLDEST_TIMESTAMP = Long.MIN_VALUE;
308
309 /**
310 * LATEST_TIMESTAMP in bytes form
311 */
312 public static final byte [] LATEST_TIMESTAMP_BYTES = Bytes.toBytes(LATEST_TIMESTAMP);
313
314 /**
315 * Define for 'return-all-versions'.
316 */
317 public static final int ALL_VERSIONS = Integer.MAX_VALUE;
318
319 /**
320 * Unlimited time-to-live.
321 */
322 // public static final int FOREVER = -1;
323 public static final int FOREVER = Integer.MAX_VALUE;
324
325 /**
326 * Seconds in a week
327 */
328 public static final int WEEK_IN_SECONDS = 7 * 24 * 3600;
329
330 //TODO: although the following are referenced widely to format strings for
331 // the shell. They really aren't a part of the public API. It would be
332 // nice if we could put them somewhere where they did not need to be
333 // public. They could have package visibility
334 public static final String NAME = "NAME";
335 public static final String VERSIONS = "VERSIONS";
336 public static final String IN_MEMORY = "IN_MEMORY";
337
338 /**
339 * This is a retry backoff multiplier table similar to the BSD TCP syn
340 * backoff table, a bit more aggressive than simple exponential backoff.
341 */
342 public static int RETRY_BACKOFF[] = { 1, 1, 1, 2, 2, 4, 4, 8, 16, 32 };
343
344 public static final String REGION_IMPL = "hbase.hregion.impl";
345
346 /** modifyTable op for replacing the table descriptor */
347 public static enum Modify {
348 CLOSE_REGION,
349 TABLE_COMPACT,
350 TABLE_FLUSH,
351 TABLE_MAJOR_COMPACT,
352 TABLE_SET_HTD,
353 TABLE_SPLIT
354 }
355
356 /**
357 * Scope tag for locally scoped data.
358 * This data will not be replicated.
359 */
360 public static final int REPLICATION_SCOPE_LOCAL = 0;
361
362 /**
363 * Scope tag for globally scoped data.
364 * This data will be replicated to all peers.
365 */
366 public static final int REPLICATION_SCOPE_GLOBAL = 1;
367
368 /**
369 * Default cluster ID, cannot be used to identify a cluster so a key with
370 * this value means it wasn't meant for replication.
371 */
372 public static final UUID DEFAULT_CLUSTER_ID = new UUID(0L,0L);
373
374 /**
375 * Parameter name for maximum number of bytes returned when calling a
376 * scanner's next method.
377 */
378 public static String HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY = "hbase.client.scanner.max.result.size";
379
380 /**
381 * Maximum number of bytes returned when calling a scanner's next method.
382 * Note that when a single row is larger than this limit the row is still
383 * returned completely.
384 *
385 * The default value is unlimited.
386 */
387 public static long DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE = Long.MAX_VALUE;
388
389 /**
390 * Parameter name for client pause value, used mostly as value to wait
391 * before running a retry of a failed get, region lookup, etc.
392 */
393 public static String HBASE_CLIENT_PAUSE = "hbase.client.pause";
394
395 /**
396 * Default value of {@link #HBASE_CLIENT_PAUSE}.
397 */
398 public static long DEFAULT_HBASE_CLIENT_PAUSE = 1000;
399
400 /**
401 * Parameter name for maximum retries, used as maximum for all retryable
402 * operations such as fetching of the root region from root region server,
403 * getting a cell's value, starting a row update, etc.
404 */
405 public static String HBASE_CLIENT_RETRIES_NUMBER = "hbase.client.retries.number";
406
407 /**
408 * Default value of {@link #HBASE_CLIENT_RETRIES_NUMBER}.
409 */
410 public static int DEFAULT_HBASE_CLIENT_RETRIES_NUMBER = 10;
411
412 /**
413 * Parameter name for maximum attempts, used to limit the number of times the
414 * client will try to obtain the proxy for a given region server.
415 */
416 public static String HBASE_CLIENT_RPC_MAXATTEMPTS = "hbase.client.rpc.maxattempts";
417
418 /**
419 * Default value of {@link #HBASE_CLIENT_RPC_MAXATTEMPTS}.
420 */
421 public static int DEFAULT_HBASE_CLIENT_RPC_MAXATTEMPTS = 1;
422
423 /**
424 * Parameter name for client prefetch limit, used as the maximum number of regions
425 * info that will be prefetched.
426 */
427 public static String HBASE_CLIENT_PREFETCH_LIMIT = "hbase.client.prefetch.limit";
428
429 /**
430 * Default value of {@link #HBASE_CLIENT_PREFETCH_LIMIT}.
431 */
432 public static int DEFAULT_HBASE_CLIENT_PREFETCH_LIMIT = 10;
433
434 /**
435 * Parameter name for number of rows that will be fetched when calling next on
436 * a scanner if it is not served from memory. Higher caching values will
437 * enable faster scanners but will eat up more memory and some calls of next
438 * may take longer and longer times when the cache is empty.
439 */
440 public static String HBASE_META_SCANNER_CACHING = "hbase.meta.scanner.caching";
441
442 /**
443 * Default value of {@link #HBASE_META_SCANNER_CACHING}.
444 */
445 public static int DEFAULT_HBASE_META_SCANNER_CACHING = 100;
446
447 /**
448 * Parameter name for unique identifier for this {@link org.apache.hadoop.conf.Configuration}
449 * instance. If there are two or more {@link org.apache.hadoop.conf.Configuration} instances that,
450 * for all intents and purposes, are the same except for their instance ids,
451 * then they will not be able to share the same {@link org.apache.hadoop.hbase.client.HConnection} instance.
452 * On the other hand, even if the instance ids are the same, it could result
453 * in non-shared {@link org.apache.hadoop.hbase.client.HConnection}
454 * instances if some of the other connection parameters differ.
455 */
456 public static String HBASE_CLIENT_INSTANCE_ID = "hbase.client.instance.id";
457
458 /**
459 * HRegion server lease period in milliseconds. Clients must report in within this period
460 * else they are considered dead. Unit measured in ms (milliseconds).
461 */
462 public static String HBASE_REGIONSERVER_LEASE_PERIOD_KEY =
463 "hbase.regionserver.lease.period";
464
465 /**
466 * Default value of {@link #HBASE_REGIONSERVER_LEASE_PERIOD_KEY}.
467 */
468 public static long DEFAULT_HBASE_REGIONSERVER_LEASE_PERIOD = 60000;
469
470 /**
471 * timeout for each RPC
472 */
473 public static String HBASE_RPC_TIMEOUT_KEY = "hbase.rpc.timeout";
474
475 /**
476 * Default value of {@link #HBASE_RPC_TIMEOUT_KEY}
477 */
478 public static int DEFAULT_HBASE_RPC_TIMEOUT = 60000;
479
480 public static final String
481 REPLICATION_ENABLE_KEY = "hbase.replication";
482
483 /** HBCK special code name used as server name when manipulating ZK nodes */
484 public static final String HBCK_CODE_NAME = "HBCKServerName";
485
486 public static final ServerName HBCK_CODE_SERVERNAME =
487 new ServerName(HBCK_CODE_NAME, -1, -1L);
488
489 public static final String KEY_FOR_HOSTNAME_SEEN_BY_MASTER =
490 "hbase.regionserver.hostname.seen.by.master";
491
492 public static final String HBASE_MASTER_LOGCLEANER_PLUGINS =
493 "hbase.master.logcleaner.plugins";
494
495 public static final String HBASE_REGION_SPLIT_POLICY_KEY =
496 "hbase.regionserver.region.split.policy";
497
498 /*
499 * Minimum percentage of free heap necessary for a successful cluster startup.
500 */
501 public static final float HBASE_CLUSTER_MINIMUM_MEMORY_THRESHOLD = 0.2f;
502
503 public static final List<String> HBASE_NON_USER_TABLE_DIRS = new ArrayList<String>(
504 Arrays.asList(new String[]{ HREGION_LOGDIR_NAME, HREGION_OLDLOGDIR_NAME,
505 CORRUPT_DIR_NAME, Bytes.toString(META_TABLE_NAME),
506 Bytes.toString(ROOT_TABLE_NAME), SPLIT_LOGDIR_NAME }));
507
508 public static final Pattern CP_HTD_ATTR_KEY_PATTERN = Pattern.compile
509 ("^coprocessor\\$([0-9]+)$", Pattern.CASE_INSENSITIVE);
510 public static final Pattern CP_HTD_ATTR_VALUE_PATTERN =
511 Pattern.compile("(^[^\\|]*)\\|([^\\|]+)\\|[\\s]*([\\d]*)[\\s]*(\\|.*)?$");
512
513 public static final String CP_HTD_ATTR_VALUE_PARAM_KEY_PATTERN = "[^=,]+";
514 public static final String CP_HTD_ATTR_VALUE_PARAM_VALUE_PATTERN = "[^,]+";
515 public static final Pattern CP_HTD_ATTR_VALUE_PARAM_PATTERN = Pattern.compile(
516 "(" + CP_HTD_ATTR_VALUE_PARAM_KEY_PATTERN + ")=(" +
517 CP_HTD_ATTR_VALUE_PARAM_VALUE_PATTERN + "),?");
518
519 private HConstants() {
520 // Can't be instantiated with this ctor.
521 }
522 }