-
Notifications
You must be signed in to change notification settings - Fork 328
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
Demonstrate race condition to discuss how to fix #91 #94
Open
themodernlife
wants to merge
1
commit into
twitter:master
Choose a base branch
from
themodernlife:thread-safety
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
67 changes: 67 additions & 0 deletions
67
src/test/java/com/hadoop/compression/lzo/TestLzopCodec.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,67 @@ | ||
package com.hadoop.compression.lzo; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.io.LongWritable; | ||
import org.apache.hadoop.io.Text; | ||
import org.apache.hadoop.io.compress.CompressionCodecFactory; | ||
import org.apache.hadoop.mapred.*; | ||
|
||
/** | ||
* Copyright (C) 2014 MediaMath <http://www.mediamath.com> | ||
* | ||
* @author ihummel | ||
*/ | ||
public class TestLzopCodec extends TestCase { | ||
private String inputDataPath; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
inputDataPath = System.getProperty("test.build.data", "data"); | ||
} | ||
|
||
public void testRaceCondition() throws Exception { | ||
JobConf conf = new JobConf(); | ||
conf.set("io.compression.codecs", "com.hadoop.compression.lzo.LzopCodec"); | ||
FileInputFormat.addInputPath(conf, new Path(inputDataPath + "/100.txt.lzo")); | ||
|
||
//CompressionCodecFactory codecFactory = new CompressionCodecFactory(conf); | ||
|
||
TextInputFormat inputFormat = new TextInputFormat(); | ||
inputFormat.configure(conf); | ||
InputSplit[] splits = inputFormat.getSplits(conf, 1); | ||
|
||
for (InputSplit is: splits) { | ||
RecordReader<LongWritable, Text> rr = inputFormat.getRecordReader(is, conf, Reporter.NULL); | ||
LongWritable key = rr.createKey(); | ||
Text value = rr.createValue(); | ||
while (rr.next(key, value)) { | ||
System.out.println("Read: " + key + ", " + value); | ||
} | ||
// This call to rr.close() will put the SAME decompressor into the pool 2x! | ||
rr.close(); | ||
} | ||
|
||
// These guys are both going to get the same instance of the decompressor! Yikes! | ||
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. even after your fix? |
||
|
||
TextInputFormat inputFormat2 = new TextInputFormat(); | ||
inputFormat.configure(conf); | ||
|
||
TextInputFormat inputFormat3 = new TextInputFormat(); | ||
inputFormat.configure(conf); | ||
|
||
for (InputSplit is: splits) { | ||
RecordReader<LongWritable, Text> rr2 = inputFormat2.getRecordReader(is, conf, Reporter.NULL); | ||
RecordReader<LongWritable, Text> rr3 = inputFormat3.getRecordReader(is, conf, Reporter.NULL); | ||
|
||
LongWritable key2 = rr2.createKey(); | ||
Text value2 = rr2.createValue(); | ||
LongWritable key3 = rr3.createKey(); | ||
Text value3 = rr3.createValue(); | ||
while (rr2.next(key2, value2) && rr3.next(key3, value3)) { | ||
System.out.println("IS2: " + key2 + ", " + value2 + " IS3: " + key3 + ", " + value3); | ||
} | ||
} | ||
} | ||
} |
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.
not used?