Question
Implement a log writer that accepts binary records from multiple threads and durably appends each complete record to a file.
```python
class DataWriter:
def __init__(self, file_path: str): ...
def push(self, data: bytes) -> None: ...
def close(self) -> None: ...
```
## Requirements
- Encode each record as a four-byte big-endian length followed by its payload.
- `push` returns only after all bytes for that record are written and the file is synchronized to durable storage.
- A record's bytes must never interleave with another record.
- Calls from one thread retain program order; calls from different threads may appear in either order.
- `close` must coordinate with active or future pushes and be idempotent.
- Handle partial writes, I/O errors, and payload lengths that cannot be represented.
After `close` completes, later pushes must raise an error rather than silently disappear. A push concurrent with close either completes its synchronization first or is rejected without a new record. Binary inputs are immutable bytes. The supplied sequential framing checks use a temporary file; browser-local checks cannot prove physical disk durability or concurrent behavior. Those require separate native maintainer tests.
If writing, flushing or synchronizing fails, propagate that failure and hold the writer in a failed state: subsequent pushes raise `RuntimeError` without writing new bytes. Existing partial bytes are uncertain, not rolled back or claimed durable. Zero-byte write progress is an `OSError`; do not loop forever. `close` remains available after failure.
## Design discussion (not graded)
1. Add a reader that detects a truncated final record after a crash.
2. Implement group commit without breaking the durability contract.
3. Add bounded buffering and backpressure.
4. Discuss checksums, rotation, and atomic recovery metadata.