Skip to content

Digging into the Database

Paolo "Nusco" Perrotta edited this page Sep 19, 2015 · 2 revisions

If you run Narjillos with the -s switch, it will save its state periodically to an .exp file. The file is actually a SQLite database.

The database saves three things in three separate tables. This data is then used by the lab program to do analysis - but if you wish, you can peek into it with any SQLite client. In case you do, here is how the data is structured and saved.

  1. The DNA table contains all the DNA strands that are generated in the pool. They get saved as soon as they're generated, so this table is always updated to the very last event in your experiment.

  2. The HISTORY table contains statistics for the whole ecosystem - such as the number of creatures, the amount of food, and the like. It's saved every 1000 ticks (which means every handful of seconds).

  3. The EXPERIMENT table contains a single row that contains the current state of the experiment, serialized to a large JSON blob. This is saved every ten minutes.

One last note about the EXPERIMENT table. If you find that there are two rows in this table, this means that by sheer coincidence, you interrupted your experiment right in the middle of a save. Narjillos uses this temporary redundancy to avoid losing data if the program is interrupted during the long blob-saving update. Don't worry - the program will automatically clean up the potentially half-saved second row when you load an experiment. Just pick up the experiment again, and everything will be clean.

When you start an existing experiment, the program de-serializes the JSON blob in EXPERIMENT and then continues the experiment, generating updates for the DNA and HISTORY table. This entire mechanism means that the content of EXPERIMENT will generally lag up to 10 minutes behind the content of HISTORY, which in turn will lag up to 1000 ticks behind the content of DNA. This is not a problem, because experiments are strictly deterministic. So, even if an experiment generates a HISTORY or DNA update that is already in the database, it will generally be the same data (with a few irrelevant differences, like the RUNNING_TIME column in the HISTORY table). The program will just skip updates to data that is already in the database.

Clone this wiki locally