rpuch commented on code in PR #6661:
URL: https://github.com/apache/ignite-3/pull/6661#discussion_r2390749354


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+/**
+ * Meta information about a payload in an index file.
+ *
+ * @see IndexFileManager
+ */
+class IndexFileMeta {
+    private final long firstLogIndex;
+
+    private final long lastLogIndex;
+
+    private final int indexFilePayloadOffset;
+
+    IndexFileMeta(long firstLogIndex, long lastLogIndex, int 
indexFilePayloadOffset) {
+        this.firstLogIndex = firstLogIndex;
+        this.lastLogIndex = lastLogIndex;
+        this.indexFilePayloadOffset = indexFilePayloadOffset;
+    }
+
+    /**
+     * Returns the inclusive lower bound of log indices stored in the index 
file for the Raft Group.
+     */
+    long firstLogIndex() {
+        return firstLogIndex;
+    }
+
+    /**
+     * Returns the non-inclusive upper bound of log indices stored in the 
index file for the Raft Group.
+     */
+    long lastLogIndex() {

Review Comment:
   If something is called 'last', you expect it to be inclusive, but here it's 
not. This looks like a source of confusion. Would it make sense to make it 
inclusive?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.util.Arrays;
+
+/**
+ * An array of {@link IndexFileMeta}.
+ *
+ * <p>Reads from multiple threads are thread-safe, but writes are expected to 
be done from a single thread only.
+ */
+class IndexFileMetaArray {
+    static final int INITIAL_CAPACITY = 10;
+
+    private final IndexFileMeta[] array;
+
+    private final int size;
+
+    IndexFileMetaArray(IndexFileMeta initialMeta) {
+        this.array = new IndexFileMeta[INITIAL_CAPACITY];
+        this.array[0] = initialMeta;
+
+        this.size = 1;
+    }
+
+    private IndexFileMetaArray(IndexFileMeta[] array, int size) {
+        this.array = array;
+        this.size = size;
+    }
+
+    IndexFileMetaArray add(IndexFileMeta indexFileMeta) {
+        // The array can be shared between multiple instances, but since it 
always grows and we read at most "size" elements,
+        // we don't need to copy it every time.
+        IndexFileMeta[] array = this.array;
+
+        if (size == array.length) {
+            array = Arrays.copyOf(array, array.length * 2);
+        }
+
+        array[size] = indexFileMeta;
+
+        return new IndexFileMetaArray(array, size + 1);
+    }
+
+    IndexFileMeta get(int index) {
+        return array[index];
+    }
+
+    int size() {
+        return size;
+    }
+
+    /**
+     * Returns the index of the {@link IndexFileMeta} containing the given log 
index or {@code -1} if no such meta exists.
+     */
+    int find(long logIndex) {
+        int lowIndex = 0;

Review Comment:
   'Index' word is terribly overloaded here. It can mean
   
   * Raft index (aka log index)
   * Index over segment file
   * Ordinal number of an index file
   * Array/list index
   
   In this case, `lowIndex` is an array index, but it is used in the same 
context as `logIndex`; name difference is just 1 character!
   
   I think it would be great to be explicit about what type of index this is; 
in this case, name it `lowArrayIndex` (and do the same with 2 other variables).
   
   More broadly, it would be great to introduce a convention to make it easy to 
see what kind of an index is mentioned. Like:
   
   * logIndex/raftIndex
   * segmentIndex
   * indexFileOrdinal
   * arrayIndex



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFilePointer.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+class IndexFilePointer {
+    private final int fileIndex;

Review Comment:
   indexFileOrdinal?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents in-memory meta information about a particular Raft group stored 
in an index file.
+ */
+class GroupIndexMeta {
+    private static final VarHandle FILE_METAS_VH;
+
+    static {
+        try {
+            FILE_METAS_VH = 
MethodHandles.lookup().findVarHandle(GroupIndexMeta.class, "fileMetas", 
IndexFileMetaArray.class);
+        } catch (ReflectiveOperationException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private final int startFileIndex;
+
+    @SuppressWarnings("FieldMayBeFinal") // Updated through a VarHandle.
+    private volatile IndexFileMetaArray fileMetas;
+
+    GroupIndexMeta(int startFileIndex, IndexFileMeta startFileMeta) {
+        this.startFileIndex = startFileIndex;
+        this.fileMetas = new IndexFileMetaArray(startFileMeta);
+    }
+
+    void addIndexMeta(IndexFileMeta indexFileMeta) {
+        IndexFileMetaArray fileMetas = this.fileMetas;
+
+        IndexFileMetaArray newFileMetas = fileMetas.add(indexFileMeta);
+
+        // Simple assignment would suffice, since we only have one thread 
writing to this field, but we use compareAndSet to verify
+        // this invariant, just in case.
+        boolean updated = FILE_METAS_VH.compareAndSet(this, fileMetas, 
newFileMetas);
+
+        assert updated : "Concurrent writes detected";
+    }
+
+    /**
+     * Returns a file pointer that uniquely identifies the index file for the 
given log index or {@code null} of no such file exists.

Review Comment:
   ```suggestion
        * Returns a file pointer that uniquely identifies the index file for 
the given log index or {@code null} if no such file exists.
   ```



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents in-memory meta information about a particular Raft group stored 
in an index file.
+ */
+class GroupIndexMeta {
+    private static final VarHandle FILE_METAS_VH;
+
+    static {
+        try {
+            FILE_METAS_VH = 
MethodHandles.lookup().findVarHandle(GroupIndexMeta.class, "fileMetas", 
IndexFileMetaArray.class);
+        } catch (ReflectiveOperationException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private final int startFileIndex;
+
+    @SuppressWarnings("FieldMayBeFinal") // Updated through a VarHandle.
+    private volatile IndexFileMetaArray fileMetas;
+
+    GroupIndexMeta(int startFileIndex, IndexFileMeta startFileMeta) {
+        this.startFileIndex = startFileIndex;
+        this.fileMetas = new IndexFileMetaArray(startFileMeta);
+    }
+
+    void addIndexMeta(IndexFileMeta indexFileMeta) {
+        IndexFileMetaArray fileMetas = this.fileMetas;
+
+        IndexFileMetaArray newFileMetas = fileMetas.add(indexFileMeta);
+
+        // Simple assignment would suffice, since we only have one thread 
writing to this field, but we use compareAndSet to verify
+        // this invariant, just in case.
+        boolean updated = FILE_METAS_VH.compareAndSet(this, fileMetas, 
newFileMetas);
+
+        assert updated : "Concurrent writes detected";
+    }
+
+    /**
+     * Returns a file pointer that uniquely identifies the index file for the 
given log index or {@code null} of no such file exists.
+     */
+    @Nullable
+    IndexFilePointer indexFilePointer(long logIndex) {
+        IndexFileMetaArray fileMetas = this.fileMetas;
+
+        int arrayIndex = fileMetas.find(logIndex);

Review Comment:
   Why do we need to return an index from `find()`? Could we just return an 
`IndexFileMeta` right away?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents in-memory meta information about a particular Raft group stored 
in an index file.
+ */
+class GroupIndexMeta {
+    private static final VarHandle FILE_METAS_VH;
+
+    static {
+        try {
+            FILE_METAS_VH = 
MethodHandles.lookup().findVarHandle(GroupIndexMeta.class, "fileMetas", 
IndexFileMetaArray.class);
+        } catch (ReflectiveOperationException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private final int startFileIndex;
+
+    @SuppressWarnings("FieldMayBeFinal") // Updated through a VarHandle.
+    private volatile IndexFileMetaArray fileMetas;
+
+    GroupIndexMeta(int startFileIndex, IndexFileMeta startFileMeta) {
+        this.startFileIndex = startFileIndex;
+        this.fileMetas = new IndexFileMetaArray(startFileMeta);
+    }
+
+    void addIndexMeta(IndexFileMeta indexFileMeta) {
+        IndexFileMetaArray fileMetas = this.fileMetas;
+
+        IndexFileMetaArray newFileMetas = fileMetas.add(indexFileMeta);
+
+        // Simple assignment would suffice, since we only have one thread 
writing to this field, but we use compareAndSet to verify
+        // this invariant, just in case.
+        boolean updated = FILE_METAS_VH.compareAndSet(this, fileMetas, 
newFileMetas);
+
+        assert updated : "Concurrent writes detected";
+    }
+
+    /**
+     * Returns a file pointer that uniquely identifies the index file for the 
given log index or {@code null} of no such file exists.

Review Comment:
   When will it not exist?



##########
modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runRace;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.ignite.internal.lang.RunnableX;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+class GroupIndexMetaTest extends BaseIgniteAbstractTest {
+    @Test
+    void testAddGet() {
+        var initialMeta = new IndexFileMeta(1, 50, 0);
+
+        var groupMeta = new GroupIndexMeta(0, initialMeta);
+
+        var additionalMeta = new IndexFileMeta(50, 100, 42);
+
+        groupMeta.addIndexMeta(additionalMeta);
+
+        assertThat(groupMeta.indexFilePointer(0), is(nullValue()));
+
+        IndexFilePointer pointer = groupMeta.indexFilePointer(1);
+
+        assertThat(pointer, is(notNullValue()));
+        assertThat(pointer.fileIndex(), is(0));
+        assertThat(pointer.fileMeta(), is(initialMeta));
+
+        pointer = groupMeta.indexFilePointer(66);
+
+        assertThat(pointer, is(notNullValue()));
+        assertThat(pointer.fileIndex(), is(1));
+        assertThat(pointer.fileMeta(), is(additionalMeta));
+
+        pointer = groupMeta.indexFilePointer(100);
+
+        assertThat(pointer, is(nullValue()));
+    }
+
+    @RepeatedTest(10)
+    void testOneWriterMultipleReaders() {
+        int startFileIndex = 100;
+
+        int logsPerFile = 50;
+
+        var initialMeta = new IndexFileMeta(0, logsPerFile, 0);
+
+        var groupMeta = new GroupIndexMeta(startFileIndex, initialMeta);
+
+        int numItems = 1000;

Review Comment:
   Number of what? Files, log entries, something else?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+/**
+ * Meta information about a payload in an index file.
+ *
+ * @see IndexFileManager
+ */
+class IndexFileMeta {
+    private final long firstLogIndex;
+
+    private final long lastLogIndex;
+

Review Comment:
   Will generation be added later?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -119,10 +138,54 @@ IndexFile saveIndexMemtable(ReadModeIndexMemTable 
indexMemTable) throws IOExcept
             }
         }
 
-        return new IndexFile(fileName, path);
+        curFileIndex++;
+
+        return syncAndRename(tmpFilePath, 
tmpFilePath.resolveSibling(fileName));
     }
 
-    private static byte[] header(ReadModeIndexMemTable indexMemTable) {
+    /**
+     * Returns a pointer into a segment file that contains the entry for the 
given group's index or {@code null} if no such entry exists.
+     */
+    @Nullable
+    SegmentFilePointer getSegmentFilePointer(long groupId, long logIndex) 
throws IOException {
+        GroupIndexMeta groupIndexMeta = groupIndexMetas.get(groupId);
+
+        if (groupIndexMeta == null) {
+            return null;
+        }
+
+        IndexFilePointer filePointer = 
groupIndexMeta.indexFilePointer(logIndex);
+
+        if (filePointer == null) {
+            return null;
+        }
+
+        Path indexFile = 
baseDir.resolve(indexFileName(filePointer.fileIndex(), 0));
+
+        IndexFileMeta fileMeta = filePointer.fileMeta();
+
+        long payloadIndex = logIndex - fileMeta.firstLogIndex();

Review Comment:
   `payloadIndex` is an index in the array of offsets, right? Can this be 
highlighted?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -119,10 +138,54 @@ IndexFile saveIndexMemtable(ReadModeIndexMemTable 
indexMemTable) throws IOExcept
             }
         }
 
-        return new IndexFile(fileName, path);
+        curFileIndex++;
+
+        return syncAndRename(tmpFilePath, 
tmpFilePath.resolveSibling(fileName));
     }
 
-    private static byte[] header(ReadModeIndexMemTable indexMemTable) {
+    /**
+     * Returns a pointer into a segment file that contains the entry for the 
given group's index or {@code null} if no such entry exists.

Review Comment:
   Why might it not exist?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.util.Arrays;
+
+/**
+ * An array of {@link IndexFileMeta}.
+ *
+ * <p>Reads from multiple threads are thread-safe, but writes are expected to 
be done from a single thread only.
+ */
+class IndexFileMetaArray {
+    static final int INITIAL_CAPACITY = 10;
+
+    private final IndexFileMeta[] array;
+
+    private final int size;
+
+    IndexFileMetaArray(IndexFileMeta initialMeta) {
+        this.array = new IndexFileMeta[INITIAL_CAPACITY];
+        this.array[0] = initialMeta;
+
+        this.size = 1;
+    }
+
+    private IndexFileMetaArray(IndexFileMeta[] array, int size) {
+        this.array = array;
+        this.size = size;
+    }
+
+    IndexFileMetaArray add(IndexFileMeta indexFileMeta) {

Review Comment:
   Let's assert that last Raft index of the previous meta matches first Raft 
index of the current one



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents in-memory meta information about a particular Raft group stored 
in an index file.
+ */
+class GroupIndexMeta {
+    private static final VarHandle FILE_METAS_VH;
+
+    static {
+        try {
+            FILE_METAS_VH = 
MethodHandles.lookup().findVarHandle(GroupIndexMeta.class, "fileMetas", 
IndexFileMetaArray.class);
+        } catch (ReflectiveOperationException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private final int startFileIndex;

Review Comment:
   Please add javadoc explaining what this is and why we need it.
   
   Also, it seems to be about ordinal number of an index file, is that right?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java:
##########
@@ -140,23 +203,47 @@ private static byte[] header(ReadModeIndexMemTable 
indexMemTable) {
         while (it.hasNext()) {
             Entry<Long, SegmentInfo> entry = it.next();
 
-            long groupId = entry.getKey();
+            Long groupId = entry.getKey();

Review Comment:
   Is it to avoid boxing further? If yes, please explain this in a comment



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents in-memory meta information about a particular Raft group stored 
in an index file.
+ */
+class GroupIndexMeta {

Review Comment:
   In the ticket, for each group there is a 'queue' of `BlockOfIndexMetas`, and 
each `BlockOfIndexMetas` contains an array of `IndexMeta` instances, so it's a 
two-level structure. But in the code `GroupIndexMeta` has an array of 
`IndexFileMeta`, that's it.
   
   Why is the structure different? Is it not final? If yes, please note this in 
the ticket.



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFilePointer.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+class SegmentFilePointer {
+    private final int fileIndex;

Review Comment:
   ordinal?



##########
modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft.storage.segstore;
+
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runRace;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import org.apache.ignite.internal.lang.RunnableX;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.junit.jupiter.api.RepeatedTest;
+import org.junit.jupiter.api.Test;
+
+class GroupIndexMetaTest extends BaseIgniteAbstractTest {
+    @Test
+    void testAddGet() {
+        var initialMeta = new IndexFileMeta(1, 50, 0);
+
+        var groupMeta = new GroupIndexMeta(0, initialMeta);
+
+        var additionalMeta = new IndexFileMeta(50, 100, 42);
+
+        groupMeta.addIndexMeta(additionalMeta);
+
+        assertThat(groupMeta.indexFilePointer(0), is(nullValue()));
+
+        IndexFilePointer pointer = groupMeta.indexFilePointer(1);
+
+        assertThat(pointer, is(notNullValue()));
+        assertThat(pointer.fileIndex(), is(0));
+        assertThat(pointer.fileMeta(), is(initialMeta));
+
+        pointer = groupMeta.indexFilePointer(66);
+
+        assertThat(pointer, is(notNullValue()));
+        assertThat(pointer.fileIndex(), is(1));
+        assertThat(pointer.fileMeta(), is(additionalMeta));
+
+        pointer = groupMeta.indexFilePointer(100);
+
+        assertThat(pointer, is(nullValue()));
+    }
+
+    @RepeatedTest(10)
+    void testOneWriterMultipleReaders() {
+        int startFileIndex = 100;
+
+        int logsPerFile = 50;

Review Comment:
   Logs or log entries?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to