Optimize SegmentedJournalReader.hasNext() 81/110681/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Mar 2024 19:47:54 +0000 (20:47 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 13 Mar 2024 07:28:57 +0000 (08:28 +0100)
commit87cf9d356ccaf6153ddbc0a763155c6787dc2932
treec1d49468751248ff51f5b703144e2e33361564dc
parent4daf276cc8c278a68f95828355ef22483b16d18d
Optimize SegmentedJournalReader.hasNext()

hasNext() is an extremely hot method and its behaviour depends on
JournalReader.Mode, which is invariant for a particular instance.

Expose the invariant to the JVM by splitting the class into the base,
which services Mode.ALL and a subclass, which performs the commit index
check.

Also move segment acquisition and reader positioning to
SegmentedJournal, as otherwise we would be calling hasNext() from
constructor, which is getting flagged by SpotBugs.

JIRA: CONTROLLER-2106
Change-Id: I29fca69a211fc8f21619a54fe59a8ff4012b01d0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/CommitsSegmentJournalReader.java [new file with mode: 0644]
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournalReader.java