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 82576ea5cd IGNITE-21885 Fix AssertionError in RocksDbSortedIndexStorage#scan (#3523) 82576ea5cd is described below commit 82576ea5cd862f805f2e88b91ba968e781d68770 Author: Alexander Polovtcev <alex.polovt...@gmail.com> AuthorDate: Fri Mar 29 15:35:29 2024 +0200 IGNITE-21885 Fix AssertionError in RocksDbSortedIndexStorage#scan (#3523) * Fix incorrect offset in assertion * Use non-zero partition ID in tests --- .../internal/storage/index/TestHashIndexStorageTest.java | 4 +++- .../internal/storage/index/TestSortedIndexStorageTest.java | 4 +++- .../internal/storage/index/AbstractIndexStorageTest.java | 2 +- .../storage/index/AbstractSortedIndexStorageTest.java | 12 ++++++------ .../ignite/internal/storage/index/impl/TestIndexRow.java | 4 ++-- .../storage/rocksdb/index/RocksDbSortedIndexStorage.java | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestHashIndexStorageTest.java b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestHashIndexStorageTest.java index 66143daccf..b93fd9c7a4 100644 --- a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestHashIndexStorageTest.java +++ b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestHashIndexStorageTest.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.storage.index; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; + import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; import org.apache.ignite.internal.storage.impl.TestMvTableStorage; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +31,7 @@ import org.junit.jupiter.api.extension.ExtendWith; public class TestHashIndexStorageTest extends AbstractHashIndexStorageTest { @BeforeEach void beforeEach() { - var storage = new TestMvTableStorage(1, 10); + var storage = new TestMvTableStorage(1, DEFAULT_PARTITION_COUNT); initialize(storage); } diff --git a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestSortedIndexStorageTest.java b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestSortedIndexStorageTest.java index f9485829d0..aeeec2311b 100644 --- a/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestSortedIndexStorageTest.java +++ b/modules/storage-api/src/test/java/org/apache/ignite/internal/storage/index/TestSortedIndexStorageTest.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.storage.index; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; + import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; import org.apache.ignite.internal.storage.impl.TestMvTableStorage; import org.apache.ignite.internal.storage.index.impl.TestSortedIndexStorage; @@ -30,7 +32,7 @@ import org.junit.jupiter.api.extension.ExtendWith; public class TestSortedIndexStorageTest extends AbstractSortedIndexStorageTest { @BeforeEach void beforeEach() { - var storage = new TestMvTableStorage(1, 10); + var storage = new TestMvTableStorage(1, DEFAULT_PARTITION_COUNT); initialize(storage); } diff --git a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractIndexStorageTest.java b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractIndexStorageTest.java index 76ef74662b..8d60029747 100644 --- a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractIndexStorageTest.java +++ b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractIndexStorageTest.java @@ -76,7 +76,7 @@ public abstract class AbstractIndexStorageTest<S extends IndexStorage, D extends @SuppressWarnings("WeakerAccess") // May be used in "@VariableSource", that's why it's public. public static final List<ColumnParams> ALL_TYPES_COLUMN_PARAMS = allTypesColumnParams(); - protected static final int TEST_PARTITION = 0; + protected static final int TEST_PARTITION = 12; protected static final String INDEX_NAME = "TEST_IDX"; diff --git a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractSortedIndexStorageTest.java b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractSortedIndexStorageTest.java index 3b961138ad..2fbb534b02 100644 --- a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractSortedIndexStorageTest.java +++ b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/AbstractSortedIndexStorageTest.java @@ -274,7 +274,7 @@ public abstract class AbstractSortedIndexStorageTest extends AbstractIndexStorag List<TestIndexRow> entries = IntStream.range(0, 10) .mapToObj(i -> { - TestIndexRow entry = TestIndexRow.randomRow(indexStorage); + TestIndexRow entry = TestIndexRow.randomRow(indexStorage, TEST_PARTITION); put(indexStorage, entry); @@ -401,8 +401,8 @@ public abstract class AbstractSortedIndexStorageTest extends AbstractIndexStorag SortedIndexStorage indexStorage = createIndexStorage(INDEX_NAME, indexSchema); - TestIndexRow entry1 = TestIndexRow.randomRow(indexStorage); - TestIndexRow entry2 = TestIndexRow.randomRow(indexStorage); + TestIndexRow entry1 = TestIndexRow.randomRow(indexStorage, TEST_PARTITION); + TestIndexRow entry2 = TestIndexRow.randomRow(indexStorage, TEST_PARTITION); if (entry2.compareTo(entry1) < 0) { TestIndexRow t = entry2; @@ -423,7 +423,7 @@ public abstract class AbstractSortedIndexStorageTest extends AbstractIndexStorag void testNullValues(ColumnParams columnParams) { SortedIndexStorage storage = createIndexStorage(INDEX_NAME, List.of(columnParams)); - TestIndexRow entry1 = TestIndexRow.randomRow(storage); + TestIndexRow entry1 = TestIndexRow.randomRow(storage, TEST_PARTITION); Object[] nullArray = new Object[1]; @@ -1411,12 +1411,12 @@ public abstract class AbstractSortedIndexStorageTest extends AbstractIndexStorag private void testPutGetRemove(List<ColumnParams> indexSchema) { SortedIndexStorage indexStorage = createIndexStorage(INDEX_NAME, indexSchema); - TestIndexRow entry1 = TestIndexRow.randomRow(indexStorage); + TestIndexRow entry1 = TestIndexRow.randomRow(indexStorage, TEST_PARTITION); TestIndexRow entry2; // using a cycle here to protect against equal keys being generated do { - entry2 = TestIndexRow.randomRow(indexStorage); + entry2 = TestIndexRow.randomRow(indexStorage, TEST_PARTITION); } while (entry1.indexColumns().byteBuffer().equals(entry2.indexColumns().byteBuffer())); put(indexStorage, entry1); diff --git a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/impl/TestIndexRow.java b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/impl/TestIndexRow.java index 20244e2fc4..56d0eb71d8 100644 --- a/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/impl/TestIndexRow.java +++ b/modules/storage-api/src/testFixtures/java/org/apache/ignite/internal/storage/index/impl/TestIndexRow.java @@ -61,7 +61,7 @@ public class TestIndexRow implements IndexRow, Comparable<TestIndexRow> { /** * Creates an row with random column values that satisfies the given schema. */ - public static TestIndexRow randomRow(SortedIndexStorage indexStorage) { + public static TestIndexRow randomRow(SortedIndexStorage indexStorage, int partitionId) { var random = new Random(); Object[] columns = indexStorage.indexDescriptor().columns().stream() @@ -69,7 +69,7 @@ public class TestIndexRow implements IndexRow, Comparable<TestIndexRow> { .map(type -> generateRandomValue(random, type)) .toArray(); - var rowId = new RowId(0); + var rowId = new RowId(partitionId); var serializer = new BinaryTupleRowSerializer(indexStorage.indexDescriptor()); diff --git a/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java b/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java index b4f5c60b7e..0b4ca1ed02 100644 --- a/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java +++ b/modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java @@ -19,8 +19,8 @@ package org.apache.ignite.internal.storage.rocksdb.index; import static org.apache.ignite.internal.rocksdb.RocksUtils.incrementPrefix; import static org.apache.ignite.internal.storage.rocksdb.RocksDbStorageUtils.KEY_BYTE_ORDER; +import static org.apache.ignite.internal.storage.rocksdb.RocksDbStorageUtils.PARTITION_ID_SIZE; import static org.apache.ignite.internal.storage.rocksdb.RocksDbStorageUtils.ROW_ID_SIZE; -import static org.apache.ignite.internal.storage.rocksdb.RocksDbStorageUtils.TABLE_ID_SIZE; import static org.apache.ignite.internal.storage.util.StorageUtils.throwExceptionIfStorageInProgressOfRebalance; import static org.apache.ignite.internal.util.ArrayUtils.BYTE_EMPTY_ARRAY; @@ -204,7 +204,7 @@ public class RocksDbSortedIndexStorage extends AbstractRocksDbIndexStorage imple } private IndexRow decodeRow(ByteBuffer bytes) { - assert bytes.getShort(TABLE_ID_SIZE) == partitionId; + assert bytes.getShort(PREFIX_WITH_IDS_LENGTH - PARTITION_ID_SIZE) == partitionId; var tuple = new BinaryTuple(descriptor.binaryTupleSchema().elementCount(), binaryTupleSlice(bytes));