controller.git
2 hours agoImprove segmented journal actor metrics 03/111103/6 master
Ruslan Kashapov [Wed, 27 Mar 2024 08:52:41 +0000 (10:52 +0200)]
Improve segmented journal actor metrics

Update write time marked on actual flush not on flush request.

JIRA: CONTROLLER-2108
Change-Id: I92a66ae775cbae6aeea69bddf654df741f473dbd
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
29 hours agoRemove JournalWriter.getLastEntry() 78/111478/2
Robert Varga [Mon, 22 Apr 2024 10:49:02 +0000 (12:49 +0200)]
Remove JournalWriter.getLastEntry()

We really do not want to retain a written entry -- and there is only a
single real user. Remove this method and update its sole caller.

JIRA: CONTROLLER-2115
Change-Id: Ibea3d820fa7d1daa023be1cdcc1a513720744b6e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
34 hours agoRemove bierman02 terminology from dev guide 91/109291/10
Oleksandr Zharov [Mon, 11 Dec 2023 16:08:51 +0000 (17:08 +0100)]
Remove bierman02 terminology from dev guide

Updated dev guide terminology after bierman02 removal.

JIRA: CONTROLLER-2088
Change-Id: I6e77b54c4c2fe1629b4a1014944c26110735a075
Signed-off-by: Oleksandr Zharov <oleksandr.zharov@pantheon.tech>
34 hours agoUse Netty to clean mapped buffers 73/111473/2
Robert Varga [Mon, 22 Apr 2024 08:20:31 +0000 (10:20 +0200)]
Use Netty to clean mapped buffers

Netty offers PlatformDependent.freeDirectBuffer(), use that to clean our
buffers.

Change-Id: Id737c9e951bc1c77376133d7053287e2840bafc6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
35 hours agoRefactor JournalReader.tryNext() 72/111472/6
Robert Varga [Sun, 21 Apr 2024 13:28:18 +0000 (15:28 +0200)]
Refactor JournalReader.tryNext()

We are usually translating an entry to an internal representation,
encode that in the API signature.

Since we have an API method to carry Indexed.* fields, we reduce our
reliance on this DTO. This leads to more efficient advance during reset,
as we do not need to instantiate Indexed instance.

JIRA: CONTROLLER-2115
Change-Id: I1d399e14997fb93b100397afab785778e47f985b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
2 days agoRemove JournalReader.getCurrentEntry() 71/111471/3
Robert Varga [Sun, 21 Apr 2024 12:51:20 +0000 (14:51 +0200)]
Remove JournalReader.getCurrentEntry()

JournalReader.currentEntry is just a single-entry cache which is not
used anywhere but tests. Remove the public method and private field.

While we are at it, make SegmentedJournalReader.tryNext() state
index management more obvious.

JIRA: CONTROLLER-2115
Change-Id: If92293e8393e71a4c1f402a0370973872a9593ac
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
2 days agoCap index to sequenceNr before tryNext() 70/111470/3
Robert Varga [Sun, 21 Apr 2024 12:04:40 +0000 (14:04 +0200)]
Cap index to sequenceNr before tryNext()

Rather than relying on Indexed.index(), which requires us to attempt to
read the next entry, use a simple getNextIndex() check.

JIRA: CONTROLLER-2115
Change-Id: Id1d7638dda0d909b8383af8f1e201fb9e7f192e0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
2 days agoFactor out FileWriter interface 86/111086/11
Robert Varga [Wed, 27 Mar 2024 00:15:59 +0000 (01:15 +0100)]
Factor out FileWriter interface

We have two specializations of JournalSegmentWriter just to provide
specialized write access. Factor out the require interface into
FileWriter and specialize that instead of JournalSegmentWriter.

JIRA: CONTROLLER-2100
Change-Id: Ie6a2497f49d7e1e00f32836cccbf0680b17b15e3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
2 days agoSegmented journal benchmark 43/111143/5
Ruslan Kashapov [Fri, 29 Mar 2024 15:47:43 +0000 (17:47 +0200)]
Segmented journal benchmark

Performance test for sal-akka-segmented-journal moved
and refactored to standalone benchmark module, making
self-contained executable jar; 'benchmark' profile
executes benchmark via maven build using current
configuration (taken from sal-clustering-config)

JIRA: CONTROLLER-2114
Change-Id: I108f7aa99b089bdc1ae12b99fcc6ff4bf53bbd38
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
5 days agoFixup checkstyle 31/111431/2
Robert Varga [Tue, 16 Apr 2024 12:23:15 +0000 (14:23 +0200)]
Fixup checkstyle

Updated checkstyle is picking up a few new warnings. Fix them up.

Change-Id: Ib5fa92b84c7e4570098a1bd1163f0947a86ed7a9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 days agoatomic-storage: remove type dependency at segment level I/O 17/111217/3
Ruslan Kashapov [Wed, 3 Apr 2024 09:53:20 +0000 (12:53 +0300)]
atomic-storage: remove type dependency at segment level I/O

Due to object de- and serialization was served by segment
I/O artifacts it required these artifacts holding serializer
instance and being dependent on its type (generics).

Moving serialization to upper level (journal) allows segment
reader/writer operate on byte level only with no extra data
conversions. Serializer interface simplified for further
isolation and removal of Kryo serializer.

JIRA: CONTROLLER-2115
Change-Id: I8f6bac3192a0f38b627150be4c8ea128f1e233e5
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
13 days agoFix followerDistributedDataStore tear down 57/111357/1
lubos-cicut [Wed, 10 Apr 2024 08:48:50 +0000 (10:48 +0200)]
Fix followerDistributedDataStore tear down

Fix closing of followerDistributedDataStore in
DistributedDataStoreRemotingIntegrationTest#tearDown.

Change-Id: Iba35cae665f29a9da0430baff1f792191a4d1287
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
3 weeks agoBump versions to 9.0.3-SNAPSHOT 07/111107/1
Robert Varga [Wed, 27 Mar 2024 12:19:56 +0000 (13:19 +0100)]
Bump versions to 9.0.3-SNAPSHOT

This starts the next development iteration.

Change-Id: I4263aa380442f375497222c0c2050e2a585c6adf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoRelease controller v9.0.2
jenkins-releng [Wed, 27 Mar 2024 10:37:57 +0000 (10:37 +0000)]
Release controller

3 weeks agoDefer up to maxEntrySize flushes by default 00/111100/2
Robert Varga [Wed, 27 Mar 2024 04:09:55 +0000 (05:09 +0100)]
Defer up to maxEntrySize flushes by default

Batching flushes has performance benefits in terms of throughput.
Keeping the flush size at maxEntrySize makes the flush times more
consistent, as the journal's syncs will be amortized to fit writing
maxEntrySize'd entries.

JIRA: CONTROLLER-2108
Change-Id: Ie385738f65d9503fdeeed6a9e0b5ced37fde7fd3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoDo not use BufferOverflowException for EOF signalling 84/111084/2
Robert Varga [Tue, 26 Mar 2024 23:20:26 +0000 (00:20 +0100)]
Do not use BufferOverflowException for EOF signalling

A neat benefit of well-structured code is that it makes it clear what
the contracts are.

In this patch we eliminate a source of BufferOverflowExceptions and opt
to report the fact next segment is needed via a @Nullable return.

JIRA: CONTROLLER-2100
Change-Id: I1b9535053561709dc2a4b60446cd7cabd19da659
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoCentralize JournalSegmentWriter.append() 81/111081/3
Robert Varga [Tue, 26 Mar 2024 23:04:35 +0000 (00:04 +0100)]
Centralize JournalSegmentWriter.append()

We have almost-identical implementations of append(), differing only
slightly in how the do buffer management.

Expose a ByteBuffer-based API to writing to segment file, in terms of
abstract methods and pull the implementation down into the superclass.

JIRA: CONTROLLER-2100
Change-Id: I8d5629019d1c5d2978b0861e30e80346fbfc3c31
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoRename JournalSegment.index() 80/111080/3
Robert Varga [Tue, 26 Mar 2024 21:16:59 +0000 (22:16 +0100)]
Rename JournalSegment.index()

'index' is an overloaded term. firstIndex() is much more descriptive
than 'index()', which is easily confused with public API argument names.

JIRA: CONTROLLER-2100
Change-Id: I7848a6bb0e1e7b4a1c7f63c8e6db5b02bd0dab76
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoUnify JournalSegmentWriter.truncate() 79/111079/3
Robert Varga [Tue, 26 Mar 2024 20:59:30 +0000 (21:59 +0100)]
Unify JournalSegmentWriter.truncate()

Implementations of truncate are practically identical, merge them into a
common method. Also eliminate JournalSegmentWriter.firstIndex, as we can
get it from the segment at any time.

JIRA: CONTROLLER-2100
Change-Id: I019978461b67693f109cd6e90c8fba2ed8b18a3f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoUnify JournalSegmentWriter.reset(long) 78/111078/3
Robert Varga [Tue, 26 Mar 2024 20:43:19 +0000 (21:43 +0100)]
Unify JournalSegmentWriter.reset(long)

We have two distinct implementations here. The version for
StorageLevel.DISK is generic enough to work for StorageLevel.MAPPED, and
will guarantee consistency with reader implementation (which is already
shared across StorageLevels).

JIRA: CONTROLLER-2100
Change-Id: I3e9a5c8a72be766431e5cb527cae1f4809964dd7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoRework MappedJournalSegmentWriter position tracking 77/111077/4
Robert Varga [Tue, 26 Mar 2024 20:03:48 +0000 (21:03 +0100)]
Rework MappedJournalSegmentWriter position tracking

Use an internal field to track the position. Also align entry reading
logic by slicing the appropriate buffer.

JIRA: CONTROLLER-2100
Change-Id: Iaa36fb32d9ffb7b215bef7829f8d3e7e5728e4b9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoFix SegmentEntry license 85/111085/1
Robert Varga [Wed, 27 Mar 2024 00:14:56 +0000 (01:14 +0100)]
Fix SegmentEntry license

All this code is Apache-2 licensed, fix the header.

JIRA: CONTROLLER-2109
Change-Id: If0604f566c43a844da4522c2274a3b1a9f308a03
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoFix reader/writer buffer sharing 83/111083/1
Robert Varga [Tue, 26 Mar 2024 23:46:44 +0000 (00:46 +0100)]
Fix reader/writer buffer sharing

DiskFileReaders should share the buffer with with their writers.

JIRA: CONTROLLER-2109
Change-Id: I79203b7111827cd1b9885956fc6ca98bf621a12a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
3 weeks agoShorten currentPosition 76/111076/2
Robert Varga [Tue, 26 Mar 2024 19:17:44 +0000 (20:17 +0100)]
Shorten currentPosition

Our current file position is limited to 2^31-1, hence we can safely use
an int instead of a long. This is what StorageLevel.MAPPED needs anyway.

JIRA: CONTROLLER-2100
Change-Id: Idddea88cdc031f515675a39afb64115ded39fe0b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoAllow segmented journal to flush periodically 80/110880/5
Robert Varga [Tue, 19 Mar 2024 20:42:14 +0000 (21:42 +0100)]
Allow segmented journal to flush periodically

Flushes to disk end up dominating our use of disk resources, as we issue
a flush after each write. This is not entirely efficient, as we may have
multiple outstanding writes in the actor queue -- and we ignore the
batching opportunity.

This patch makes it possible to configure an upper bound of the number
of outstanding bytes written which can remainin unflushed.

We flush whenever we reach this watermark or when we flush all messages
that have been submitted at the time the flush batch has been started.

JIRA: CONTROLLER-2108
Change-Id: I6f18de7871c89b5feffecc71580e1f440024f2a3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoRename patched ByteBufferInput 08/111008/5
Robert Varga [Mon, 25 Mar 2024 08:47:22 +0000 (09:47 +0100)]
Rename patched ByteBufferInput

Hide the patched version and renake it to Kryo505ByteBufferInput.

JIRA: CONTROLLER-2109
Change-Id: Ie2b50dab13f1ae93e343f18acf4a05a890616576
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoDeploy fix of ByteBufferInput and use it 07/111007/12
Robert Varga [Mon, 25 Mar 2024 08:24:52 +0000 (09:24 +0100)]
Deploy fix of ByteBufferInput and use it

readAscii() just wants to fix up the last byte it passes to the String
constructor. Do that after reading.

Inherit everything alse that is not required from the regular
ByteBufferInput to minimize code duplication.

JIRA: CONTROLLER-2109
Change-Id: Ic12b8e06317a8376b34d514daaf1ba7d46d16178
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoUnify Disk segment reading 03/111003/10
Robert Varga [Sat, 23 Mar 2024 23:52:08 +0000 (00:52 +0100)]
Unify Disk segment reading

DiskJournalSegmentWriter contains code duplicating DiskFileReader. Let's
remediate the situation by having an internal DiskFileReader, through
which we access the file in a read-only manner.

JIRA: CONTROLLER-2109
Change-Id: I0a5ffd1aebbea71513f6cd70e2138562755316fa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoAdd almost-verbatim kryo.io.ByteBufferInput from kryo-4.0.3 06/111006/7
Robert Varga [Mon, 25 Mar 2024 08:15:58 +0000 (09:15 +0100)]
Add almost-verbatim kryo.io.ByteBufferInput from kryo-4.0.3

We are about to address a deeply-seated problem. Import souces almost
verbatim. Changes:
- inline MAX_SAFE_ARRAY_SIZE
- different package
- CR/LF changed
- javadoc corrected

JIRA: CONTROLLER-2109
Change-Id: I56cbaa7e541d9e78025095cb86effae8f97883c6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoLower reader buffering 02/111002/8
Robert Varga [Sat, 23 Mar 2024 22:41:35 +0000 (23:41 +0100)]
Lower reader buffering

We are choosing buffer for two entries. This is a legacy choice, when we
could not compact our buffer and is actively hostile to large
maxEntrySize.

At the end of the day we really need space for one full entry. Since we
are being smart re. buffer management, we do not need the doubled buffer
size -- so allocate just what we need.

One exemption is when the buffer would be less than 8KiB -- in that case
just do not bother and cache up to 8KiB as needed.

JIRA: CONTROLLER-2109
Change-Id: Ic03df7e271e59588608f07c097b3831db83d7bd7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoFactor out FileReader interface 01/111001/5
Robert Varga [Sat, 23 Mar 2024 21:52:25 +0000 (22:52 +0100)]
Factor out FileReader interface

As it turns out, JournalSegmentReader's specializations are providing a
very simple API they provide via abstract methods.

Extract this API into FileReader, allowing JournalSegmentReader to
become a final class, reducing mental requirements to understand what is
going on.

JIRA: CONTROLLER-2109
Change-Id: I4199f10a9483b18ac381f16e2b0d818f2d74ac16
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoRemove JournalReader.getCurrentIndex() 05/111005/3
Robert Varga [Mon, 25 Mar 2024 07:34:32 +0000 (08:34 +0100)]
Remove JournalReader.getCurrentIndex()

This method is used only in tests and has the weird 'or 0' return.
Refactor test asserts and remove this method.

Change-Id: If397f2398e75d08de867cf4c674a1dd14e8add30
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoRefactor JournalSegmentReader 00/111000/6
Robert Varga [Sat, 23 Mar 2024 21:00:34 +0000 (22:00 +0100)]
Refactor JournalSegmentReader

We have almost-duplicated code in {Disk,Mapped}JournalSegmentReader,
which looks very similar to what DiskJournalSegmentWriter revolves
around.

JournalSegmentReader revolves around tracking current position and
interpreting bytes read. Its specializations provide the means for
access.

JIRA: CONTROLLER-2109
Change-Id: I80b78cde5baf6b222d888e635dd5c854331f261a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoDo not use ByteBufferInput 04/111004/4
Robert Varga [Mon, 25 Mar 2024 07:05:59 +0000 (08:05 +0100)]
Do not use ByteBufferInput

ByteBufferInput ends up calling ByteBuffer.put() in readAscii(). Work
this around by integrating through InputStream. Not exactly nice, but
the best we can do right now.

JIRA: CONTROLLER-2109
Change-Id: I182c3cefb97ada0cd9fdc2b7440256f38341df5a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoMove entry tracking to SegmentedJournalReader 98/110998/10
Robert Varga [Sat, 23 Mar 2024 13:51:23 +0000 (14:51 +0100)]
Move entry tracking to SegmentedJournalReader

We have duplicated state tracking just because JournalSegmentReader used
to provide the same API as SegmentedJournalReader.

Rehost tracking the next index and current entry into
SegmentedJournalReader, making it more obvious as to what is going on.

This allows Indexed to enforce the entry being non-null, as we do not
have to use a fake entry anymore.

JIRA: CONTROLLER-2109
Change-Id: I9ebd50fde94d695bb62315bba1b6adb1235b37f1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoSimplify JournalSegmentReader entry access 99/110999/1
Robert Varga [Sat, 23 Mar 2024 12:27:22 +0000 (13:27 +0100)]
Simplify JournalSegmentReader entry access

The only user is SegmentedJournalReader, which is using these methods to
implement its tryNext() operation.

Mirror this with JournalSegmentReader.tryNext(), which simplifies some
of the logic.

JIRA: CONTROLLER-2109
Change-Id: Id104743b16199b4734b322d1397b85280f03346b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoJournalIndex.truncate() should return last entry 49/110949/1
Robert Varga [Thu, 21 Mar 2024 08:47:32 +0000 (09:47 +0100)]
JournalIndex.truncate() should return last entry

The only time we are calling truncate(), we are following up with a seek
to the appropriate entry.

Return the last indexed position from truncate(), so we can do better
than a linear search.

JIRA: CONTROLLER-2109
Change-Id: I701b0eefbf1f4d83f74ba95b93c41407289d95cb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoMove ENTRY_HEADER_BYTES 07/110907/1
Robert Varga [Wed, 20 Mar 2024 15:52:24 +0000 (16:52 +0100)]
Move ENTRY_HEADER_BYTES

We have SegmentEntry.HEADER_BYTES instead of ENTRY_HEADER_BYTES.

JIRA: CONTROLLER-2109
Change-Id: I4bc66155dccd3e177a61bad28be50e0bc62827ab
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoIntroduce SegmentEntry 96/110896/4
Robert Varga [Wed, 20 Mar 2024 00:52:54 +0000 (01:52 +0100)]
Introduce SegmentEntry

This is a helper DTO to communicate CRC32 and a buffer slice during
DiskJournalSegmentWriter's indexing.

This allows us improve the reset(long) loop to a manageable size, which
is mostly self-explanatory.

JIRA: CONTROLLER-2109
Change-Id: Ife1bddaf7684a304a0e7cdfd24ca9e774ac5143d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoImprove disk entry access 10/110810/5
Robert Varga [Sun, 17 Mar 2024 11:22:10 +0000 (12:22 +0100)]
Improve disk entry access

Eliminate superfluous compactions while a complete entry is available.
This is done by carefully looking at the buffer and figuring out how
many bytes we actually need progress.

JIRA: CONTROLLER-2109
Change-Id: If091b5c6f74da6a989629dae49137ed492725e2d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
4 weeks agoSegmentJournal.log is static 97/110897/2
Robert Varga [Wed, 20 Mar 2024 01:16:42 +0000 (02:16 +0100)]
SegmentJournal.log is static

This is derived from getClass() on a final class -- hence we can
amortize the logger into a static field, from whence it will be
constant-propagated.

Change-Id: Idcc6cf2d86c5ae687694fa5c16089687ac4a949a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoDelete test directories after test 42/110842/1
Robert Varga [Mon, 18 Mar 2024 11:47:18 +0000 (12:47 +0100)]
Delete test directories after test

We have files in target being archived. Remove them after the test
finishes.

Change-Id: I68ea84a78e82bffcc3d8e0868b2f492759f64f90
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoBump versions to 9.0.2-SNAPSHOT 76/110776/1
Robert Varga [Fri, 15 Mar 2024 16:07:51 +0000 (17:07 +0100)]
Bump versions to 9.0.2-SNAPSHOT

This starts the next deveopment iteration.

Change-Id: I5940bc14b5261316778f547b0111b62b3a983bdb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoRelease controller v9.0.1
jenkins-releng [Fri, 15 Mar 2024 14:14:17 +0000 (14:14 +0000)]
Release controller

5 weeks agoChange FileChannel prefix to Disk 51/110751/1
Robert Varga [Fri, 15 Mar 2024 12:26:10 +0000 (13:26 +0100)]
Change FileChannel prefix to Disk

We use FileChannelJournalSegment{Reader,Writer} for StorageLevel.DISK,
and Mapped* for StorageLevel.MAPPED.

Fix this by a quick rename to DiskJournaSegment{Reader,Writer},
improving internal consistency and shortening class names.

Change-Id: Ia6d7311ed93527ff77cde3f7b57bb34689f962cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoAdd PANTHEON.tech copyright headers 50/110750/2
Robert Varga [Fri, 15 Mar 2024 12:20:47 +0000 (13:20 +0100)]
Add PANTHEON.tech copyright headers

These files have been significantly altered and hence deserve a
contributor copyright with a fresh year.

JIRA: CONTROLLER-2105
Change-Id: Ieceb00a54d204db5ba8bb92971a719f2b0815c59
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoNormalized copyright header 49/110749/2
Robert Varga [Fri, 15 Mar 2024 12:10:18 +0000 (13:10 +0100)]
Normalized copyright header

Use a closed range and our standard 'and others' moniker.

JIRA: CONTROLLER-2105
Change-Id: I868b02415666da378f395ff711d5092a334d0196
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoFuther improvements to ByteBuffer invocations 48/110748/1
Robert Varga [Fri, 15 Mar 2024 11:13:18 +0000 (12:13 +0100)]
Futher improvements to ByteBuffer invocations

MappedJournalSegmentWriter should take advantage of fluent APIs of
ByteBuffer.

JIRA: CONTROLLER-2097
Change-Id: If12fe247bd08db450e00ea9878ecfafb7f75596b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoCentralize entry header size 47/110747/1
Robert Varga [Fri, 15 Mar 2024 11:09:13 +0000 (12:09 +0100)]
Centralize entry header size

We jave 'Integer.BYTES + Integer.BYTES' strewn all across the code,
centralize this constant into a single place.

JIRA: CONTROLLER-2098
Change-Id: If15f944db20b01767ca387f652ddf11fed64e2fa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoMake JournalSegmentWriter.getNextIndex() final 46/110746/1
Robert Varga [Fri, 15 Mar 2024 10:11:11 +0000 (11:11 +0100)]
Make JournalSegmentWriter.getNextIndex() final

We have duplicated code between the two implementations. Centralize it
to the common superclass.

JIRA: CONTROLLER-2098
Change-Id: I84b1a1d716c2ccbaaf2f75e3728bcbad0aa05ec6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoMake JournalSegmentWriter.getLastIndex() final 45/110745/1
Robert Varga [Fri, 15 Mar 2024 10:05:21 +0000 (11:05 +0100)]
Make JournalSegmentWriter.getLastIndex() final

We have duplicated code between the two implementations. Centralize it
to the common superclass.

JIRA: CONTROLLER-2098
Change-Id: I805e882566d8f891c23a1f25143d453c94284cd1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoImprove ByteBuffer invocations 44/110744/1
Robert Varga [Fri, 15 Mar 2024 09:58:55 +0000 (10:58 +0100)]
Improve ByteBuffer invocations

ByteBuffer has a fluent API, returning the same buffer from methods
which do not return something else.

Take advantage of this a chain invocations, resulting in denser byte
code.

JIRA: CONTROLLER-2097
Change-Id: Ic744e5e4f4d8c3fec5026f9d7edc58b7a5387c0e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoImprove FileChannelJournalSegmentWriter's buffer management 35/110735/3
Oleksandr Zharov [Thu, 14 Mar 2024 13:46:11 +0000 (14:46 +0100)]
Improve FileChannelJournalSegmentWriter's buffer management

Minor refactor of logic in FileChannelJournalSegmentWriter class.
Removed unnecessary buffer clearing after each entry. New logic
remove already proccesed entry from the buffer and if needed reads
new data from FileChannel to it's capacity.

JIRA: CONTROLLER-2097
Change-Id: I571d531437b068cd468bdc92b3ab6a4223450a45
Signed-off-by: Oleksandr Zharov <oleksandr.zharov@pantheon.tech>
5 weeks agoUse correct JournalSegmentWriter for initial indexing 40/110740/1
Robert Varga [Fri, 15 Mar 2024 08:11:41 +0000 (09:11 +0100)]
Use correct JournalSegmentWriter for initial indexing

JournalSegment should look at StorageLevel and pick the appropriate
writer instead of always using FileChannelJournalSegment.

JIRA: CONTROLLER-2099
Change-Id: I060618a2808a837214b5ae61f4860f329c1799f0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoRemove LeaderLocationListenerRegistration 33/110733/2
Robert Varga [Thu, 14 Mar 2024 10:34:27 +0000 (11:34 +0100)]
Remove LeaderLocationListenerRegistration

This specialization is not used anywhere, remove it and adjust
LeaderLocationListener.

Change-Id: Ic6a738b2b34ecaca980fb222fb363ef391f24b1a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoMigrate users of deprecated methods 32/110732/2
Robert Varga [Thu, 14 Mar 2024 10:24:05 +0000 (11:24 +0100)]
Migrate users of deprecated methods

Updated yangtools/mdsal are providing a few more convenient methods, use
those instead of their deprecated equivalents.

Change-Id: I6a971e349dc7d5aed00697c179dfa0c37afa8209
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoBump upstreams 31/110731/1
Robert Varga [Thu, 14 Mar 2024 08:48:54 +0000 (09:48 +0100)]
Bump upstreams

Adopt:
- odlparent-13.0.11
- yangtools-13.0.1
- mdsal-13.0.0

Change-Id: I33bbfb6a9016ae13cfaba8d95bf461f8167621eb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoJournalReader is not an Iterator 94/110694/2
Robert Varga [Wed, 13 Mar 2024 12:32:07 +0000 (13:32 +0100)]
JournalReader is not an Iterator

Iterator dictating a two method API, which is not quite appropriate, as
the writer could be manipulated between hasNext() and next() methods --
and next() has to perform validation again.

Introduce JournalReader.tryNext(), which returns a @Nullable Indexed --
either the next entry (as next()), or null (indicating !hasNext() case).

JIRA: CONTROLLER-2106
Change-Id: Ie0338a9869ece8e6381ae719a29e97fd569b442f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoCatch JournalReader.next() violations in Mode.COMMITS 90/110690/1
Robert Varga [Wed, 13 Mar 2024 09:39:30 +0000 (10:39 +0100)]
Catch JournalReader.next() violations in Mode.COMMITS

JournalReader.next() is specified as an Iterator and should be throwing
NSEs. This is not the case when we ask for only commits, as the
corresponding check is done only in hasNext() and thus we would give out
uncommitted entries.

Fix this by adding an override to check for this condition.

JIRA: CONTROLLER-2106
Change-Id: I1f391cc19b9674646786c93656b83519e0f1f47b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoUse try-with-resources in testCompactAndRecover 89/110689/1
Robert Varga [Wed, 13 Mar 2024 09:24:36 +0000 (10:24 +0100)]
Use try-with-resources in testCompactAndRecover

Eclipse is flagging a warning here, make sure we silence it.

Change-Id: I7bfa9d490e8b9b71bf04511bc42d6d101345b179
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoCache reader's nextIndex during reset() 88/110688/1
Robert Varga [Wed, 13 Mar 2024 08:50:03 +0000 (09:50 +0100)]
Cache reader's nextIndex during reset()

JournalSegmentReader.getNextIndex() involves some computation, so do not
call it twice when deciding how to reset SegmentedJournalReader.

JIRA: CONTROLLER-2106
Change-Id: I7527d8f0c47d35b7a59c30558715204a85b24eae
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoRemove JournalSegmentReader.getCurrentIndex() 87/110687/1
Robert Varga [Wed, 13 Mar 2024 07:45:42 +0000 (08:45 +0100)]
Remove JournalSegmentReader.getCurrentIndex()

This method is only ever called by SegmentedJournalReader, inline it
there. This removes one source of the magic 0 index.

JIRA: CONTROLLER-2106
Change-Id: I0fcb16e806d027d22f8e6370788aab21884c9e71
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoModernize Indexed 83/110683/3
Robert Varga [Tue, 12 Mar 2024 21:17:44 +0000 (22:17 +0100)]
Modernize Indexed

Indexed.getType() is not used anywhere, hence remove it. While we are
here, also turn the class into a record, as it is a pure DTO.

Also add a FIXME to require the actual entry to be non-null.

JIRA: CONTROLLER-2101
Change-Id: I8bd42a815096a3d0993eb41c59cf39655a7ed0fd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoOptimize SegmentedJournalReader.getCurrentEntry() 82/110682/2
Robert Varga [Tue, 12 Mar 2024 20:49:59 +0000 (21:49 +0100)]
Optimize SegmentedJournalReader.getCurrentEntry()

This method has very simple logic, the reasoning for which is left
unexplained.

Add a comment about what is going on and use assign-and-check construct
to trim a bit of byte code.

JIRA: CONTROLLER-2106
Change-Id: I5d4e5551ae089489636da38600109f7821fa306b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
5 weeks agoOptimize SegmentedJournalReader.hasNext() 81/110681/2
Robert Varga [Tue, 12 Mar 2024 19:47:54 +0000 (20:47 +0100)]
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>
5 weeks agoFix JournalSegment{Reader,Writer} license 86/110686/3
Robert Varga [Wed, 13 Mar 2024 07:23:25 +0000 (08:23 +0100)]
Fix JournalSegment{Reader,Writer} license

atomix-storage is licensed under APL, not EPL. Fix that.

Change-Id: I2a88fb978d0e1e9e22a5aecffcc4a7ca7fc2ae96
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRefactor JournalSegmentReader.readNext() 80/110680/1
Robert Varga [Tue, 12 Mar 2024 19:37:02 +0000 (20:37 +0100)]
Refactor JournalSegmentReader.readNext()

The two implementations share the callout to getNextIndex(), pull it
down to the base class to better define the API we are after.

JIRA: CONTROLLER-2099
Change-Id: Id82a039dbb02156bef43ff9f9398d0e1883cc38f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoSpecialize tests to ClientBackedDataStore 72/110672/4
Robert Varga [Tue, 12 Mar 2024 16:03:59 +0000 (17:03 +0100)]
Specialize tests to ClientBackedDataStore

We have only one subclass of AbstractDataStore, use that instead of
AbstractDataStore.

Change-Id: Ia6552b1c050fb99e3084c2d8f5c36ea052e991be
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoLock down AbstractDataStore 71/110671/2
Robert Varga [Tue, 12 Mar 2024 15:30:37 +0000 (16:30 +0100)]
Lock down AbstractDataStore

We have really only one specialization -- ClientBackedDataStore. We
therefore can further lock down the methods we expose.

Change-Id: I321c920fff6027e21c5ff78f489b192eb6675bbc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRemove StorageLevel.MEMORY 64/110664/1
Robert Varga [Tue, 12 Mar 2024 09:25:16 +0000 (10:25 +0100)]
Remove StorageLevel.MEMORY

This enum is defunct and results in DISK being used. Remove it.

JIRA: CONTROLLER-2101
Change-Id: Ibc6f6916f20e5b0fc0f3c8fe6651e65f24074d53
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRemove JournalWriter.append(Indexed) 63/110663/1
Robert Varga [Tue, 12 Mar 2024 09:24:04 +0000 (10:24 +0100)]
Remove JournalWriter.append(Indexed)

This method is only used in a single test and can be realized via the
usual append(E) method. Remove it.

JIRA: CONTROLLER-2101
Change-Id: Ie1ec3507c18d9970be4968c9239b08ad8323f3a9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoClean up JournalSegment 95/110595/2
Robert Varga [Mon, 11 Mar 2024 12:23:08 +0000 (13:23 +0100)]
Clean up JournalSegment

We have plenty of unused and needlessly-public methods. Clean that up.

Change-Id: Ie93dd9eff7f847be23bf4d7fea9acefcac0beb60
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoHide SegmentedJournal{Reader,Writer} 94/110594/3
Robert Varga [Mon, 11 Mar 2024 11:49:40 +0000 (12:49 +0100)]
Hide SegmentedJournal{Reader,Writer}

These classes are define by Journal{Reader,Writer} interfaces, hide them
as they are pure implementation details.

JIRA: CONTROLLER-2098
Change-Id: I1149b970001cb64ffe503f128cce3864e396280a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoDisconnect JournalSegmentWriter from JournalWriter 93/110593/3
Robert Varga [Mon, 11 Mar 2024 11:08:05 +0000 (12:08 +0100)]
Disconnect JournalSegmentWriter from JournalWriter

JournalSegmentWriter is really the internal API, so it should not have a
public API straightjacket. Disconnect the implementation, making method
properly package-private.

This also makes it very clear that JournalWriter is not something users
should close() -- because doing so would wreck internal machinery rather
thoroughly, rendering the segment writer inoperable -- and that should
only be possible via JournalSegment's lifecycle.

JIRA: CONTROLLER-2098
Change-Id: Ia18b0dc640cba11689bb36cf338c8cef3ae4e6f8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRemove MappableJournalSegmentWriter 91/110591/4
Robert Varga [Mon, 11 Mar 2024 10:56:22 +0000 (11:56 +0100)]
Remove MappableJournalSegmentWriter

MappableJournalSegmentWriter is now just mediating implementation access
-- which is always is now guarded by a reference.

This means we can ditch this indirection and give out
SegmentedJournalWriter directly.

JIRA: CONTROLLER-2098
Change-Id: If15bdb10f9a317960aaf41aa80c57e929923ed21
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRework JournalSegment writer access 90/110590/4
Robert Varga [Mon, 11 Mar 2024 10:45:51 +0000 (11:45 +0100)]
Rework JournalSegment writer access

The only user of JournalSegment.writer() is SegmentedJournalWriter,
which is using acquire/release to guard access to the writer.

Rework these methods so that acquire/release are internal and exposed
functionality is acquireWriter() and releaseWriter().

JIRA: CONTROLLER-2098
Change-Id: I345cec145fd82ee59c525d183584d69a9e599bf9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoDisconnect JournalSegmentReader from JournalReader 89/110589/4
Robert Varga [Mon, 11 Mar 2024 10:28:37 +0000 (11:28 +0100)]
Disconnect JournalSegmentReader from JournalReader

JournalSegmentReader is the only used by SegmentedJournalReader, which
is the actual implementation of JournalReader.

There is really no point in JournalSegmentReader to conform to the
public API, as not all elements are needed.

This disconnects JournalSegmentReader, eliminating getFirstIndex(), as
that is simply not called -- and was not conforming to the API anyway.

JIRA: CONTROLLER-2098
Change-Id: Icd802ee07207d4f6787e3bdb71e36e553f2010c3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoEliminate MappableJournalSegmentReader 88/110588/4
Robert Varga [Mon, 11 Mar 2024 10:13:05 +0000 (11:13 +0100)]
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>
6 weeks agoHide JournalSegment 87/110587/3
Robert Varga [Mon, 11 Mar 2024 10:02:19 +0000 (11:02 +0100)]
Hide JournalSegment

JournalSegment is an implementation detail, which we do not want to leak
to the outside world. Hide it an make it final.

JIRA: CONTROLLER-2098
Change-Id: Ife71005f481c7ffb3c2eb6b89d3c5afa5e7f1609
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoClean up SegmentedJournalWriter 84/110584/2
Robert Varga [Mon, 11 Mar 2024 08:08:57 +0000 (09:08 +0100)]
Clean up SegmentedJournalWriter

We have duplicated code in append() methods and their recovery is not
obvious. Move common code into a private method and reduce the size of
catch blocks.

JIRA: CONTROLLER-2098
Change-Id: I58e6ff19cf2eaa2e97c56499d70171cb93da6174
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoClean up SegmentedJournalReader 83/110583/2
Robert Varga [Mon, 11 Mar 2024 07:44:57 +0000 (08:44 +0100)]
Clean up SegmentedJournalReader

We have bit of duplicated code dealing with moving to next segment.
Concentrate it to a single method.

This shows the code actually has a bug, where it fails to close the
reader -- hence potentially leaking.

JIRA: CONTROLLER-2098
Change-Id: Ib58116d21cedde58c8f84d5fffd245e8e8408935
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoDo not store JournalSegment in JournalSegmentWriter 82/110582/3
Robert Varga [Sun, 10 Mar 2024 22:01:42 +0000 (23:01 +0100)]
Do not store JournalSegment in JournalSegmentWriter

We are only accessing index() and maxSegmentSize. We already copy
index() to firstIndex, so let's do the same maxSegmentSize and use
firstIndex instead of accessing segment.index().

JIRA: CONTROLLER-2098
Change-Id: Ia8a24c7f73187a5803d279309775f361a39c91b0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoInline SegmentedJournalReader.initialize() 81/110581/2
Robert Varga [Sun, 10 Mar 2024 18:25:50 +0000 (19:25 +0100)]
Inline SegmentedJournalReader.initialize()

This method is only invoked from the constructor, inline it there to
similify lifecycle.

JIRA: CONTROLLER-2098
Change-Id: I2c2790f785e13dd411a23eff299221b129a99630
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoRemove MappableJournalSegmentWriter.firstIndex() 80/110580/2
Robert Varga [Sun, 10 Mar 2024 18:20:31 +0000 (19:20 +0100)]
Remove MappableJournalSegmentWriter.firstIndex()

This method is not used anywhere, remove it. This makes
MappableJournalSegmentWriter a pure delegator with map/unmap changing
the delegate object.

JIRA: CONTROLLER-2098
Change-Id: Ifcbc22edb0046ae890837415e9751a4a8274d4d3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoShare FileChannel across all JournalSegmentReaders 79/110579/2
Robert Varga [Sun, 10 Mar 2024 18:00:39 +0000 (19:00 +0100)]
Share FileChannel across all JournalSegmentReaders

Now that neither the writer not reader manipulates FileChannel state, we
can share a single channel. This has the nice effect of lifting its
lifecycle management completely to JournalSegment.

JIRA: CONTROLLER-2096
Change-Id: Ib7653d1494fdb53d1a1c73ad20ab103b29fedaa0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoExpand JournalSegmentReader 78/110578/3
Robert Varga [Sun, 10 Mar 2024 17:21:00 +0000 (18:21 +0100)]
Expand JournalSegmentReader

The two subclasses contain a lot of duplicated code. This patch
centralizes most code to reside in JournalSegmentReader.

JIRA: CONTROLLER-2098
Change-Id: I09a968ff8a283fc86f8591ab3d302cc2af0eb86a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoIntroduce JournalSegmentReader 77/110577/2
Robert Varga [Sun, 10 Mar 2024 16:33:55 +0000 (17:33 +0100)]
Introduce JournalSegmentReader

The two implementations for accessing the file have a common API and
potentially share a lot of code. Introduce JournalSegmentReader to act
as a common superclass.

JIRA: CONTROLLER-2098
Change-Id: Ie8b524812f6193206e1df100ac55ed4f11ad9f5c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoPerform proper handoff between JournalSegmentWriters 76/110576/3
Robert Varga [Sun, 10 Mar 2024 13:27:28 +0000 (14:27 +0100)]
Perform proper handoff between JournalSegmentWriters

Switching between JournalSegmentWriter implementations is a matter of
just handing off state, which is limited to the last entry and position
in the file.

This patch introduces alternative constructors, which allow this state
to be moved to the new implementation without needing to re-read the
file.

JIRA: CONTROLLER-2043
Change-Id: I796cb4da4e09dfe6332ca82a7dfdb76740e30164
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoMove JournalSegmentWriter switchover logic 75/110575/5
Robert Varga [Sun, 10 Mar 2024 11:53:21 +0000 (12:53 +0100)]
Move JournalSegmentWriter switchover logic

This patch moves the logic to JournalSegmentWriter implementations,
which allows us to communicate internal state without the need to
re-establish it or leak it to the outside world.

JIRA: CONTROLLER-2043
Change-Id: Ifcb937fdaeaecd46b53a962c541ebfff689ecd40
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoIntroduce JournalSegmentWriter 74/110574/4
Robert Varga [Sun, 10 Mar 2024 11:22:56 +0000 (12:22 +0100)]
Introduce JournalSegmentWriter

MappableJournalSegmentWriter needs to flip between the two
implementations with seamless handoff.

Introduce JournalSegmentWriter as common superclass, exposing
currently-used interface.

JIRA: CONTROLLER-2043
JIRA: CONTROLLER-2098
Change-Id: I11f01ea027a757a32e25bf434d29abeca7d40f6e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoTrack channel position in explicit field 73/110573/4
Robert Varga [Sat, 9 Mar 2024 17:28:02 +0000 (18:28 +0100)]
Track channel position in explicit field

Rather than manipulating the channel, use an explicit field to keep
track of our current position.

JIRA: CONTROLLER-2095
Change-Id: I50adbef833251035f7c54ec624f9a03d59b5c7c9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoSimplify FileChannelJournalSegmentWriter position tracking 72/110572/3
Robert Varga [Sat, 9 Mar 2024 17:13:01 +0000 (18:13 +0100)]
Simplify FileChannelJournalSegmentWriter position tracking

This patch makes the obvious switch in state tracking: memory buffer
does not hold anything of value w.r.t. overall state, so there is no
point in marking/resetting and maintaining memory.position() beyond
what we need for reading from it.

Local 'position' acts now as the authoritative source of where we want
to go and we propagate it to channel position when we validate an entry.

JIRA: CONTROLLER-2095
Change-Id: Iab150a3c7348c714170223b397167cd4bb87f087
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoImprove entry crc32 computation 71/110571/3
Robert Varga [Sat, 9 Mar 2024 15:03:10 +0000 (16:03 +0100)]
Improve entry crc32 computation

We have a codepath difference here, where we use either a ByteBuffer or
a raw array to compute CRC32.

MappedJournalSegmentWriter does not make it immediately clear we use
this buffer twice -- once for CRC32 and once for deserialization.

Move acquisition of slice just after we have read the expected CRC32, so
it is clear it is something we would be doing even if there were no
checksum involved.

Mirror the same in FileChannelJournalSegmentWriter, as this will allow
us to further consolidate the code and stop mucking with memory.limit(),
which is causing us to invalidate our previously-set mark.

JIRA: CONTROLLER-2095
Change-Id: I355bd97cd8acb4f5d9d91310de97ecb2cbd70282
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoInvert checksum check 70/110570/2
Robert Varga [Sat, 9 Mar 2024 14:49:37 +0000 (15:49 +0100)]
Invert checksum check

We have a hardly-visible else branch which terminates our loop. Increase
its visibility by making it a dedicated if.

JIRA: CONTROLLER-2095
Change-Id: Ia0f6901793b1847a13afc5a3da3fdd5382180606
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoDo not use java.util.zip.Checksum 69/110569/3
Robert Varga [Sat, 9 Mar 2024 14:32:01 +0000 (15:32 +0100)]
Do not use java.util.zip.Checksum

We are using this interface only for local variable type declaration,
use CRC32 directly, just as MappedJournalSegmentWriter does.

JIRA: CONTROLLER-2095
Change-Id: I054c639ae49b4fccef863a363c6e8665ea1322f6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoReduce position changes during read 68/110568/2
Robert Varga [Sat, 9 Mar 2024 14:29:56 +0000 (15:29 +0100)]
Reduce position changes during read

Rather than using a read() which updates the position, requiring us to
set the position again, set it only once and use read with offset --
eliminating one syscall.

JIRA: CONTROLLER-2095
Change-Id: I478ba1cbb1f5737a751b43cb6ed0d018e49e6485
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoClean up initial FileChannel writer reset's read 67/110567/2
Robert Varga [Sat, 9 Mar 2024 14:13:20 +0000 (15:13 +0100)]
Clean up initial FileChannel writer reset's read

The code here bears marks of 'copy, paste and cudgel to compliance'
programming and is strikingly similar to what MappedJournalSegmentWriter
does -- except it needs to deal with reading as well.

This patch takes the first step towards sanity by eliminating a useless
if() and uses FileChannel.read(ByteBuffer, long) to reduce position
adjustments.

JIRA: CONTROLLER-2095
Change-Id: I528cb14608402a406e20d168a7e8520c9eb66edf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoOptimize MappedJournalSegmentWriter.truncate() 66/110566/2
Robert Varga [Sat, 9 Mar 2024 13:33:11 +0000 (14:33 +0100)]
Optimize MappedJournalSegmentWriter.truncate()

Reduce code duplication by separating current position manipulation and
entry zero-out.

Also use a single putLong() instead of two putInt()s, eliminating one
range check.

Overall this makes the two implementations much more similar, allowing
sharing code at some later point in the future.

JIRA: CONTROLLER-2095
Change-Id: I9791b5e27a779210b5500a7923ccada7156f26e5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoOptimize FileChannelJournalSegmentWriter.truncate() 65/110565/2
Robert Varga [Sat, 9 Mar 2024 13:09:45 +0000 (14:09 +0100)]
Optimize FileChannelJournalSegmentWriter.truncate()

FileChannelJournalSegmentWriter.truncate() is inefficient in that it
zeroes-out its memory buffer and then writes it completely out.

This patch aligns it with what MappedJournalSegmentWriter does, which is
just zeroing out the entry header -- reducing both IO and CPU overheads.

JIRA: CONTROLLER-2095
Change-Id: I487157e78524cc9b00c9efff2064dbe892638ae4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
6 weeks agoImprove FileChannelJournalSegmentWriter.truncate() 63/110563/3
Robert Varga [Sat, 9 Mar 2024 12:30:12 +0000 (13:30 +0100)]
Improve FileChannelJournalSegmentWriter.truncate()

Reduce the dance around channel position by explicitly passing it down,
thus reducing the number of syscalls we incur.

Also inline FileChannelJournalSegmentWriter.zero() and add a FIXME to
improve our zero-out strategy.

JIRA: CONTROLLER-2095
Change-Id: I885947fef51132a294c900396d902cf5481e2bd8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>