-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-27649 WALPlayer does not properly dedupe overridden cell versions #5047
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dcb695
HBASE-27649 WALPlayer does not properly dedupe overridden cell versions
bbeaudreault c8b90a0
fix test
bbeaudreault bf8ca51
trigger build
bbeaudreault 45091db
Only use ExtendedCellSerialization for WALPlayer
bbeaudreault d93421c
fix
bbeaudreault b4bc918
initial pass at reusing splits
bbeaudreault 9f61026
use environment edge
bbeaudreault 456b66e
use assertThat
bbeaudreault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/ExtendedCellSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.mapreduce; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import org.apache.hadoop.hbase.ExtendedCell; | ||
import org.apache.hadoop.hbase.KeyValue; | ||
import org.apache.hadoop.hbase.KeyValueUtil; | ||
import org.apache.hadoop.hbase.PrivateCellUtil; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.hadoop.io.serializer.Deserializer; | ||
import org.apache.hadoop.io.serializer.Serialization; | ||
import org.apache.hadoop.io.serializer.Serializer; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
|
||
/** | ||
* Similar to CellSerialization, but includes the sequenceId from an ExtendedCell. This is necessary | ||
* so that CellSortReducer can sort by sequenceId, if applicable. Note that these two serializations | ||
* are not compatible -- data serialized by CellSerialization cannot be deserialized with | ||
* ExtendedCellSerialization and vice versa. This is ok for {@link HFileOutputFormat2} because the | ||
* serialization is not actually used for the actual written HFiles, just intermediate data (between | ||
* mapper and reducer of a single job). | ||
*/ | ||
@InterfaceAudience.Private | ||
public class ExtendedCellSerialization implements Serialization<ExtendedCell> { | ||
@Override | ||
public boolean accept(Class<?> c) { | ||
return ExtendedCell.class.isAssignableFrom(c); | ||
} | ||
|
||
@Override | ||
public ExtendedCellDeserializer getDeserializer(Class<ExtendedCell> t) { | ||
return new ExtendedCellDeserializer(); | ||
} | ||
|
||
@Override | ||
public ExtendedCellSerializer getSerializer(Class<ExtendedCell> c) { | ||
return new ExtendedCellSerializer(); | ||
} | ||
|
||
public static class ExtendedCellDeserializer implements Deserializer<ExtendedCell> { | ||
private DataInputStream dis; | ||
|
||
@Override | ||
public void close() throws IOException { | ||
this.dis.close(); | ||
} | ||
|
||
@Override | ||
public KeyValue deserialize(ExtendedCell ignore) throws IOException { | ||
KeyValue kv = KeyValueUtil.create(this.dis); | ||
PrivateCellUtil.setSequenceId(kv, this.dis.readLong()); | ||
return kv; | ||
} | ||
|
||
@Override | ||
public void open(InputStream is) throws IOException { | ||
this.dis = new DataInputStream(is); | ||
} | ||
} | ||
|
||
public static class ExtendedCellSerializer implements Serializer<ExtendedCell> { | ||
private DataOutputStream dos; | ||
|
||
@Override | ||
public void close() throws IOException { | ||
this.dos.close(); | ||
} | ||
|
||
@Override | ||
public void open(OutputStream os) throws IOException { | ||
this.dos = new DataOutputStream(os); | ||
} | ||
|
||
@Override | ||
public void serialize(ExtendedCell kv) throws IOException { | ||
dos.writeInt(PrivateCellUtil.estimatedSerializedSizeOf(kv) - Bytes.SIZEOF_INT); | ||
PrivateCellUtil.writeCell(kv, dos, true); | ||
dos.writeLong(kv.getSequenceId()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.io.File; | ||
import java.io.PrintStream; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
|
@@ -50,6 +51,7 @@ | |
import org.apache.hadoop.hbase.regionserver.TestRecoveredEdits; | ||
import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
import org.apache.hadoop.hbase.testclassification.MapReduceTests; | ||
import org.apache.hadoop.hbase.tool.BulkLoadHFiles; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
import org.apache.hadoop.hbase.util.LauncherSecurityManager; | ||
|
@@ -131,6 +133,84 @@ public void testPlayingRecoveredEdit() throws Exception { | |
assertTrue(TEST_UTIL.countRows(tn) > 0); | ||
} | ||
|
||
/** | ||
* Tests that when you write multiple cells with the same timestamp they are properly sorted by | ||
* their sequenceId in WALPlayer/CellSortReducer so that the correct one wins when querying from | ||
* the resulting bulkloaded HFiles. See HBASE-27649 | ||
*/ | ||
@Test | ||
public void testWALPlayerBulkLoadWithOverriddenTimestamps() throws Exception { | ||
final TableName tableName = TableName.valueOf(name.getMethodName() + "1"); | ||
final byte[] family = Bytes.toBytes("family"); | ||
final byte[] column1 = Bytes.toBytes("c1"); | ||
final byte[] column2 = Bytes.toBytes("c2"); | ||
final byte[] row = Bytes.toBytes("row"); | ||
Table table = TEST_UTIL.createTable(tableName, family); | ||
|
||
long now = System.currentTimeMillis(); | ||
// put a row into the first table | ||
Put p = new Put(row); | ||
p.addColumn(family, column1, now, column1); | ||
p.addColumn(family, column2, now, column2); | ||
|
||
table.put(p); | ||
|
||
byte[] lastVal = null; | ||
|
||
for (int i = 0; i < 50; i++) { | ||
lastVal = Bytes.toBytes(ThreadLocalRandom.current().nextLong()); | ||
p = new Put(row); | ||
p.addColumn(family, column1, now, lastVal); | ||
|
||
table.put(p); | ||
|
||
// wal rolling is necessary to trigger the bug. otherwise no sorting | ||
// needs to occur in the reducer because it's all sorted and coming from a single file. | ||
if (i % 10 == 0) { | ||
WAL log = cluster.getRegionServer(0).getWAL(null); | ||
log.rollWriter(); | ||
} | ||
} | ||
|
||
WAL log = cluster.getRegionServer(0).getWAL(null); | ||
log.rollWriter(); | ||
String walInputDir = new Path(cluster.getMaster().getMasterFileSystem().getWALRootDir(), | ||
HConstants.HREGION_LOGDIR_NAME).toString(); | ||
|
||
Configuration configuration = new Configuration(TEST_UTIL.getConfiguration()); | ||
String outPath = "/tmp/" + name.getMethodName(); | ||
configuration.set(WALPlayer.BULK_OUTPUT_CONF_KEY, outPath); | ||
configuration.setBoolean(WALPlayer.MULTI_TABLES_SUPPORT, true); | ||
|
||
WALPlayer player = new WALPlayer(configuration); | ||
assertEquals(0, ToolRunner.run(configuration, player, | ||
new String[] { walInputDir, tableName.getNameAsString() })); | ||
|
||
Get g = new Get(row); | ||
Result result = table.get(g); | ||
byte[] value = CellUtil.cloneValue(result.getColumnLatestCell(family, column1)); | ||
assertTrue( | ||
"Expected " + Bytes.toStringBinary(column1) + " latest value to be equal to lastVal=" | ||
+ Bytes.toStringBinary(lastVal) + " but was " + Bytes.toStringBinary(value), | ||
Bytes.equals(lastVal, value)); | ||
|
||
table = TEST_UTIL.truncateTable(tableName); | ||
g = new Get(row); | ||
result = table.get(g); | ||
assertTrue("expected row to be empty after truncate but got " + result, result.isEmpty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use assertThat and Matchers.empty? |
||
|
||
BulkLoadHFiles.create(configuration).bulkLoad(tableName, | ||
new Path(outPath, tableName.getNamespaceAsString() + "/" + tableName.getNameAsString())); | ||
|
||
g = new Get(row); | ||
result = table.get(g); | ||
value = CellUtil.cloneValue(result.getColumnLatestCell(family, column1)); | ||
assertTrue( | ||
"Expected " + Bytes.toStringBinary(column1) + " latest value to be equal to lastVal=" | ||
+ Bytes.toStringBinary(lastVal) + " but was " + Bytes.toStringBinary(value), | ||
Bytes.equals(lastVal, value)); | ||
} | ||
|
||
/** | ||
* Simple end-to-end test | ||
*/ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use EnvironmentEdgeManager.currentTime if possible