This is an automated email from the ASF dual-hosted git repository.
apolovtsev pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 0378e392c61 IGNITE-26739 Use exclusive last log indices in Log Storage
(#6798)
0378e392c61 is described below
commit 0378e392c61c7f73b1cec27033e1758a90669bf3
Author: Alexander Polovtcev <[email protected]>
AuthorDate: Thu Oct 16 15:38:07 2025 +0300
IGNITE-26739 Use exclusive last log indices in Log Storage (#6798)
---
.../raft/storage/segstore/GroupIndexMeta.java | 8 +++----
.../raft/storage/segstore/IndexFileManager.java | 24 ++++++++++----------
.../raft/storage/segstore/IndexFileMeta.java | 26 +++++++++++-----------
.../raft/storage/segstore/IndexFileMetaArray.java | 18 ++++++++++-----
.../raft/storage/segstore/RaftLogCheckpointer.java | 10 ++++-----
.../raft/storage/segstore/SegmentFileManager.java | 20 +++++++++--------
.../raft/storage/segstore/SegmentInfo.java | 6 ++---
.../raft/storage/segstore/SegstoreLogStorage.java | 8 ++++---
.../storage/segstore/DeserializedIndexFile.java | 4 ++--
.../raft/storage/segstore/GroupIndexMetaTest.java | 23 +++++++------------
.../storage/segstore/IndexFileMetaArrayTest.java | 26 +++++++++++-----------
.../storage/segstore/SegmentFileManagerTest.java | 12 +++++-----
12 files changed, 95 insertions(+), 90 deletions(-)
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java
index 3227b418fc9..5ee00ff8b47 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMeta.java
@@ -63,13 +63,13 @@ class GroupIndexMeta {
return fileMetas.find(logIndex);
}
- long firstLogIndex() {
- return fileMetas.get(0).firstLogIndex();
+ long firstLogIndexInclusive() {
+ return fileMetas.get(0).firstLogIndexInclusive();
}
- long lastLogIndex() {
+ long lastLogIndexExclusive() {
IndexFileMetaArray fileMetas = this.fileMetas;
- return fileMetas.get(fileMetas.size() - 1).lastLogIndex();
+ return fileMetas.get(fileMetas.size() - 1).lastLogIndexExclusive();
}
}
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java
index f2b5b36d086..1e1ed1e4f16 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java
@@ -163,8 +163,8 @@ class IndexFileManager {
Path indexFile =
baseDir.resolve(indexFileName(indexFileMeta.indexFileOrdinal(), 0));
- // Index file payload is a 0-based array, which indices correspond to
the [fileMeta.firstLogIndex, fileMeta.lastLogIndex] range.
- long payloadArrayIndex = logIndex - indexFileMeta.firstLogIndex();
+ // Index file payload is a 0-based array, which indices correspond to
the [fileMeta.firstLogIndex, fileMeta.lastLogIndex) range.
+ long payloadArrayIndex = logIndex -
indexFileMeta.firstLogIndexInclusive();
assert payloadArrayIndex >= 0 : payloadArrayIndex;
@@ -192,19 +192,19 @@ class IndexFileManager {
/**
* Returns the lowest log index for the given group across all index files
or {@code -1} if no such index exists.
*/
- long firstLogIndex(long groupId) {
+ long firstLogIndexInclusive(long groupId) {
GroupIndexMeta groupIndexMeta = groupIndexMetas.get(groupId);
- return groupIndexMeta == null ? -1 : groupIndexMeta.firstLogIndex();
+ return groupIndexMeta == null ? -1 :
groupIndexMeta.firstLogIndexInclusive();
}
/**
- * Returns the highest log index for the given group across all index
files or {@code -1} if no such index exists.
+ * Returns the highest possible log index for the given group across all
index files or {@code -1} if no such index exists.
*/
- long lastLogIndex(long groupId) {
+ long lastLogIndexExclusive(long groupId) {
GroupIndexMeta groupIndexMeta = groupIndexMetas.get(groupId);
- return groupIndexMeta == null ? -1 : groupIndexMeta.lastLogIndex();
+ return groupIndexMeta == null ? -1 :
groupIndexMeta.lastLogIndexExclusive();
}
private byte[] serializeHeaderAndFillMetadata(ReadModeIndexMemTable
indexMemTable) {
@@ -230,11 +230,11 @@ class IndexFileManager {
SegmentInfo segmentInfo = entry.getValue();
- long firstLogIndex = segmentInfo.firstLogIndex();
+ long firstLogIndexInclusive = segmentInfo.firstLogIndexInclusive();
- long lastLogIndex = segmentInfo.lastLogIndex();
+ long lastLogIndexExclusive = segmentInfo.lastLogIndexExclusive();
- var indexFileMeta = new IndexFileMeta(firstLogIndex, lastLogIndex,
payloadOffset, curFileOrdinal);
+ var indexFileMeta = new IndexFileMeta(firstLogIndexInclusive,
lastLogIndexExclusive, payloadOffset, curFileOrdinal);
putIndexFileMeta(groupId, indexFileMeta);
@@ -242,8 +242,8 @@ class IndexFileManager {
.putLong(groupId)
.putInt(0) // Flags.
.putInt(payloadOffset)
- .putLong(firstLogIndex)
- .putLong(lastLogIndex);
+ .putLong(firstLogIndexInclusive)
+ .putLong(lastLogIndexExclusive);
payloadOffset += payloadSize(segmentInfo);
}
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java
index 30e759755f5..9c5bf9a77cb 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMeta.java
@@ -25,17 +25,17 @@ import org.apache.ignite.internal.tostring.S;
* @see IndexFileManager
*/
class IndexFileMeta {
- private final long firstLogIndex;
+ private final long firstLogIndexInclusive;
- private final long lastLogIndex;
+ private final long lastLogIndexExclusive;
private final int indexFilePayloadOffset;
private final int indexFileOrdinal;
- IndexFileMeta(long firstLogIndex, long lastLogIndex, int
indexFilePayloadOffset, int indexFileOrdinal) {
- this.firstLogIndex = firstLogIndex;
- this.lastLogIndex = lastLogIndex;
+ IndexFileMeta(long firstLogIndexInclusive, long lastLogIndexExclusive, int
indexFilePayloadOffset, int indexFileOrdinal) {
+ this.firstLogIndexInclusive = firstLogIndexInclusive;
+ this.lastLogIndexExclusive = lastLogIndexExclusive;
this.indexFilePayloadOffset = indexFilePayloadOffset;
this.indexFileOrdinal = indexFileOrdinal;
}
@@ -43,15 +43,15 @@ class IndexFileMeta {
/**
* Returns the inclusive lower bound of log indices stored in the index
file for the Raft Group.
*/
- long firstLogIndex() {
- return firstLogIndex;
+ long firstLogIndexInclusive() {
+ return firstLogIndexInclusive;
}
/**
- * Returns the inclusive upper bound of log indices stored in the index
file for the Raft Group.
+ * Returns the exclusive upper bound of log indices stored in the index
file for the Raft Group.
*/
- long lastLogIndex() {
- return lastLogIndex;
+ long lastLogIndexExclusive() {
+ return lastLogIndexExclusive;
}
/**
@@ -75,15 +75,15 @@ class IndexFileMeta {
}
IndexFileMeta that = (IndexFileMeta) o;
- return firstLogIndex == that.firstLogIndex && lastLogIndex ==
that.lastLogIndex
+ return firstLogIndexInclusive == that.firstLogIndexInclusive &&
lastLogIndexExclusive == that.lastLogIndexExclusive
&& indexFilePayloadOffset == that.indexFilePayloadOffset
&& indexFileOrdinal == that.indexFileOrdinal;
}
@Override
public int hashCode() {
- int result = Long.hashCode(firstLogIndex);
- result = 31 * result + Long.hashCode(lastLogIndex);
+ int result = Long.hashCode(firstLogIndexInclusive);
+ result = 31 * result + Long.hashCode(lastLogIndexExclusive);
result = 31 * result + indexFilePayloadOffset;
result = 31 * result + indexFileOrdinal;
return result;
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java
index 472566fb54f..6ec73edac44 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArray.java
@@ -45,10 +45,10 @@ class IndexFileMetaArray {
}
IndexFileMetaArray add(IndexFileMeta indexFileMeta) {
- assert indexFileMeta.firstLogIndex() == array[size - 1].lastLogIndex()
+ 1 :
+ assert indexFileMeta.firstLogIndexInclusive() == array[size -
1].lastLogIndexExclusive() :
String.format("Index File Metas must be contiguous. Expected
log index: %d, actual log index: %d",
- array[size - 1].lastLogIndex() + 1,
- indexFileMeta.firstLogIndex()
+ array[size - 1].lastLogIndexExclusive(),
+ indexFileMeta.firstLogIndexInclusive()
);
// The array can be shared between multiple instances, but since it
always grows and we read at most "size" elements,
@@ -72,6 +72,14 @@ class IndexFileMetaArray {
return size;
}
+ long firstLogIndexInclusive() {
+ return array[0].firstLogIndexInclusive();
+ }
+
+ long lastLogIndexExclusive() {
+ return array[size - 1].lastLogIndexExclusive();
+ }
+
/**
* Returns the {@link IndexFileMeta} containing the given Raft log index
or {@code null} if no such meta exists.
*/
@@ -85,9 +93,9 @@ class IndexFileMetaArray {
IndexFileMeta midValue = array[middleArrayIndex];
- if (logIndex < midValue.firstLogIndex()) {
+ if (logIndex < midValue.firstLogIndexInclusive()) {
highArrayIndex = middleArrayIndex - 1;
- } else if (logIndex > midValue.lastLogIndex()) {
+ } else if (logIndex >= midValue.lastLogIndexExclusive()) {
lowArrayIndex = middleArrayIndex + 1;
} else {
return midValue;
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/RaftLogCheckpointer.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/RaftLogCheckpointer.java
index 122aeb3e64c..89435d042f9 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/RaftLogCheckpointer.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/RaftLogCheckpointer.java
@@ -129,7 +129,7 @@ class RaftLogCheckpointer {
/**
* Returns the lowest log index for the given group present in the
checkpoint queue or {@code -1} if no such index exists.
*/
- long firstLogIndex(long groupId) {
+ long firstLogIndexInclusive(long groupId) {
Iterator<Entry> it = queue.tailIterator();
long firstIndex = -1;
@@ -138,7 +138,7 @@ class RaftLogCheckpointer {
SegmentInfo segmentInfo =
it.next().memTable().segmentInfo(groupId);
if (segmentInfo != null) {
- firstIndex = segmentInfo.firstLogIndex();
+ firstIndex = segmentInfo.firstLogIndexInclusive();
}
}
@@ -146,16 +146,16 @@ class RaftLogCheckpointer {
}
/**
- * Returns the highest log index for the given group present in the
checkpoint queue or {@code -1} if no such index exists.
+ * Returns the highest possible log index for the given group present in
the checkpoint queue or {@code -1} if no such index exists.
*/
- long lastLogIndex(long groupId) {
+ long lastLogIndexExclusive(long groupId) {
Iterator<Entry> it = queue.tailIterator();
while (it.hasNext()) {
SegmentInfo segmentInfo =
it.next().memTable().segmentInfo(groupId);
if (segmentInfo != null) {
- return segmentInfo.lastLogIndex();
+ return segmentInfo.lastLogIndexExclusive();
}
}
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java
index 86a5a211b53..b17a07cc61f 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java
@@ -219,12 +219,12 @@ class SegmentFileManager implements ManuallyCloseable {
/**
* Returns the lowest log index for the given group present in the storage
or {@code -1} if no such index exists.
*/
- long firstLogIndex(long groupId) {
+ long firstLogIndexInclusive(long groupId) {
long logIndexFromMemtable = firstLogIndexFromMemtable(groupId);
- long logIndexFromCheckpointQueue = checkpointer.firstLogIndex(groupId);
+ long logIndexFromCheckpointQueue =
checkpointer.firstLogIndexInclusive(groupId);
- long logIndexFromIndexFiles = indexFileManager.firstLogIndex(groupId);
+ long logIndexFromIndexFiles =
indexFileManager.firstLogIndexInclusive(groupId);
if (logIndexFromIndexFiles >= 0) {
return logIndexFromIndexFiles;
@@ -242,26 +242,28 @@ class SegmentFileManager implements ManuallyCloseable {
SegmentInfo segmentInfo =
currentSegmentFile.memtable().segmentInfo(groupId);
- return segmentInfo == null ? -1 : segmentInfo.firstLogIndex();
+ return segmentInfo == null ? -1 : segmentInfo.firstLogIndexInclusive();
}
/**
- * Returns the highest log index for the given group present in the
storage or {@code -1} if no such index exists.
+ * Returns the highest possible exclusive log index for the given group or
{@code -1} if no such index exists.
+ *
+ * <p>The highest log index currently present in the storage can be
computed as {@code lastLogIndexExclusive - 1}.
*/
- long lastLogIndex(long groupId) {
+ long lastLogIndexExclusive(long groupId) {
long logIndexFromMemtable = lastLogIndexFromMemtable(groupId);
if (logIndexFromMemtable >= 0) {
return logIndexFromMemtable;
}
- long logIndexFromCheckpointQueue = checkpointer.lastLogIndex(groupId);
+ long logIndexFromCheckpointQueue =
checkpointer.lastLogIndexExclusive(groupId);
if (logIndexFromCheckpointQueue >= 0) {
return logIndexFromCheckpointQueue;
}
- return indexFileManager.lastLogIndex(groupId);
+ return indexFileManager.lastLogIndexExclusive(groupId);
}
private long lastLogIndexFromMemtable(long groupId) {
@@ -269,7 +271,7 @@ class SegmentFileManager implements ManuallyCloseable {
SegmentInfo segmentInfo =
currentSegmentFile.memtable().segmentInfo(groupId);
- return segmentInfo == null ? -1 : segmentInfo.lastLogIndex();
+ return segmentInfo == null ? -1 : segmentInfo.lastLogIndexExclusive();
}
/**
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentInfo.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentInfo.java
index 2e22002b7db..e4428cd2f12 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentInfo.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentInfo.java
@@ -133,15 +133,15 @@ class SegmentInfo {
/**
* Returns the inclusive lower bound of log indices stored in this
memtable.
*/
- long firstLogIndex() {
+ long firstLogIndexInclusive() {
return logIndexBase;
}
/**
* Returns the inclusive upper bound of log indices stored in this
memtable.
*/
- long lastLogIndex() {
- return logIndexBase + segmentFileOffsets.size() - 1;
+ long lastLogIndexExclusive() {
+ return logIndexBase + segmentFileOffsets.size();
}
/**
diff --git
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegstoreLogStorage.java
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegstoreLogStorage.java
index d1ac329e082..7e0a28e9756 100644
---
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegstoreLogStorage.java
+++
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegstoreLogStorage.java
@@ -83,16 +83,18 @@ class SegstoreLogStorage implements LogStorage {
@Override
public long getFirstLogIndex() {
- long firstLogIndex = segmentFileManager.firstLogIndex(groupId);
+ long firstLogIndex =
segmentFileManager.firstLogIndexInclusive(groupId);
+ // JRaft requires to return 1 as the first log index if there are no
entries.
return firstLogIndex >= 0 ? firstLogIndex : 1;
}
@Override
public long getLastLogIndex() {
- long lastLogIndex = segmentFileManager.lastLogIndex(groupId);
+ long lastLogIndex = segmentFileManager.lastLogIndexExclusive(groupId);
- return lastLogIndex >= 0 ? lastLogIndex : 0;
+ // JRaft requires to return 0 as the last log index if there are no
entries.
+ return Math.max(lastLogIndex - 1, 0);
}
@Override
diff --git
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/DeserializedIndexFile.java
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/DeserializedIndexFile.java
index e32532e87ef..b0ed9cc5e7e 100644
---
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/DeserializedIndexFile.java
+++
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/DeserializedIndexFile.java
@@ -75,7 +75,7 @@ class DeserializedIndexFile {
long lastIndex = groupMeta.getLong();
// Read the payload of the group.
- int payloadEntriesNum = (int) (lastIndex - firstIndex + 1);
+ int payloadEntriesNum = (int) (lastIndex - firstIndex);
Map<Long, Integer> logIndexToSegmentFileOffset =
newHashMap(payloadEntriesNum);
@@ -89,7 +89,7 @@ class DeserializedIndexFile {
channel.position(currentPosition);
- for (long logIndex = firstIndex; logIndex <= lastIndex;
logIndex++) {
+ for (long logIndex = firstIndex; logIndex < lastIndex;
logIndex++) {
logIndexToSegmentFileOffset.put(logIndex,
indexPayload.getInt());
}
}
diff --git
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java
index a4d781e75e0..717b70dc08b 100644
---
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java
+++
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/GroupIndexMetaTest.java
@@ -20,7 +20,6 @@ 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;
@@ -35,25 +34,19 @@ class GroupIndexMetaTest extends BaseIgniteAbstractTest {
var groupMeta = new GroupIndexMeta(initialMeta);
- var additionalMeta = new IndexFileMeta(51, 100, 42, 1);
+ var additionalMeta = new IndexFileMeta(50, 100, 42, 1);
groupMeta.addIndexMeta(additionalMeta);
assertThat(groupMeta.indexMeta(0), is(nullValue()));
- IndexFileMeta indexFileMeta = groupMeta.indexMeta(1);
+ assertThat(groupMeta.indexMeta(1), is(initialMeta));
- assertThat(indexFileMeta, is(notNullValue()));
- assertThat(indexFileMeta, is(initialMeta));
+ assertThat(groupMeta.indexMeta(50), is(additionalMeta));
- indexFileMeta = groupMeta.indexMeta(66);
+ assertThat(groupMeta.indexMeta(66), is(additionalMeta));
- assertThat(indexFileMeta, is(notNullValue()));
- assertThat(indexFileMeta, is(additionalMeta));
-
- indexFileMeta = groupMeta.indexMeta(101);
-
- assertThat(indexFileMeta, is(nullValue()));
+ assertThat(groupMeta.indexMeta(100), is(nullValue()));
}
@RepeatedTest(10)
@@ -62,7 +55,7 @@ class GroupIndexMetaTest extends BaseIgniteAbstractTest {
int logEntriesPerFile = 50;
- var initialMeta = new IndexFileMeta(0, logEntriesPerFile - 1, 0,
startFileOrdinal);
+ var initialMeta = new IndexFileMeta(0, logEntriesPerFile, 0,
startFileOrdinal);
var groupMeta = new GroupIndexMeta(initialMeta);
@@ -71,7 +64,7 @@ class GroupIndexMetaTest extends BaseIgniteAbstractTest {
RunnableX writer = () -> {
for (int relativeFileOrdinal = 1; relativeFileOrdinal <
totalIndexFiles; relativeFileOrdinal++) {
long startLogIndex = relativeFileOrdinal * logEntriesPerFile;
- long lastLogIndex = startLogIndex + logEntriesPerFile - 1;
+ long lastLogIndex = startLogIndex + logEntriesPerFile;
groupMeta.addIndexMeta(new IndexFileMeta(startLogIndex,
lastLogIndex, 0, startFileOrdinal + relativeFileOrdinal));
}
@@ -90,7 +83,7 @@ class GroupIndexMetaTest extends BaseIgniteAbstractTest {
int expectedStartLogIndex = relativeFileOrdinal *
logEntriesPerFile;
- int expectedEndLogIndex = expectedStartLogIndex +
logEntriesPerFile - 1;
+ int expectedEndLogIndex = expectedStartLogIndex +
logEntriesPerFile;
var expectedMeta = new
IndexFileMeta(expectedStartLogIndex, expectedEndLogIndex, 0,
expectedFileOrdinal);
diff --git
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArrayTest.java
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArrayTest.java
index ce6e81a97ad..44fc67718f4 100644
---
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArrayTest.java
+++
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileMetaArrayTest.java
@@ -28,14 +28,14 @@ import org.junit.jupiter.api.Test;
class IndexFileMetaArrayTest extends BaseIgniteAbstractTest {
@Test
void testAddGet() {
- var initialMeta = new IndexFileMeta(1, 1, 0, 0);
+ var initialMeta = new IndexFileMeta(1, 2, 0, 0);
var array = new IndexFileMetaArray(initialMeta);
assertThat(array.size(), is(1));
assertThat(array.get(0), is(initialMeta));
- var meta2 = new IndexFileMeta(2, 2, 0, 1);
+ var meta2 = new IndexFileMeta(2, 3, 0, 1);
array = array.add(meta2);
@@ -43,12 +43,12 @@ class IndexFileMetaArrayTest extends BaseIgniteAbstractTest
{
assertThat(array.get(1), is(meta2));
for (int i = 0; i < INITIAL_CAPACITY; i++) {
- long logIndex = meta2.firstLogIndex() + i + 1;
+ long logIndex = meta2.firstLogIndexInclusive() + i + 1;
- array = array.add(new IndexFileMeta(logIndex, logIndex, 0, i + 2));
+ array = array.add(new IndexFileMeta(logIndex, logIndex + 1, 0, i +
2));
}
- var meta3 = new IndexFileMeta(INITIAL_CAPACITY + 3, INITIAL_CAPACITY +
3, 0, INITIAL_CAPACITY + 3);
+ var meta3 = new IndexFileMeta(INITIAL_CAPACITY + 3, INITIAL_CAPACITY +
4, 0, INITIAL_CAPACITY + 3);
array = array.add(meta3);
@@ -59,8 +59,8 @@ class IndexFileMetaArrayTest extends BaseIgniteAbstractTest {
@Test
void testFindReturnsCorrectIndex() {
var meta1 = new IndexFileMeta(1, 10, 100, 0);
- var meta2 = new IndexFileMeta(11, 20, 200, 1);
- var meta3 = new IndexFileMeta(21, 30, 300, 2);
+ var meta2 = new IndexFileMeta(10, 20, 200, 1);
+ var meta3 = new IndexFileMeta(20, 30, 300, 2);
IndexFileMetaArray array = new IndexFileMetaArray(meta1)
.add(meta2)
@@ -70,17 +70,17 @@ class IndexFileMetaArrayTest extends BaseIgniteAbstractTest
{
assertThat(array.find(1), is(meta1));
assertThat(array.find(5), is(meta1));
- assertThat(array.find(10), is(meta1));
+ assertThat(array.find(9), is(meta1));
- assertThat(array.find(11), is(meta2));
+ assertThat(array.find(10), is(meta2));
assertThat(array.find(15), is(meta2));
- assertThat(array.find(20), is(meta2));
+ assertThat(array.find(19), is(meta2));
- assertThat(array.find(21), is(meta3));
+ assertThat(array.find(20), is(meta3));
assertThat(array.find(25), is(meta3));
- assertThat(array.find(30), is(meta3));
+ assertThat(array.find(29), is(meta3));
- assertThat(array.find(31), is(nullValue()));
+ assertThat(array.find(30), is(nullValue()));
}
@Test
diff --git
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManagerTest.java
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManagerTest.java
index fe3f9e7d749..6ac85e32815 100644
---
a/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManagerTest.java
+++
b/modules/raft/src/test/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManagerTest.java
@@ -350,18 +350,18 @@ class SegmentFileManagerTest extends IgniteAbstractTest {
List<byte[]> batches = randomData(batchSize, 100);
IntFunction<RunnableX> writerTaskFactory = groupId -> () -> {
- assertThat(fileManager.firstLogIndex(groupId), is(-1L));
- assertThat(fileManager.lastLogIndex(groupId), is(-1L));
+ assertThat(fileManager.firstLogIndexInclusive(groupId), is(-1L));
+ assertThat(fileManager.lastLogIndexExclusive(groupId), is(-1L));
for (int i = 0; i < batches.size(); i++) {
appendBytes(groupId, batches.get(i), i);
- assertThat(fileManager.firstLogIndex(groupId), is(0L));
- assertThat(fileManager.lastLogIndex(groupId), is((long) i));
+ assertThat(fileManager.firstLogIndexInclusive(groupId),
is(0L));
+ assertThat(fileManager.lastLogIndexExclusive(groupId), is(i +
1L));
}
- assertThat(fileManager.firstLogIndex(groupId), is(0L));
- assertThat(fileManager.lastLogIndex(groupId), is((long)
(batches.size() - 1)));
+ assertThat(fileManager.firstLogIndexInclusive(groupId), is(0L));
+ assertThat(fileManager.lastLogIndexExclusive(groupId), is((long)
batches.size()));
};
runRace(writerTaskFactory.apply(0), writerTaskFactory.apply(1));