Eliminate MappableJournalSegmentReader 88/110588/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2024 10:13:05 +0000 (11:13 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2024 12:51:31 +0000 (13:51 +0100)
commit2e8a82c1b46bedf40e5e3d51f03efae75d72ca48
treeb8f49cbc258f81c91b5fd11a374a5967dadeaba0
parent08ea7b7900a387c0afb07664147d3c652dc1047e
Eliminate MappableJournalSegmentReader

MappableJournalSegmentReader is an indirection used by
JournalSegmentReader to get a stable reader and the backend is
manipulated via map()/unmap() operations.

This is sort of a band-aid to lifecycle, as JournalSegment.close()
eagerly closes the writer, which in turn invalidates buffer and all that
jazz.

This dance is quite unnecessary, as JournalSegmentReader always acquires
the Segment, hence as long as it has a reader, the segment is guaranteed
to be mapped -- except for the case of close().

This patch reworks the logic in couple of ways:
- references are now guarding the writer itself, so as long as there are
  some, the writer is not closed.
- createReader() now increments the reference count, which means we can
  directly allocate the appopriate JournalSegmentReader implementation
- JournalSegmentReader.close() now routes to
  JournalSegment.closeReader(), which in turn releases the reference

JIRA: CONTROLLER-2098
Change-Id: I29b926dec5dc1a77e7e5e51ee3e2deb4f0ca6e33
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/MappableJournalSegmentReader.java [deleted file]
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalReader.java