← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design and implement a Durable Log Writer that multiple threads can call concurrently to append records to a file on disk.
Requirements
write() returns to a caller, the record must survive a process crash or power loss.fsync for the entire batch (group-commit).API to implement
class DurableLogWriter {
// Create or open the log file at `path` and optionally run recovery.
DurableLogWriter(Path path, boolean recover) throws IOException;
// Append `data` to the log and return only after the record is durable.
// This call must be thread-safe.
void write(byte[] data) throws IOException;
// Close the log file.
void close() throws IOException;
// Return an iterator over all valid records in the file (used for recovery).
Iterator<byte[]> iterator() throws IOException;
}
Record format you must use
Each record is laid out as:
[4 bytes length][variable data][4 bytes CRC32 of data]
The length field lets readers skip to the next record; the CRC lets readers detect corruption and stop at the first invalid record.