Improve JsonFileDB reliability with crash recovery and file locking#1204
Open
leifermendez wants to merge 1 commit intobuilderbot-devfrom
Open
Improve JsonFileDB reliability with crash recovery and file locking#1204leifermendez wants to merge 1 commit intobuilderbot-devfrom
leifermendez wants to merge 1 commit intobuilderbot-devfrom
Conversation
…d temp recovery - Add fsync before atomic rename to ensure data is flushed to disk - Add file locking (wx flag) to prevent multi-instance write corruption - Add retry logic with exponential backoff (3 attempts) in atomicWrite - Recover data from temp files left by crashes instead of discarding them - Verify written data integrity by reading back and validating after write - Propagate write errors to callers instead of swallowing silently - Use compact JSON serialization (no pretty-print) for better performance - Add 9 reliability tests covering recovery, locking, and integrity https://claude.ai/code/session_01PPG9yRSRNvAE9me3FNYhoX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Que tipo de Pull Request es?
Descripción
Resumen de cambios
Esta PR mejora significativamente la confiabilidad de
JsonFileDBimplementando mecanismos robustos de recuperación ante crashes y control de concurrencia:Características principales:
Recuperación de archivos temporales: Si existe un archivo
.tmpde un crash anterior, el sistema intenta recuperar los datos si contienen más entradas que el archivo principal.Sistema de bloqueo de archivos: Implementa un mecanismo simple pero efectivo de file locking usando archivos
.lockcon:Escritura atómica mejorada:
fsync()para garantizar persistencia en discoMejor manejo de errores:
Suite completa de tests de confiabilidad (
reliability.test.ts):Cambios técnicos:
atomicWrite()con reintentos y verificaciónMAX_RETRIES,RETRY_BASE_MS,LOCK_STALE_MSrecoverFromTempFile(),acquireLock(),releaseLock()Beneficios:
✅ Mayor durabilidad ante interrupciones inesperadas
✅ Soporte para múltiples instancias sin corrupción de datos
✅ Mejor performance con JSON compacto
✅ Recuperación automática de estados inconsistentes
✅ Cobertura de tests exhaustiva
Forma parte de este proyecto:
https://claude.ai/code/session_01PPG9yRSRNvAE9me3FNYhoX