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);
}
}
}
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"));
}
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);
}
}
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);
}
}
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);
}
}
Aggregations