Skip to content

Commit b952883

Browse files
committed
HBASE-25824 IntegrationTestLoadCommonCrawl
This integration test loads successful resource retrieval records from the Common Crawl (https://commoncrawl.org/) public dataset into an HBase table and writes records that can be used to later verify the presence and integrity of those records. Run like: ./bin/hbase org.apache.hadoop.hbase.test.IntegrationTestLoadCommonCrawl \ -Dfs.s3n.awsAccessKeyId=<AWS access key> \ -Dfs.s3n.awsSecretAccessKey=<AWS secret key> \ /path/to/test-CC-MAIN-2021-10-warc.paths.gz \ /path/to/tmp/warc-loader-output Access to the Common Crawl dataset in S3 is made available to anyone by Amazon AWS, but Hadoop's S3N filesystem still requires valid access credentials to initialize. The input path can either specify a directory or a file. The file may optionally be compressed with gzip. If a directory, the loader expects the directory to contain one or more WARC files from the Common Crawl dataset. If a file, the loader expects a list of Hadoop S3N URIs which point to S3 locations for one or more WARC files from the Common Crawl dataset, one URI per line. Lines should be terminated with the UNIX line terminator. Included in hbase-it/src/test/resources/CC-MAIN-2021-10-warc.paths.gz is a list of all WARC files comprising the Q1 2021 crawl archive. There are 64,000 WARC files in this data set, each containing ~1GB of gzipped data. The WARC files contain several record types, such as metadata, request, and response, but we only load the response record types. If the HBase table schema does not specify compression (by default) there is roughly a 10x expansion. Loading the full crawl archive results in a table approximately 640 TB in size. The hadoop-aws jar will be needed at runtime to instantiate the S3N filesystem. Use the -files ToolRunner argument to add it. You can also split the Loader and Verify stages: Load with: ./bin/hbase 'org.apache.hadoop.hbase.test.IntegrationTestLoadCommonCrawl$Loader' \ -files /path/to/hadoop-aws.jar \ -Dfs.s3n.awsAccessKeyId=<AWS access key> \ -Dfs.s3n.awsSecretAccessKey=<AWS secret key> \ /path/to/test-CC-MAIN-2021-10-warc.paths.gz \ /path/to/tmp/warc-loader-output Verify with: ./bin/hbase 'org.apache.hadoop.hbase.test.IntegrationTestLoadCommonCrawl$Verify' \ /path/to/tmp/warc-loader-output
1 parent 2382f68 commit b952883

File tree

10 files changed

+1934
-0
lines changed

10 files changed

+1934
-0
lines changed

hbase-it/src/test/java/org/apache/hadoop/hbase/test/IntegrationTestLoadCommonCrawl.java

Lines changed: 746 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.hbase.test.util;
20+
21+
// Cribbed from hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/CRC64.java
22+
23+
public class CRC64 {
24+
private static final long POLY = 0x9a6c9329ac4bc9b5L;
25+
private static final int TABLE_LENGTH = 256;
26+
private static final long[] TABLE = new long[TABLE_LENGTH];
27+
static {
28+
/* Initialize a table constructed from POLY */
29+
for (int n = 0; n < TABLE_LENGTH; ++n) {
30+
long crc = n;
31+
for (int i = 0; i < 8; ++i) {
32+
if ((crc & 1) == 1) {
33+
crc = (crc >>> 1) ^ POLY;
34+
} else {
35+
crc >>>= 1;
36+
}
37+
}
38+
TABLE[n] = crc;
39+
}
40+
}
41+
42+
private long value = -1;
43+
44+
public void reset() {
45+
value = -1;
46+
}
47+
48+
public void update(byte[] input, int off, int len) {
49+
for (int i = off; i < off+len; i++) {
50+
value = TABLE[(input[i] ^ (int) value) & 0xFF] ^ (value >>> 8);
51+
}
52+
}
53+
54+
public void update(byte[] input) {
55+
update(input, 0, input.length);
56+
}
57+
58+
public long getValue() {
59+
// Return the compliment of 'value' to complete the calculation
60+
return ~value;
61+
}
62+
63+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
/*
19+
* The MIT License (MIT)
20+
* Copyright (c) 2014 Martin Kleppmann
21+
*
22+
* Permission is hereby granted, free of charge, to any person obtaining a copy
23+
* of this software and associated documentation files (the "Software"), to deal
24+
* in the Software without restriction, including without limitation the rights
25+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
* copies of the Software, and to permit persons to whom the Software is
27+
* furnished to do so, subject to the following conditions:
28+
*
29+
* The above copyright notice and this permission notice shall be included in
30+
* all copies or substantial portions of the Software.
31+
*
32+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38+
* THE SOFTWARE.
39+
*/
40+
41+
package org.apache.hadoop.hbase.test.util.warc;
42+
43+
import java.io.BufferedInputStream;
44+
import java.io.DataInputStream;
45+
import java.io.FilterInputStream;
46+
import java.io.IOException;
47+
import java.io.InputStream;
48+
import org.apache.hadoop.conf.Configuration;
49+
import org.apache.hadoop.fs.FileSystem;
50+
import org.apache.hadoop.fs.Path;
51+
import org.apache.hadoop.io.compress.CompressionCodec;
52+
import org.slf4j.Logger;
53+
import org.slf4j.LoggerFactory;
54+
55+
/**
56+
* Reads {@link WARCRecord}s from a WARC file, using Hadoop's filesystem APIs. (This means you
57+
* can read from HDFS, S3 or any other filesystem supported by Hadoop). This implementation is
58+
* not tied to the MapReduce APIs -- that link is provided by the mapred
59+
* {@link com.martinkl.warc.mapred.WARCInputFormat} and the mapreduce
60+
* {@link com.martinkl.warc.mapreduce.WARCInputFormat}.
61+
*/
62+
public class WARCFileReader {
63+
private static final Logger logger = LoggerFactory.getLogger(WARCFileReader.class);
64+
65+
private final long fileSize;
66+
private CountingInputStream byteStream = null;
67+
private DataInputStream dataStream = null;
68+
private long bytesRead = 0, recordsRead = 0;
69+
70+
/**
71+
* Opens a file for reading. If the filename ends in `.gz`, it is automatically decompressed
72+
* on the fly.
73+
* @param conf The Hadoop configuration.
74+
* @param filePath The Hadoop path to the file that should be read.
75+
* @throws IOException
76+
*/
77+
public WARCFileReader(Configuration conf, Path filePath) throws IOException {
78+
FileSystem fs = filePath.getFileSystem(conf);
79+
this.fileSize = fs.getFileStatus(filePath).getLen();
80+
logger.info("Reading from " + filePath);
81+
82+
CompressionCodec codec = filePath.getName().endsWith(".gz") ?
83+
WARCFileWriter.getGzipCodec(conf) : null;
84+
byteStream = new CountingInputStream(new BufferedInputStream(fs.open(filePath)));
85+
dataStream = new DataInputStream(codec == null ? byteStream : codec.createInputStream(byteStream));
86+
}
87+
88+
/**
89+
* Reads the next record from the file.
90+
* @return The record that was read.
91+
* @throws IOException
92+
*/
93+
public WARCRecord read() throws IOException {
94+
WARCRecord record = new WARCRecord(dataStream);
95+
recordsRead++;
96+
return record;
97+
}
98+
99+
/**
100+
* Closes the file. No more reading is possible after the file has been closed.
101+
* @throws IOException
102+
*/
103+
public void close() throws IOException {
104+
if (dataStream != null) dataStream.close();
105+
byteStream = null;
106+
dataStream = null;
107+
}
108+
109+
/**
110+
* Returns the number of records that have been read since the file was opened.
111+
*/
112+
public long getRecordsRead() {
113+
return recordsRead;
114+
}
115+
116+
/**
117+
* Returns the number of bytes that have been read from file since it was opened.
118+
* If the file is compressed, this refers to the compressed file size.
119+
*/
120+
public long getBytesRead() {
121+
return bytesRead;
122+
}
123+
124+
/**
125+
* Returns the proportion of the file that has been read, as a number between 0.0
126+
* and 1.0.
127+
*/
128+
public float getProgress() {
129+
if (fileSize == 0) return 1.0f;
130+
return (float) bytesRead / (float) fileSize;
131+
}
132+
133+
private class CountingInputStream extends FilterInputStream {
134+
public CountingInputStream(InputStream in) {
135+
super(in);
136+
}
137+
138+
@Override
139+
public int read() throws IOException {
140+
int result = in.read();
141+
if (result != -1) bytesRead++;
142+
return result;
143+
}
144+
145+
@Override
146+
public int read(byte[] b, int off, int len) throws IOException {
147+
int result = in.read(b, off, len);
148+
if (result != -1) bytesRead += result;
149+
return result;
150+
}
151+
152+
@Override
153+
public long skip(long n) throws IOException {
154+
long result = in.skip(n);
155+
bytesRead += result;
156+
return result;
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)