Backtracking in Ptolemy Models

Download Report

Transcript Backtracking in Ptolemy Models

Backtracking for
Distributed Model Execution
Actions and Settings
• Motivation
– Distributed model execution requires backtracking. When a component receives a message tagged with a
time in its past, it must rollback and process the message in the correct sequential order.
Batch Refactoring
– Incremental backtracking aims to capture every change in model states. Every time an actor assigns a new
value to its private non-static field (state), the old value must be remembered so that a rollback can be
issued later.
Ptolemy Editor
• Automatic Java Source Refactoring
– It is boring for the programmers to manually capture all the changes, so we take a refactoring approach.
– An Eclipse plug-in refactors actor source code as it is being written. A command-line tool is implemented to
refactor a list of sources at a time.
Refactoring Preview
• Backtracking with Checkpoint Objects
– A checkpoint object monitors a group of objects to be checkpointed and rolled back at the same time.
– A timestamp is the handle of a checkpoint.
– The rollback method of a checkpoint object rolls the state back to a previous timestamp.
• Modified SDF Director
package mypackage;
package refactored.mypackage;
import java.io.InputStream;
import
import
import
import
import
import
/**
* A buffer of predefined size for an input stream.
*/
public class StreamBuffer {
– In its original design, SDF does not conform to the prefire-fire-postfire semantics.
/**
* Construct a buffer with an input stream.
*/
public StreamBuffer(InputStream stream) {
_stream = stream;
}
– The modified SDF director conforms to the prefire-fire-postfire semantics by recording a checkpoint
before the first fire.
/**
* A buffer of predefined size for an input stream.
*/
public class StreamBuffer implements Rollbackable {
protected Checkpoint $CHECKPOINT = new Checkpoint(this);
/**
* Return the next byte in the buffer. If the buffer
* is empty, more bytes are read from the input stream.
*/
public byte nextByte() throws Exception {
if (_pointer >= SIZE) {
_stream.read(_buffer);
_pointer = 0;
}
return _buffer[_pointer++];
}
– SDF composite actors can now be embedded in CT and provide the correct semantics in a clean way.
prefire
/**
* Size of the buffer.
*/
public static final int SIZE = 20;
// The buffer.
private byte[] _buffer = new byte[SIZE];
// The current read position in the buffer.
private int _pointer = SIZE;
// The input stream to be read.
private InputStream _stream;
/**
* Size of the buffer.
*/
public static final int SIZE = 20;
create checkpoint
Backtracking
/**
* Construct a buffer with an input stream.
*/
public StreamBuffer(InputStream stream) {
$ASSIGN$_stream(stream);
}
// The buffer.
private byte[] _buffer = new byte[SIZE];
fire
// The current read position in the buffer.
private int _pointer = SIZE;
rollback
java.io.InputStream;
java.lang.Object;
ptolemy.backtrack.Checkpoint;
ptolemy.backtrack.Rollbackable;
ptolemy.backtrack.util.CheckpointRecord;
ptolemy.backtrack.util.FieldRecord;
/**
* Return the next byte in the buffer. If the buffer
* is empty, more bytes are read from the input stream.
*/
public byte nextByte() throws Exception {
if (_pointer >= SIZE) {
_stream.read($BACKUP$_buffer());
$ASSIGN$_pointer(0);
}
return _buffer[$ASSIGN$SPECIAL$_pointer(11, _pointer)];
}
// The input stream to be read.
private InputStream _stream;
}
delete checkpoint
postfire
// Extra fields and methods omitted.
...
}