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