You are given an existing Python 3.10 codebase with an abstract base class RecordSink (from abc import ABC, abstractmethod) that defines open() -> None, write(record: dict) -> None, and close() -> None. A Pipeline class instantiates a sink, calls sink.open() once, then for each record calls sink.write(record), and finally calls sink.close(); Pipeline must not be modified. Implement a new concrete RotatingFileSink that:
(
-
writes each record as a compact JSON line (UTF-
-
to disk,
(
-
rotates to a new file when either a maximum number of lines N is reached or total bytes exceed limit L, using filenames like prefix_00001.log, prefix_00002.log, etc.,
(
-
supports use as a context manager via
enter
/
exit
while preserving existing open/close semantics,
(
-
is safe for concurrent write() calls from multiple threads using a lock,
(
-
raises a custom SinkClosedError if write() is invoked after close(), and
(
-
adheres to Liskov substitution so Pipeline works unchanged. Do not alter existing method signatures or the Pipeline. Provide the full class implementation and a brief unit test showing rotation and thread-safety.