提交 55f880bd 编写于 作者: G Gyula Fora 提交者: Stephan Ewen

[streaming] javadoc added to fault tolerance buffer

上级 d1fc3385
...@@ -26,10 +26,13 @@ import java.util.TreeMap; ...@@ -26,10 +26,13 @@ import java.util.TreeMap;
import eu.stratosphere.nephele.io.RecordWriter; import eu.stratosphere.nephele.io.RecordWriter;
/** An object to provide fault tolerance for Stratosphere stream processing.
* It works as a buffer to hold StreamRecords for a task for re-emitting failed, or timed out records.
*/
public class FaultTolerancyBuffer { public class FaultTolerancyBuffer {
private long TIMEOUT = 1000; private long TIMEOUT = 1000;
private Long timeOfLastUpdate; private Long timeOfLastUpdate;
private Map<String, StreamRecord> recordBuffer; private Map<String, StreamRecord> recordBuffer;
private Map<String, Integer> ackCounter; private Map<String, Integer> ackCounter;
...@@ -41,6 +44,13 @@ public class FaultTolerancyBuffer { ...@@ -41,6 +44,13 @@ public class FaultTolerancyBuffer {
private int numberOfOutputs; private int numberOfOutputs;
/**Creates fault tolerance buffer object for the given output channels and channel ID
*
* @param outputs
* List of outputs
* @param channelID
* ID of the task object that uses this buffer
*/
public FaultTolerancyBuffer(List<RecordWriter<StreamRecord>> outputs, public FaultTolerancyBuffer(List<RecordWriter<StreamRecord>> outputs,
String channelID) { String channelID) {
this.timeOfLastUpdate = System.currentTimeMillis(); this.timeOfLastUpdate = System.currentTimeMillis();
...@@ -53,6 +63,9 @@ public class FaultTolerancyBuffer { ...@@ -53,6 +63,9 @@ public class FaultTolerancyBuffer {
this.recordTimestamps = new HashMap<String, Long>(); this.recordTimestamps = new HashMap<String, Long>();
} }
/** Adds the record to the fault tolerance buffer. This record will be monitored for acknowledgements and timeout.
*
*/
public void addRecord(StreamRecord streamRecord) { public void addRecord(StreamRecord streamRecord) {
recordBuffer.put(streamRecord.getId(), streamRecord); recordBuffer.put(streamRecord.getId(), streamRecord);
...@@ -60,6 +73,13 @@ public class FaultTolerancyBuffer { ...@@ -60,6 +73,13 @@ public class FaultTolerancyBuffer {
addTimestamp(streamRecord.getId()); addTimestamp(streamRecord.getId());
} }
/** Checks for records that have timed out since the last check and fails them.
*
* @param currentTime
* Time when the check should be made, usually current system time.
* @return
* Returns the list of the records that have timed out.
*/
List<String> timeoutRecords(Long currentTime) { List<String> timeoutRecords(Long currentTime) {
if (timeOfLastUpdate + TIMEOUT < currentTime) { if (timeOfLastUpdate + TIMEOUT < currentTime) {
List<String> timedOutRecords = new LinkedList<String>(); List<String> timedOutRecords = new LinkedList<String>();
...@@ -85,6 +105,14 @@ public class FaultTolerancyBuffer { ...@@ -85,6 +105,14 @@ public class FaultTolerancyBuffer {
return null; return null;
} }
/**Stores time stamp for a record by recordID
* and also adds the record to a map which maps a time stamp to the IDs of records that were emitted at that time.
* <p>
* Later used for timeouts.
*
* @param recordID
* ID of the record
*/
public void addTimestamp(String recordID) { public void addTimestamp(String recordID) {
Long currentTime = System.currentTimeMillis(); Long currentTime = System.currentTimeMillis();
recordTimestamps.put(recordID, currentTime); recordTimestamps.put(recordID, currentTime);
...@@ -98,6 +126,11 @@ public class FaultTolerancyBuffer { ...@@ -98,6 +126,11 @@ public class FaultTolerancyBuffer {
} }
} }
/**Returns a StreamRecord after removing it from the buffer
*
* @param recordID
* The ID of the record that will be popped
*/
public StreamRecord popRecord(String recordID) { public StreamRecord popRecord(String recordID) {
System.out.println("Pop ID: " + recordID); System.out.println("Pop ID: " + recordID);
StreamRecord record = recordBuffer.get(recordID); StreamRecord record = recordBuffer.get(recordID);
...@@ -105,6 +138,11 @@ public class FaultTolerancyBuffer { ...@@ -105,6 +138,11 @@ public class FaultTolerancyBuffer {
return record; return record;
} }
/** Removes a StreamRecord by ID from the fault tolerance buffer, further acks will have no effects for this record.
* @param recordID
* The ID of the record that will be removed
*
*/
void removeRecord(String recordID) { void removeRecord(String recordID) {
recordBuffer.remove(recordID); recordBuffer.remove(recordID);
ackCounter.remove(recordID); ackCounter.remove(recordID);
...@@ -119,6 +157,11 @@ public class FaultTolerancyBuffer { ...@@ -119,6 +157,11 @@ public class FaultTolerancyBuffer {
} }
} }
/**Acknowledges the record of the given ID, if all the outputs have sent acknowledgments, removes it from the buffer
*
* @param recordID
* ID of the record that has been acknowledged
*/
//TODO: find a place to call timeoutRecords //TODO: find a place to call timeoutRecords
public void ackRecord(String recordID) { public void ackRecord(String recordID) {
if (ackCounter.containsKey(recordID)) { if (ackCounter.containsKey(recordID)) {
...@@ -133,6 +176,11 @@ public class FaultTolerancyBuffer { ...@@ -133,6 +176,11 @@ public class FaultTolerancyBuffer {
//timeoutRecords(System.currentTimeMillis()); //timeoutRecords(System.currentTimeMillis());
} }
/**Re-emits the failed record for the given ID, removes the old record and stores it with a new ID.
*
* @param recordID
* ID of the record that has been failed
*/
public void failRecord(String recordID) { public void failRecord(String recordID) {
// Create new id to avoid double counting acks // Create new id to avoid double counting acks
System.out.println("Fail ID: " + recordID); System.out.println("Fail ID: " + recordID);
...@@ -140,7 +188,12 @@ public class FaultTolerancyBuffer { ...@@ -140,7 +188,12 @@ public class FaultTolerancyBuffer {
addRecord(newRecord); addRecord(newRecord);
reEmit(newRecord); reEmit(newRecord);
} }
/**
* Emit give record to all output channels
* @param record
* Record to be re-emitted
*/
public void reEmit(StreamRecord record) { public void reEmit(StreamRecord record) {
for (RecordWriter<StreamRecord> output : outputs) { for (RecordWriter<StreamRecord> output : outputs) {
try { try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册