Simulator
This lesson explains how to interact with the simulator for the exercise presented in the next lesson.
We'll cover the following...
The program, afs.py
, allows you to experiment with the cache consistency
behavior of the Andrew File System (AFS). The program generates random client
traces (of file opens, reads, writes, and closes), enabling the user to see if
they can predict what values end up in various files.
Here is an example run:
prompt> ./afs.py -C 2 -n 1 -s 12
Server c0 c1
file:a contains:0
open:a [fd:0]
write:0 value? -> 1
close:0
open:a [fd:0]
read:0 -> value?
close:0
file:a contains:?
prompt>
The trace is fairly simple to read. On the left is the server, and each column
shows actions being taken on each of two clients (use -C <clients>
to specify
a different number). Each client generates one random action (-n 1
), which is
either the open/read/close of a file or the open/write/close of a file. The
contents of a file, for simplicity, is always just a single number.
To generate different traces, use -s
(for a random seed), as always. Here we
set it to 12
to get this specific trace.
In the trace, the server shows the initial contents of all the files in the system:
file:a contains:0
As you can see in this trace, there is just one file (a
) and it contains the
value 0
.
Time increases downwards, and what is next is client 0 (c0
) opening the file
a
(which returns a file descriptor, 0 in this case), writing to that
descriptor, and then closing the file.
Immediately you see the first question posed to you:
write:0 value? -> 1
When writing to descriptor 0, you are overwriting an existing value with the new value of 1. What was that old value? (pretty easy in this case: 0).
Then client 1 begins doing some work (c1
). It ...