Search in sources :

Example 1 with INITIAL_SCHEMA_VERSION

use of org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION in project ignite-3 by apache.

the class TupleMarshallerVarlenOnlyBenchmark method init.

/**
 * Setup.
 */
@Setup
public void init() {
    final long seed = System.currentTimeMillis();
    final boolean useString = "string".equals(type);
    rnd = new Random(seed);
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", INT64, false, (Supplier<Object> & Serializable) () -> 0L) }, IntStream.range(0, fieldsCount).boxed().map(i -> new Column("col" + i, useString ? STRING : BYTES, nullable)).toArray(Column[]::new));
    marshaller = new TupleMarshallerImpl(new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION) {

        @Override
        public SchemaDescriptor schema() {
            return schema;
        }

        @Override
        public SchemaDescriptor schema(int ver) {
            return schema;
        }

        @Override
        public int lastSchemaVersion() {
            return schema.version();
        }
    });
    if (useString) {
        final byte[] data = new byte[dataSize / fieldsCount];
        for (int i = 0; i < data.length; i++) {
            data[i] = (byte) (rnd.nextInt() & 0x7F);
        }
        // Latin1 string.
        val = new String(data, StandardCharsets.ISO_8859_1);
    } else {
        rnd.nextBytes((byte[]) (val = new byte[dataSize / fieldsCount]));
    }
}
Also used : IntStream(java.util.stream.IntStream) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) Blackhole(org.openjdk.jmh.infra.Blackhole) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Random(java.util.Random) Scope(org.openjdk.jmh.annotations.Scope) Supplier(java.util.function.Supplier) Warmup(org.openjdk.jmh.annotations.Warmup) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) Row(org.apache.ignite.internal.schema.row.Row) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Runner(org.openjdk.jmh.runner.Runner) RunnerException(org.openjdk.jmh.runner.RunnerException) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Setup(org.openjdk.jmh.annotations.Setup) Columns(org.apache.ignite.internal.schema.Columns) Mode(org.openjdk.jmh.annotations.Mode) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerException(org.apache.ignite.internal.schema.marshaller.TupleMarshallerException) Param(org.openjdk.jmh.annotations.Param) State(org.openjdk.jmh.annotations.State) StandardCharsets(java.nio.charset.StandardCharsets) Benchmark(org.openjdk.jmh.annotations.Benchmark) Serializable(java.io.Serializable) TimeUnit(java.util.concurrent.TimeUnit) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) Column(org.apache.ignite.internal.schema.Column) Fork(org.openjdk.jmh.annotations.Fork) Tuple(org.apache.ignite.table.Tuple) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Serializable(java.io.Serializable) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Random(java.util.Random) Column(org.apache.ignite.internal.schema.Column) Supplier(java.util.function.Supplier) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with INITIAL_SCHEMA_VERSION

use of org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION in project ignite-3 by apache.

the class TupleMarshallerFixlenOnlyBenchmark method init.

/**
 * Setup.
 */
@Setup
public void init() {
    long seed = System.currentTimeMillis();
    rnd = new Random(seed);
    schema = new SchemaDescriptor(42, new Column[] { new Column("key", NativeTypes.INT64, false) }, IntStream.range(0, fieldsCount).boxed().map(i -> new Column("col" + i, NativeTypes.INT64, nullable)).toArray(Column[]::new));
    marshaller = new TupleMarshallerImpl(new SchemaRegistryImpl(v -> null, () -> INITIAL_SCHEMA_VERSION) {

        @Override
        public SchemaDescriptor schema() {
            return schema;
        }

        @Override
        public SchemaDescriptor schema(int ver) {
            return schema;
        }

        @Override
        public int lastSchemaVersion() {
            return schema.version();
        }
    });
    vals = new Object[schema.valueColumns().length()];
    for (int i = 0; i < vals.length; i++) {
        vals[i] = rnd.nextLong();
    }
}
Also used : IntStream(java.util.stream.IntStream) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) Blackhole(org.openjdk.jmh.infra.Blackhole) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Random(java.util.Random) Scope(org.openjdk.jmh.annotations.Scope) Warmup(org.openjdk.jmh.annotations.Warmup) Row(org.apache.ignite.internal.schema.row.Row) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Runner(org.openjdk.jmh.runner.Runner) RunnerException(org.openjdk.jmh.runner.RunnerException) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Setup(org.openjdk.jmh.annotations.Setup) Columns(org.apache.ignite.internal.schema.Columns) Mode(org.openjdk.jmh.annotations.Mode) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) TupleMarshallerException(org.apache.ignite.internal.schema.marshaller.TupleMarshallerException) Param(org.openjdk.jmh.annotations.Param) State(org.openjdk.jmh.annotations.State) Benchmark(org.openjdk.jmh.annotations.Benchmark) TimeUnit(java.util.concurrent.TimeUnit) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) Fork(org.openjdk.jmh.annotations.Fork) Tuple(org.apache.ignite.table.Tuple) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Random(java.util.Random) Column(org.apache.ignite.internal.schema.Column) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with INITIAL_SCHEMA_VERSION

use of org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION in project ignite-3 by apache.

the class StopCalciteModuleTest method before.

/**
 * Before.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@BeforeEach
public void before(TestInfo testInfo) {
    when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
    when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
    when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
    ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
    when(topologySrvc.localMember()).thenReturn(node);
    when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
    SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
    schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
    when(tbl.name()).thenReturn("PUBLIC.TEST");
    // Mock create table (notify on register listener).
    doAnswer(invocation -> {
        EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
        clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
        return null;
    }).when(tableManager).listen(eq(TableEvent.CREATE), any());
    RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
    asm.appendInt(0);
    asm.appendInt(0);
    BinaryRow binaryRow = asm.build();
    // Mock table scan
    doAnswer(invocation -> {
        int part = (int) invocation.getArguments()[0];
        return (Flow.Publisher<BinaryRow>) s -> {
            s.onSubscribe(new Flow.Subscription() {

                @Override
                public void request(long n) {
                }

                @Override
                public void cancel() {
                }
            });
            if (part == 0) {
                for (int i = 0; i < ROWS; ++i) {
                    s.onNext(binaryRow);
                }
            }
            s.onComplete();
        };
    }).when(tbl).scan(anyInt(), any());
    LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
Also used : ClusterNode(org.apache.ignite.network.ClusterNode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ThreadInfo(java.lang.management.ThreadInfo) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TableImpl(org.apache.ignite.internal.table.TableImpl) Flow(java.util.concurrent.Flow) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ManagementFactory(java.lang.management.ManagementFactory) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) MessagingService(org.apache.ignite.network.MessagingService) TableManager(org.apache.ignite.internal.table.distributed.TableManager) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Mockito.when(org.mockito.Mockito.when) ThreadMXBean(java.lang.management.ThreadMXBean) UUID(java.util.UUID) TestInfo(org.junit.jupiter.api.TestInfo) ClusterNode(org.apache.ignite.network.ClusterNode) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) Column(org.apache.ignite.internal.schema.Column) TableEvent(org.apache.ignite.internal.table.event.TableEvent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClusterService(org.apache.ignite.network.ClusterService) EventListener(org.apache.ignite.internal.manager.EventListener) Collections(java.util.Collections) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableImpl(org.apache.ignite.internal.table.TableImpl) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) Flow(java.util.concurrent.Flow) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Column(org.apache.ignite.internal.schema.Column) EventListener(org.apache.ignite.internal.manager.EventListener) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with INITIAL_SCHEMA_VERSION

use of org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION in project ignite-3 by apache.

the class UpgradingRowAdapterTest method testVariousColumnTypes.

@Test
public void testVariousColumnTypes() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
    SchemaDescriptor schema2 = new SchemaDescriptor(2, new Column[] { new Column("keyUuidCol", NativeTypes.UUID, false) }, new Column[] { new Column("added", INT8, true), new Column("valByteCol", INT8, true), new Column("valShortCol", INT16, true), new Column("valIntCol", INT32, true), new Column("valLongCol", INT64, true), new Column("valFloatCol", FLOAT, true), new Column("valDoubleCol", DOUBLE, true), new Column("valDateCol", DATE, true), new Column("valTimeCol", time(), true), new Column("valDateTimeCol", datetime(), true), new Column("valTimeStampCol", timestamp(), true), new Column("valBitmask1Col", NativeTypes.bitmaskOf(22), true), new Column("valBytesCol", BYTES, false), new Column("valStringCol", STRING, false), new Column("valNumberCol", NativeTypes.numberOf(20), false), new Column("valDecimalCol", NativeTypes.decimalOf(25, 5), false) });
    int addedColumnIndex = schema2.column("added").schemaIndex();
    schema2.columnMapping(new ColumnMapper() {

        @Override
        public ColumnMapper add(@NotNull Column col) {
            return null;
        }

        @Override
        public ColumnMapper add(int from, int to) {
            return null;
        }

        @Override
        public int map(int idx) {
            return idx < addedColumnIndex ? idx : idx == addedColumnIndex ? -1 : idx - 1;
        }

        @Override
        public Column mappedColumn(int idx) {
            return idx == addedColumnIndex ? schema2.column(idx) : null;
        }
    });
    List<Object> values = generateRowValues(schema);
    ByteBufferRow row = new ByteBufferRow(serializeValuesToRow(schema, values));
    // Validate row.
    validateRow(values, new SchemaRegistryImpl(1, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
    // Validate upgraded row.
    values.add(addedColumnIndex, null);
    validateRow(values, new SchemaRegistryImpl(2, v -> v == 1 ? schema : schema2, () -> INITIAL_SCHEMA_VERSION), row);
}
Also used : DATE(org.apache.ignite.internal.schema.NativeTypes.DATE) BeforeEach(org.junit.jupiter.api.BeforeEach) LocalDateTime(java.time.LocalDateTime) Random(java.util.Random) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ArrayList(java.util.ArrayList) DOUBLE(org.apache.ignite.internal.schema.NativeTypes.DOUBLE) BigDecimal(java.math.BigDecimal) INT64(org.apache.ignite.internal.schema.NativeTypes.INT64) Row(org.apache.ignite.internal.schema.row.Row) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) INITIAL_SCHEMA_VERSION(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION) INT8(org.apache.ignite.internal.schema.NativeTypes.INT8) LocalTime(java.time.LocalTime) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NativeType(org.apache.ignite.internal.schema.NativeType) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) FLOAT(org.apache.ignite.internal.schema.NativeTypes.FLOAT) NativeTypes.datetime(org.apache.ignite.internal.schema.NativeTypes.datetime) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) NativeTypes.timestamp(org.apache.ignite.internal.schema.NativeTypes.timestamp) SchemaTestUtils(org.apache.ignite.internal.schema.SchemaTestUtils) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Instant(java.time.Instant) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) BYTES(org.apache.ignite.internal.schema.NativeTypes.BYTES) List(java.util.List) NativeTypes(org.apache.ignite.internal.schema.NativeTypes) STRING(org.apache.ignite.internal.schema.NativeTypes.STRING) Column(org.apache.ignite.internal.schema.Column) LocalDate(java.time.LocalDate) NativeTypes.time(org.apache.ignite.internal.schema.NativeTypes.time) INT16(org.apache.ignite.internal.schema.NativeTypes.INT16) BitSet(java.util.BitSet) INT32(org.apache.ignite.internal.schema.NativeTypes.INT32) NotNull(org.jetbrains.annotations.NotNull) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) ColumnMapper(org.apache.ignite.internal.schema.mapping.ColumnMapper) Test(org.junit.jupiter.api.Test)

Aggregations

Column (org.apache.ignite.internal.schema.Column)4 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)4 INITIAL_SCHEMA_VERSION (org.apache.ignite.internal.schema.registry.SchemaRegistryImpl.INITIAL_SCHEMA_VERSION)4 Random (java.util.Random)3 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)3 SchemaRegistryImpl (org.apache.ignite.internal.schema.registry.SchemaRegistryImpl)3 Row (org.apache.ignite.internal.schema.row.Row)3 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 IntStream (java.util.stream.IntStream)2 Columns (org.apache.ignite.internal.schema.Columns)2 BYTES (org.apache.ignite.internal.schema.NativeTypes.BYTES)2 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)2 IgniteLogger (org.apache.ignite.lang.IgniteLogger)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 Serializable (java.io.Serializable)1 ManagementFactory (java.lang.management.ManagementFactory)1 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1