Skip to content

1.4. Data Integrity

Jimmy Bourque edited this page Nov 30, 2026 · 1 revision

Français

The data-integrity task is an automated maintenance process that verifies the consistency of application data stored as JSON files in Azure Blob Storage. It runs automatically according to a configured schedule, so manual integrity checks are not required.

The application does not use a relational database. This keeps operating costs low, but requires the application to validate relationships between books, exams, catalog indexes, and user profiles.

Because the application follows an event-driven architecture, an issue during an event flow may create inconsistent information. The data-integrity task detects missing, invalid, or inconsistent data and fixes it.

This task is processed by the JbtiEvolution.OraklLearn.Indexer project, which runs background tasks to maintain application data and supporting structures, including integrity checks, index maintenance, and relationships between content and user profiles.

Mutex Settings

Settings are defined in AppSettings.json files for instances that participate in the mutex mechanism. The mutex name used by the data-integrity task is "data-integrity". The following values are recommended for all instance settings.

Key Description Type / Unit Example Value
Mutex Configuration section for the mutex mechanism. It defines how instances synchronize, report their alive status, and coordinate exclusive access to protected resources. Array
Mutex[].Name The unique mutex name string data-integrity
Mutex[].HeartBeatSecondsInterval Interval at which an instance updates its heartbeat. The heartbeat is a date and time written to the instance mutex file to confirm that the instance is still alive. During the same update, the instance reads the global mutex locking state and adapts its internal behavior if that state has changed. integer / seconds 10
Mutex[].LeaseMinutesExpiration Maximum duration after which an instance heartbeat is considered expired. If the current time exceeds the last heartbeat timestamp plus this expiration duration, the instance is considered inactive or invalid and is ignored by the mutex mechanism. integer / minutes 1

Example

"Mutex": [
  {
    "Name": "data-integrity",
    "HeartBeatSecondsInterval": 10,
    "LeaseMinutesExpiration": 1
  }
]

Important Timing Rule

Rule Explanation
HeartBeatSecondsInterval must be lower than LeaseMinutesExpiration The instance must update its heartbeat before its lease expires.
Example With HeartBeatSecondsInterval = 10 seconds and LeaseMinutesExpiration = 1 minute, the instance refreshes its heartbeat every 10 seconds, while expiration occurs after 60 seconds.
Lock transition If an instance is waiting for active operations that use protected resources to finish, it continues updating its heartbeat. Therefore, the transition to an active locking policy may take longer than LeaseMinutesExpiration without causing the instance to be considered expired.

Mutex States

State Meaning
locked The mutex is locked. The owner instance requires exclusive access to specific protected resources in order to execute a critical operation without interference from other instances.
unlocked The mutex is free. Instances may access resources normally, according to the application rules.

Instance Locking Policies

Each instance writes its current policy to its instance mutex file using the current_policy value.

current_policy Meaning
none The instance is not applying any locking restriction. This is the normal state when the global mutex is free.
applying_locking The instance has detected and acknowledged the locked state and is applying the required restrictions. Active operations that already use protected resources may still be running, so the instance waits for them to finish. The heartbeat continues to be updated during this transition.
active_locking The instance has completed the transition to the locking policy. No active operation is using the protected resources, and the instance will not start new operations that require those resources.

When an instance detects that the mutex is free, it immediately releases its locking restrictions and updates its instance mutex file with current_policy = none.

Lock Coordination Behavior

Element Description
Mutex owner The instance that requests and owns the locked state. It can start its exclusive operation only after the other active instances have applied the locking policy.
Active instances Instances with a valid, non-expired heartbeat. Expired instances are ignored by the mutex mechanism.
Lock detection During each heartbeat update, an instance reads the global mutex locking state. If the state has changed, the instance adapts its internal behavior.
Behavior adaptation After detecting a locked state, an instance stops starting operations that use protected resources. Operations that are already using those resources are allowed to finish.
Lock acknowledgement After detecting the locking state, the instance updates its instance mutex file with current_policy = applying_locking. This indicates that the instance is aware of the lock and is applying the required restrictions.
Waiting period The instance may need to wait for active operations that use protected resources to finish. During this waiting period, it continues updating its heartbeat so that its lease remains valid.
Lock activation After all active operations accessing protected resources have ended, the instance updates its instance mutex file with current_policy = active_locking.
Exclusive operation start The mutex owner waits until all active instances have reported current_policy = active_locking before starting its protected operation. The owner may therefore wait longer than the configured lease expiration duration, because active instances continue updating their heartbeats while they complete their transition.
Unlock handling When the global mutex changes to unlocked, each instance releases its locking restrictions and updates its instance mutex file with current_policy = none.
Allowed operations Operations that do not read from or modify resources protected by the mutex may still be executed, such as using features in the book editor or exam editor, reading a book, or practicing an exam.

Example Use Case: data-integrity Task

Case Description
Processing The data-integrity task reviews all stored books and exams, all indexed books and indexed exams used by the catalog, and all user profiles with their relationships to the catalog and stored books.
Required locking During this task, the mutex may be set to locked to prevent other instances from modifying the resources being analyzed.
Lock confirmation Before starting the exclusive data-integrity operation, the mutex owner waits until all active instances have detected the lock, completed their transition, and reported current_policy = active_locking.
Protected resources Stored books, stored exams, catalog book indexes, catalog exam indexes, user profiles, and the relationships between user profiles, and stored books may be protected by the mutex.
Example of a blocked operation A user profile cannot be modified while the mutex is locked, because an integrity issue may be detected and the profile file may need to be corrected.
Example of an allowed operation Operations that do not read from or modify resources protected by the mutex may still be executed, such as using features in the book editor or exam editor, reading a book, or practicing an exam.

Clone this wiki locally