Skip to content

Commit 7799786

Browse files
author
Wang, Gang(Gary)
committed
MNEMONIC-229: Remove the call to initNextPool from user
MNEMONIC-231: Remove the explicit call to readConfig().
1 parent 341156c commit 7799786

File tree

11 files changed

+57
-38
lines changed

11 files changed

+57
-38
lines changed

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/main/java/org/apache/mnemonic/hadoop/MneDurableInputSession.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,28 @@ public class MneDurableInputSession<V>
4444
private Configuration configuration;
4545
private Iterator<String> m_fp_iter;
4646

47-
public MneDurableInputSession(TaskAttemptContext taskAttemptContext, Path path) {
48-
this(taskAttemptContext.getConfiguration(), path);
49-
setTaskAttemptContext(taskAttemptContext);
47+
public MneDurableInputSession(TaskAttemptContext taskAttemptContext,
48+
Configuration configuration, Path path, String prefix) {
49+
if (null == taskAttemptContext && null == configuration) {
50+
throw new ConfigurationException("Session is not configured properly");
51+
}
52+
if (null != taskAttemptContext) {
53+
setTaskAttemptContext(taskAttemptContext);
54+
setConfiguration(taskAttemptContext.getConfiguration());
55+
} else {
56+
setConfiguration(configuration);
57+
}
58+
initialize(path, prefix);
5059
}
5160

52-
public MneDurableInputSession(Configuration configuration, Path path) {
53-
setConfiguration(configuration);
61+
public void initialize(Path path, String prefix) {
5462
if (!Files.isRegularFile(Paths.get(path.toString()), LinkOption.NOFOLLOW_LINKS)) {
5563
throw new UnsupportedOperationException();
5664
}
5765
List<String> fpathlist = new ArrayList<String>();
5866
fpathlist.add(path.toString());
5967
m_fp_iter = fpathlist.iterator();
68+
readConfig(prefix);
6069
}
6170

6271
public void validateConfig() {

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/main/java/org/apache/mnemonic/hadoop/MneDurableOutputSession.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,24 @@ public class MneDurableOutputSession<V>
4242
private TaskAttemptContext taskAttemptContext;
4343
private Configuration configuration;
4444

45-
public MneDurableOutputSession(TaskAttemptContext taskAttemptContext) {
46-
this(taskAttemptContext.getConfiguration());
47-
setTaskAttemptContext(taskAttemptContext);
45+
public MneDurableOutputSession(TaskAttemptContext taskAttemptContext,
46+
Configuration configuration, String prefix) {
47+
if (null == taskAttemptContext && null == configuration) {
48+
throw new ConfigurationException("Session is not configured properly");
49+
}
50+
if (null != taskAttemptContext) {
51+
setTaskAttemptContext(taskAttemptContext);
52+
setConfiguration(taskAttemptContext.getConfiguration());
53+
} else {
54+
setConfiguration(configuration);
55+
}
56+
initialize(prefix);
4857
}
49-
50-
public MneDurableOutputSession(Configuration configuration) {
51-
setConfiguration(configuration);
58+
59+
public void initialize(String prefix) {
5260
m_recordmap = new HashMap<V, DurableSinglyLinkedList<V>>();
61+
readConfig(prefix);
62+
initNextPool();
5363
}
5464

5565
public void validateConfig() {
@@ -122,7 +132,7 @@ protected String getUniqueName(String name, String extension) {
122132
}
123133

124134
@Override
125-
public boolean initNextPool() {
135+
protected boolean initNextPool() {
126136
boolean ret = false;
127137
if (m_act != null) {
128138
m_act.close();

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/main/java/org/apache/mnemonic/hadoop/mapred/MneMapredRecordReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class MneMapredRecordReader<MV extends MneDurableInputValue<V>, V>
4545

4646
public MneMapredRecordReader(FileSplit fileSplit, JobConf conf) throws IOException {
4747
m_fileSplit = fileSplit;
48-
m_session = new MneDurableInputSession<V>(conf, m_fileSplit.getPath());
49-
m_session.readConfig(MneConfigHelper.DEFAULT_INPUT_CONFIG_PREFIX);
48+
m_session = new MneDurableInputSession<V>(null, conf,
49+
m_fileSplit.getPath(), MneConfigHelper.DEFAULT_INPUT_CONFIG_PREFIX);
5050
m_iter = m_session.iterator();
5151
}
5252

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/main/java/org/apache/mnemonic/hadoop/mapreduce/MneMapreduceRecordReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void close() throws IOException {
5050
@Override
5151
public void initialize(InputSplit inputSplit, TaskAttemptContext context) {
5252
FileSplit split = (FileSplit) inputSplit;
53-
m_session = new MneDurableInputSession<V>(context, split.getPath());
54-
m_session.readConfig(MneConfigHelper.DEFAULT_INPUT_CONFIG_PREFIX);
53+
m_session = new MneDurableInputSession<V>(context, null,
54+
split.getPath(), MneConfigHelper.DEFAULT_INPUT_CONFIG_PREFIX);
5555
m_iter = m_session.iterator();
5656
}
5757

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/test/java/org/apache/mnemonic/mapred/MneMapredBufferDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ protected DurableBuffer<?> genupdDurableBuffer(
132132
@Test(enabled = true)
133133
public void testWriteBufferData() throws Exception {
134134
NullWritable nada = NullWritable.get();
135-
MneDurableOutputSession<DurableBuffer<?>> sess = new MneDurableOutputSession<DurableBuffer<?>>(m_conf);
136-
sess.readConfig(MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
137-
sess.initNextPool();
135+
MneDurableOutputSession<DurableBuffer<?>> sess =
136+
new MneDurableOutputSession<DurableBuffer<?>>(null, m_conf,
137+
MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
138138
MneDurableOutputValue<DurableBuffer<?>> mdvalue =
139139
new MneDurableOutputValue<DurableBuffer<?>>(sess);
140140
OutputFormat<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> outputFormat =

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/test/java/org/apache/mnemonic/mapreduce/MneMapreduceBufferDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ protected DurableBuffer<?> genupdDurableBuffer(
135135
@Test(enabled = true)
136136
public void testWriteBufferData() throws Exception {
137137
NullWritable nada = NullWritable.get();
138-
MneDurableOutputSession<DurableBuffer<?>> sess = new MneDurableOutputSession<DurableBuffer<?>>(m_tacontext);
139-
sess.readConfig(MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
140-
sess.initNextPool();
138+
MneDurableOutputSession<DurableBuffer<?>> sess =
139+
new MneDurableOutputSession<DurableBuffer<?>>(m_tacontext, null,
140+
MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
141141
MneDurableOutputValue<DurableBuffer<?>> mdvalue =
142142
new MneDurableOutputValue<DurableBuffer<?>>(sess);
143143
OutputFormat<NullWritable, MneDurableOutputValue<DurableBuffer<?>>> outputFormat =

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/test/java/org/apache/mnemonic/mapreduce/MneMapreduceChunkDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ protected DurableChunk<?> genupdDurableChunk(
140140
@Test(enabled = true)
141141
public void testWriteChunkData() throws Exception {
142142
NullWritable nada = NullWritable.get();
143-
MneDurableOutputSession<DurableChunk<?>> sess = new MneDurableOutputSession<DurableChunk<?>>(m_tacontext);
144-
sess.readConfig(MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
145-
sess.initNextPool();
143+
MneDurableOutputSession<DurableChunk<?>> sess =
144+
new MneDurableOutputSession<DurableChunk<?>>(m_tacontext, null,
145+
MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
146146
MneDurableOutputValue<DurableChunk<?>> mdvalue =
147147
new MneDurableOutputValue<DurableChunk<?>>(sess);
148148
OutputFormat<NullWritable, MneDurableOutputValue<DurableChunk<?>>> outputFormat =

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/test/java/org/apache/mnemonic/mapreduce/MneMapreduceLongDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public void tearDown() {
108108
@Test(enabled = true)
109109
public void testWriteLongData() throws Exception {
110110
NullWritable nada = NullWritable.get();
111-
MneDurableOutputSession<Long> sess = new MneDurableOutputSession<Long>(m_tacontext);
112-
sess.readConfig(MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
113-
sess.initNextPool();
111+
MneDurableOutputSession<Long> sess =
112+
new MneDurableOutputSession<Long>(m_tacontext, null,
113+
MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
114114
MneDurableOutputValue<Long> mdvalue =
115115
new MneDurableOutputValue<Long>(sess);
116116
OutputFormat<NullWritable, MneDurableOutputValue<Long>> outputFormat =

mnemonic-hadoop/mnemonic-hadoop-mapreduce/src/test/java/org/apache/mnemonic/mapreduce/MneMapreducePersonDataTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public void tearDown() {
108108
@Test(enabled = true)
109109
public void testWritePersonData() throws Exception {
110110
NullWritable nada = NullWritable.get();
111-
MneDurableOutputSession<Person<Long>> sess = new MneDurableOutputSession<Person<Long>>(m_tacontext);
112-
sess.readConfig(MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
113-
sess.initNextPool();
111+
MneDurableOutputSession<Person<Long>> sess =
112+
new MneDurableOutputSession<Person<Long>>(m_tacontext, null,
113+
MneConfigHelper.DEFAULT_OUTPUT_CONFIG_PREFIX);
114114
MneDurableOutputValue<Person<Long>> mdvalue =
115115
new MneDurableOutputValue<Person<Long>>(sess);
116116
OutputFormat<NullWritable, MneDurableOutputValue<Person<Long>>> outputFormat =

mnemonic-sessions/src/main/java/org/apache/mnemonic/sessions/DurableOutputSession.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public abstract class DurableOutputSession<V, A extends RestorableAllocator<A>>
4646
protected DurableSinglyLinkedList<V> m_listnode;
4747
protected A m_act;
4848

49+
/**
50+
* Initialize the next pool, must be called before use
51+
*
52+
* @return true if success
53+
*/
54+
protected abstract boolean initNextPool();
55+
4956
@Override
5057
public A getAllocator() {
5158
return m_act;

0 commit comments

Comments
 (0)