Search in sources :

Example 21 with IgniteException

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

the class IgnitionManager method start.

/**
 * 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 configStr Optional node configuration based on {@link org.apache.ignite.configuration.schemas.runner.NodeConfigurationSchema}
 *                  and {@link org.apache.ignite.configuration.schemas.network.NetworkConfigurationSchema}. Following rules are used for
 *                  applying the configuration properties:
 *                  <ol>
 *                      <li>Specified property overrides existing one or just applies itself if it wasn't
 *                          previously specified.</li>
 *                      <li>All non-specified properties either use previous value or use default one from
 *                          corresponding configuration schema.</li>
 *                  </ol>
 *                  So that, in case of initial node start (first start ever) specified configuration, supplemented
 *                  with defaults, is used. If no configuration was provided defaults are used for all
 *                  configuration properties. In case of node restart, specified properties override existing
 *                  ones, non specified properties that also weren't specified previously use default values.
 *                  Please pay attention that previously specified properties are searched in the
 *                  {@code workDir} specified by the user.
 * @param workDir   Work directory for the started node. Must not be {@code null}.
 * @return Started Ignite node.
 * @throws IgniteException If error occurs while reading node configuration.
 */
// TODO IGNITE-14580 Add exception handling logic to IgnitionProcessor.
public static Ignite start(@NotNull String nodeName, @Nullable String configStr, @NotNull Path workDir) {
    synchronized (IgnitionManager.class) {
        if (ignition == null) {
            ServiceLoader<Ignition> ldr = ServiceLoader.load(Ignition.class);
            ignition = ldr.iterator().next();
        }
    }
    if (configStr == null) {
        return ignition.start(nodeName, workDir);
    } else {
        try (InputStream inputStream = new ByteArrayInputStream(configStr.getBytes(StandardCharsets.UTF_8))) {
            return ignition.start(nodeName, inputStream, workDir);
        } catch (IOException e) {
            throw new IgniteException("Couldn't close the stream with node config.", e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IgniteException(org.apache.ignite.lang.IgniteException) IOException(java.io.IOException)

Example 22 with IgniteException

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

the class ItDmlTest method testMergeKeysConflict.

/**
 * Test MERGE operator with keys conflicts.
 */
@Test
public void testMergeKeysConflict() {
    sql("DROP TABLE IF EXISTS test1 ");
    sql("DROP TABLE IF EXISTS test2 ");
    sql("CREATE TABLE test1 (k int PRIMARY KEY, a int, b int)");
    sql("INSERT INTO test1 VALUES (0, 0, 0)");
    sql("INSERT INTO test1 VALUES (1, 1, 1)");
    sql("INSERT INTO test1 VALUES (2, 2, 2)");
    sql("CREATE TABLE test2 (k int PRIMARY KEY, a int, b int)");
    IgniteException ex = assertThrows(IgniteException.class, () -> sql("MERGE INTO test2 USING test1 ON test1.a = test2.a " + "WHEN MATCHED THEN UPDATE SET b = test1.b + 1 " + "WHEN NOT MATCHED THEN INSERT (k, a, b) VALUES (0, a, b)"));
    assertTrue(ex.getCause().getMessage().contains("Failed to MERGE some keys due to keys conflict"));
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) Test(org.junit.jupiter.api.Test)

Example 23 with IgniteException

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

the class RecordViewImpl method marshalKeys.

/**
 * Marshal key-records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshalKeys(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshalKey(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } 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)

Example 24 with IgniteException

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

the class RecordViewImpl method marshal.

/**
 * Marshal records.
 *
 * @param recs Records collection.
 * @return Binary rows collection.
 */
private Collection<BinaryRow> marshal(@NotNull Collection<R> recs) {
    final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(recs.size());
    try {
        for (R rec : recs) {
            final BinaryRow row = marsh.marshal(Objects.requireNonNull(rec));
            rows.add(row);
        }
        return rows;
    } 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)

Example 25 with IgniteException

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

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal value object from given binary row.
 *
 * @param binaryRow Binary row.
 * @return Value object.
 */
private R unmarshal(BinaryRow binaryRow) {
    if (binaryRow == null || !binaryRow.hasValue()) {
        return null;
    }
    Row row = schemaReg.resolve(binaryRow);
    RecordMarshaller<R> marshaller = marshaller(row.schemaVersion());
    try {
        return marshaller.unmarshal(row);
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

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