forked from ionutig/HBaseWD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
135 lines (101 loc) · 4.62 KB
/
README
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
HBaseWD:
---------
http://github.com/sematext/HBaseWD
Released under Apache License 2.0.
Description:
------------
HBaseWD stands for Distributing (sequential) Writes. It was inspired by
discussions on HBase mailing lists around the problem of choosing between:
* writing records with sequential row keys (e.g. time-series data with row key
built based on ts)
* using random unique IDs for records
First approach makes possible to perform fast range scans with help of setting
start/stop keys on Scanner, but creates single region server hot-spotting
problem upon writing data (as row keys go in sequence all records end up
written into a single region at a time).
Second approach aims for fastest writing performance by distributing new
records over random regions but makes not possible doing fast range scans
against written data.
The suggested approach stays in the middle of the two above and proved to
perform well by distributing records over the cluster during writing data
while allowing range scans over it. HBaseWD provides very simple API to
work with which makes it perfect to use with existing code.
Please refer to unit-tests for lib usage info as they aimed to act as example.
For a clear introductory post read:
http://blog.sematext.com/2012/04/09/hbasewd-avoid-regionserver-hotspotting-despite-writing-records-with-sequential-keys/
Brief Usage Info (Examples):
----------------------------
Distributing records with sequential keys which are being written in up to
Byte.MAX_VALUE buckets:
byte bucketsCount = (byte) 32; // distributing into 32 buckets
RowKeyDistributor keyDistributor =
new RowKeyDistributorByOneBytePrefix(bucketsCount);
for (int i = 0; i < 100; i++) {
Put put = new Put(keyDistributor.getDistributedKey(originalKey));
... // add values
hTable.put(put);
}
Performing a range scan over written data (internally <bucketsCount> scanners
executed):
Scan scan = new Scan(startKey, stopKey);
ResultScanner rs = DistributedScanner.create(hTable, scan, keyDistributor);
for (Result current : rs) {
...
}
Performing mapreduce job over written data chunk specified by Scan:
Configuration conf = HBaseConfiguration.create();
Job job = new Job(conf, "testMapreduceJob");
Scan scan = new Scan(startKey, stopKey);
TableMapReduceUtil.initTableMapperJob("table", scan,
RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);
// Substituting standard TableInputFormat which was set in
// TableMapReduceUtil.initTableMapperJob(...)
job.setInputFormatClass(WdTableInputFormat.class);
keyDistributor.addInfo(job.getConfiguration());
Another useful RowKeyDistributor is RowKeyDistributorByHashPrefix. Please see
example below. It will creates "distributed key" based on original key value
so that later when you have original key and want to update the record you can
calculate distributed key without roundtrip to HBase.
AbstractRowKeyDistributor keyDistributor =
new RowKeyDistributorByHashPrefix(
new RowKeyDistributorByHashPrefix.OneByteSimpleHash(15));
You can use your own hashing logic here by implementing simple interface:
public static interface Hasher extends Parametrizable {
byte[] getHashPrefix(byte[] originalKey);
byte[][] getAllPossiblePrefixes();
}
Extending Row Keys Distributing Patterns:
-----------------------------------------
HBaseWD is designed to be flexible and to support custom row key distribution
approaches. To define custom row key distributing logic just implement
AbstractRowKeyDistributor abstract class which is really very simple:
public abstract class AbstractRowKeyDistributor implements Parametrizable {
public abstract byte[] getDistributedKey(byte[] originalKey);
public abstract byte[] getOriginalKey(byte[] adjustedKey);
public abstract byte[][] getAllDistributedKeys(byte[] originalKey);
... // some utility methods
}
Mailing List:
-------------
To participate more in the discussion, join the group at
https://groups.google.com/group/hbasewd/
Build Notes:
------------
Tests take some time to execute (can be up to several minutes), to skip
their execution use -Dmaven.skip.tests=true.
The latest stable version can be linked from you maven project with:
<repositories>
<repository>
<id>sonatype release</id>
<url>https://oss.sonatype.org/content/repositories/releases/</url>
</repository>
</repositories>
[...]
<dependency>
<groupId>com.sematext.hbasewd</groupId>
<artifactId>hbasewd</artifactId>
<version>0.1.0</version>
</dependency>
Author:
-------
Alex Baranau