Search in sources :

Example 6 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class IgnitionImpl method doStart.

/**
 * Starts an Ignite node with an optional bootstrap configuration from a HOCON file.
 *
 * @param nodeName   Name of the node. Must not be {@code null}.
 * @param cfgContent Node configuration in the HOCON format. Can be {@code null}.
 * @param workDir    Work directory for the started node. Must not be {@code null}.
 * @return Started Ignite node.
 */
private static Ignite doStart(String nodeName, @Nullable String cfgContent, Path workDir, @Nullable ClassLoader serviceLoaderClassLoader) {
    if (nodeName.isEmpty()) {
        throw new IllegalArgumentException("Node name must not be null or empty.");
    }
    IgniteImpl nodeToStart = new IgniteImpl(nodeName, workDir, serviceLoaderClassLoader);
    IgniteImpl prevNode = nodes.putIfAbsent(nodeName, nodeToStart);
    if (prevNode != null) {
        String errMsg = "Node with name=[" + nodeName + "] already exists.";
        LOG.error(errMsg);
        throw new IgniteException(errMsg);
    }
    ackBanner();
    try {
        nodeToStart.start(cfgContent);
    } catch (Exception e) {
        nodes.remove(nodeName);
        if (e instanceof IgniteException) {
            throw e;
        } else {
            throw new IgniteException(e);
        }
    }
    ackSuccessStart();
    return nodeToStart;
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) IgniteException(org.apache.ignite.lang.IgniteException) IOException(java.io.IOException)

Example 7 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class ItFunctionsTest method testRange.

@Test
public void testRange() {
    assertQuery("SELECT * FROM table(system_range(1, 4))").returns(1L).returns(2L).returns(3L).returns(4L).check();
    assertQuery("SELECT * FROM table(system_range(1, 4, 2))").returns(1L).returns(3L).check();
    assertQuery("SELECT * FROM table(system_range(4, 1, -1))").returns(4L).returns(3L).returns(2L).returns(1L).check();
    assertQuery("SELECT * FROM table(system_range(4, 1, -2))").returns(4L).returns(2L).check();
    assertEquals(0, sql("SELECT * FROM table(system_range(4, 1))").size());
    assertEquals(0, sql("SELECT * FROM table(system_range(null, 1))").size());
    IgniteException ex = assertThrows(IgniteException.class, () -> sql("SELECT * FROM table(system_range(1, 1, 0))"), "Increment can't be 0");
    assertTrue(ex.getCause() instanceof IllegalArgumentException, IgniteStringFormatter.format("Expected cause is {}, but was {}", IllegalArgumentException.class.getSimpleName(), ex.getCause() == null ? null : ex.getCause().getClass().getSimpleName()));
    assertEquals("Increment can't be 0", ex.getCause().getMessage());
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) Test(org.junit.jupiter.api.Test)

Example 8 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class Commons method compile.

/**
 * Compile.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
public static <T> T compile(Class<T> interfaceType, String body) {
    final boolean debug = CalciteSystemProperty.DEBUG.value();
    if (debug) {
        Util.debugCode(System.out, body);
    }
    try {
        final ICompilerFactory compilerFactory;
        try {
            compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
        } catch (Exception e) {
            throw new IllegalStateException("Unable to instantiate java compiler", e);
        }
        IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator();
        cbe.setImplementedInterfaces(new Class[] { interfaceType });
        cbe.setParentClassLoader(ExpressionFactoryImpl.class.getClassLoader());
        if (debug) {
            // Add line numbers to the generated janino class
            cbe.setDebuggingInformation(true, true, true);
        }
        return (T) cbe.createInstance(new StringReader(body));
    } catch (Exception e) {
        throw new IgniteException(e);
    }
}
Also used : ICompilerFactory(org.codehaus.commons.compiler.ICompilerFactory) ExpressionFactoryImpl(org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactoryImpl) IgniteException(org.apache.ignite.lang.IgniteException) SourceStringReader(org.apache.calcite.util.SourceStringReader) StringReader(java.io.StringReader) IClassBodyEvaluator(org.codehaus.commons.compiler.IClassBodyEvaluator) IgniteException(org.apache.ignite.lang.IgniteException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) SqlParseException(org.apache.calcite.sql.parser.SqlParseException)

Example 9 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal records.
 *
 * @param rows Row collection.
 * @return Records collection.
 */
@NotNull
public Collection<R> unmarshal(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyList();
    }
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<R> recs = new ArrayList<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                recs.add(marsh.unmarshal(row));
            }
        }
        return recs;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with IgniteException

use of org.apache.ignite.lang.IgniteException in project ignite-3 by apache.

the class TableManager method createTableLocally.

/**
 * Creates local structures for a table.
 *
 * @param causalityToken Causality token.
 * @param name  Table name.
 * @param tblId Table id.
 * @param assignment Affinity assignment.
 */
private void createTableLocally(long causalityToken, String name, UUID tblId, List<List<ClusterNode>> assignment, SchemaDescriptor schemaDesc) {
    int partitions = assignment.size();
    var partitionsGroupsFutures = new ArrayList<CompletableFuture<RaftGroupService>>();
    Path storageDir = partitionsStoreDir.resolve(name);
    try {
        Files.createDirectories(storageDir);
    } catch (IOException e) {
        throw new IgniteInternalException("Failed to create partitions store directory for " + name + ": " + e.getMessage(), e);
    }
    TableConfiguration tableCfg = tablesCfg.tables().get(name);
    DataRegion dataRegion = dataRegions.computeIfAbsent(tableCfg.dataRegion().value(), dataRegionName -> {
        DataRegion newDataRegion = engine.createDataRegion(dataStorageCfg.regions().get(dataRegionName));
        try {
            newDataRegion.start();
        } catch (Exception e) {
            try {
                newDataRegion.stop();
            } catch (Exception stopException) {
                e.addSuppressed(stopException);
            }
            throw e;
        }
        return newDataRegion;
    });
    TableStorage tableStorage = engine.createTable(storageDir, tableCfg, dataRegion);
    tableStorage.start();
    for (int p = 0; p < partitions; p++) {
        int partId = p;
        try {
            partitionsGroupsFutures.add(raftMgr.prepareRaftGroup(raftGroupName(tblId, p), assignment.get(p), () -> new PartitionListener(tblId, new VersionedRowStore(tableStorage.getOrCreatePartition(partId), txManager))));
        } catch (NodeStoppingException e) {
            throw new AssertionError("Loza was stopped before Table manager", e);
        }
    }
    CompletableFuture.allOf(partitionsGroupsFutures.toArray(CompletableFuture[]::new)).thenRun(() -> {
        try {
            Int2ObjectOpenHashMap<RaftGroupService> partitionMap = new Int2ObjectOpenHashMap<>(partitions);
            for (int p = 0; p < partitions; p++) {
                CompletableFuture<RaftGroupService> future = partitionsGroupsFutures.get(p);
                assert future.isDone();
                RaftGroupService service = future.join();
                partitionMap.put(p, service);
            }
            InternalTableImpl internalTable = new InternalTableImpl(name, tblId, partitionMap, partitions, netAddrResolver, txManager, tableStorage);
            var schemaRegistry = new SchemaRegistryImpl(v -> {
                if (!busyLock.enterBusy()) {
                    throw new IgniteException(new NodeStoppingException());
                }
                try {
                    return tableSchema(tblId, v);
                } finally {
                    busyLock.leaveBusy();
                }
            }, () -> {
                if (!busyLock.enterBusy()) {
                    throw new IgniteException(new NodeStoppingException());
                }
                try {
                    return latestSchemaVersion(tblId);
                } finally {
                    busyLock.leaveBusy();
                }
            });
            schemaRegistry.onSchemaRegistered(schemaDesc);
            var table = new TableImpl(internalTable, schemaRegistry);
            tablesVv.update(causalityToken, previous -> {
                var val = previous == null ? new HashMap() : new HashMap<>(previous);
                val.put(name, table);
                return val;
            }, th -> {
                throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
            });
            tablesByIdVv.update(causalityToken, previous -> {
                var val = previous == null ? new HashMap() : new HashMap<>(previous);
                val.put(tblId, table);
                return val;
            }, th -> {
                throw new IgniteInternalException(IgniteStringFormatter.format("Cannot create a table [name={}, id={}]", name, tblId), th);
            });
            completeApiCreateFuture(table);
            fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, table), null);
        } catch (Exception e) {
            fireEvent(TableEvent.CREATE, new TableEventParameters(causalityToken, tblId, name), e);
        }
    }).join();
}
Also used : TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) IgniteTablesInternal(org.apache.ignite.internal.table.IgniteTablesInternal) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) ConfigurationUtil.directProxy(org.apache.ignite.internal.configuration.util.ConfigurationUtil.directProxy) ConfigurationUtil.getByInternalId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.getByInternalId) ExtendedTableChange(org.apache.ignite.internal.configuration.schema.ExtendedTableChange) IgniteLogger(org.apache.ignite.lang.IgniteLogger) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) Map(java.util.Map) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) Path(java.nio.file.Path) SchemaUtils(org.apache.ignite.internal.schema.SchemaUtils) ExtendedTableView(org.apache.ignite.internal.configuration.schema.ExtendedTableView) IgniteComponent(org.apache.ignite.internal.manager.IgniteComponent) SchemaConfiguration(org.apache.ignite.internal.configuration.schema.SchemaConfiguration) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DEFAULT_DATA_REGION_NAME(org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema.DEFAULT_DATA_REGION_NAME) CompletionException(java.util.concurrent.CompletionException) Producer(org.apache.ignite.internal.manager.Producer) StorageEngine(org.apache.ignite.internal.storage.engine.StorageEngine) UUID(java.util.UUID) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) Collectors(java.util.stream.Collectors) TxManager(org.apache.ignite.internal.tx.TxManager) TableView(org.apache.ignite.configuration.schemas.table.TableView) ClusterNode(org.apache.ignite.network.ClusterNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteStringFormatter(org.apache.ignite.lang.IgniteStringFormatter) NotNull(org.jetbrains.annotations.NotNull) InternalTable(org.apache.ignite.internal.table.InternalTable) IgniteException(org.apache.ignite.lang.IgniteException) Loza(org.apache.ignite.internal.raft.Loza) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) ByteUtils(org.apache.ignite.internal.util.ByteUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SchemaSerializerImpl(org.apache.ignite.internal.schema.marshaller.schema.SchemaSerializerImpl) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SchemaView(org.apache.ignite.internal.configuration.schema.SchemaView) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TableImpl(org.apache.ignite.internal.table.TableImpl) IgniteSpinBusyLock(org.apache.ignite.internal.util.IgniteSpinBusyLock) IgniteTables(org.apache.ignite.table.manager.IgniteTables) NoSuchElementException(java.util.NoSuchElementException) VersionedValue(org.apache.ignite.internal.causality.VersionedValue) TopologyService(org.apache.ignite.network.TopologyService) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) Files(java.nio.file.Files) NamedListView(org.apache.ignite.configuration.NamedListView) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteObjectName(org.apache.ignite.internal.util.IgniteObjectName) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) BaselineManager(org.apache.ignite.internal.baseline.BaselineManager) TableStorage(org.apache.ignite.internal.storage.engine.TableStorage) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) NetworkAddress(org.apache.ignite.network.NetworkAddress) Consumer(java.util.function.Consumer) ConfigurationNotificationEvent(org.apache.ignite.configuration.notifications.ConfigurationNotificationEvent) TableEvent(org.apache.ignite.internal.table.event.TableEvent) AffinityUtils(org.apache.ignite.internal.affinity.AffinityUtils) EventListener(org.apache.ignite.internal.manager.EventListener) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) Table(org.apache.ignite.table.Table) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) RocksDbStorageEngine(org.apache.ignite.internal.storage.rocksdb.RocksDbStorageEngine) TableChange(org.apache.ignite.configuration.schemas.table.TableChange) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteException(org.apache.ignite.lang.IgniteException) ExtendedTableConfiguration(org.apache.ignite.internal.configuration.schema.ExtendedTableConfiguration) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) Path(java.nio.file.Path) VersionedRowStore(org.apache.ignite.internal.table.distributed.storage.VersionedRowStore) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) RaftGroupService(org.apache.ignite.raft.client.service.RaftGroupService) IOException(java.io.IOException) SchemaRegistryImpl(org.apache.ignite.internal.schema.registry.SchemaRegistryImpl) TableAlreadyExistsException(org.apache.ignite.lang.TableAlreadyExistsException) TableNotFoundException(org.apache.ignite.lang.TableNotFoundException) CompletionException(java.util.concurrent.CompletionException) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NoSuchElementException(java.util.NoSuchElementException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IOException(java.io.IOException) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) PartitionListener(org.apache.ignite.internal.table.distributed.raft.PartitionListener) TableEventParameters(org.apache.ignite.internal.table.event.TableEventParameters) InternalTableImpl(org.apache.ignite.internal.table.distributed.storage.InternalTableImpl) DataRegion(org.apache.ignite.internal.storage.engine.DataRegion)

Aggregations

IgniteException (org.apache.ignite.lang.IgniteException)39 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)10 NotNull (org.jetbrains.annotations.NotNull)10 Map (java.util.Map)9 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 HashMap (java.util.HashMap)7 List (java.util.List)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)7 HashSet (java.util.HashSet)6 CompletionException (java.util.concurrent.CompletionException)6 Row (org.apache.ignite.internal.schema.row.Row)6 NoSuchElementException (java.util.NoSuchElementException)5 Set (java.util.Set)5 UUID (java.util.UUID)5 Consumer (java.util.function.Consumer)5 Collectors (java.util.stream.Collectors)5