> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cdf/3.1/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/cdf/3.1/dets-files.md).

# DETS files

The [CDR records](https://en.wikipedia.org/wiki/Charging_data_record) are stored in [DETS](https://www.erlang.org/doc/man/dets.html) files. These files are moved from the receiver to [S3](https://en.wikipedia.org/wiki/S3). The sender moves these files from S3 and sends the CDR records in them. When a CDR has been sent, it is stored in another DETS file, which is eventually (when sufficiently full) archived in S3.

Moving files to S3 is done in two steps:

1. CDF downloads a file to the local disk and saves this copy under a temporary name.
2. When copying is complete, the original is deleted.

Moving files from S3 is done in three steps:

1. CDF creates a local file copy by uploading file content that has been compressed, to a temporary file with a matching name.
2. When copying is complete, it is renamed with the target name.
3. When that action is successful, the original is deleted. In the case of a failure, CDF tries again.

This diagram presents the detailed data flow of CDF:

![Data flow in CDF](https://docs.cennso.com/api/assets/components/cdf/3.1/assets/cdf3-data-flow.svg)

1. The receiver receives ACR records from Rf (DIAMETER).

2. ACRs are saved as CDRs in DETS files on disk. You can configure the directory in the `values.yaml` file:

   ```yaml
      receiver:
         directory: aname
   ```

   Example: `file:///data/2011-12-13/aname/20000.dets`

   After a configurable time, the DETS file is closed and moved to a staging area.
   Example: `file:///data/2011-12-13/aname/to_sender/20000.dets`

3. Files in the staging area are moved to S3, in a configurable bucket.
   Example: `s3://s3bucket/2011-12-13/aname/to_sender/20000.dets`

   If it is not possible to move files to S3, they stay on the disk until it is possible.

4. The sender searches for files in S3. The search starts with oldest date first and only switches to the next date after all files in the `to_sender/` directory are sent. Only the configured directories are searched. You can configure the directories in the `values.yaml` file:

   ```yaml
   sender:
      directories:
      - aname
   ```

   Example: `s3://s3bucket/2011-12-13/aname/to_sender/20000.dets`

5. The sender moves files from S3 to the disk. No more than two files at a time are stored on the disk in the `to_sender/` directory.
   File `20002.dets` is only moved from S3 after `20000.dets` is gone, meaning that all records are sent.
   Example: `file:///data/2011-12-13/aname/to_sender/20002.dets`

6. The sender reads the CDRs from the file.
   Example: `file:///data/2011-12-13/aname/10000.dets`

7. The sender sends the CDRs.

8. The sender stores the record in a new DETS file.

9. The sender deletes the record from the old file.

   When the new DETS file is full, it is closed and moved to a staging area.
   Example: `file:///data/2011-12-13/aname/to_archive/10000.dets`

10. Files in the staging area are moved to S3 in a configurable bucket.
   Example: `s3://s3bucket/2011-12-13/aname/to_archive/10000.dets`

   If it is not possible to move files to/from S3 they stay on the disk until it is possible.
