use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RaftGroupServiceTest method mockUserInput.
/**
* @param delay {@code True} to create a delay before response.
* @param peer Fail the request targeted to given peer.
*/
private void mockUserInput(boolean delay, @Nullable Peer peer) {
when(messagingService.invoke(any(NetworkAddress.class), argThat(new ArgumentMatcher<ActionRequest>() {
@Override
public boolean matches(ActionRequest arg) {
return arg.command() instanceof TestCommand;
}
}), anyLong())).then(invocation -> {
NetworkAddress target = invocation.getArgument(0);
if (peer != null && target.equals(peer.address()))
return failedFuture(new IgniteInternalException(new ConnectException()));
if (delay) {
return CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
fail();
}
return FACTORY.actionResponse().result(new TestResponse()).build();
});
}
Object resp;
if (leader == null)
resp = FACTORY.errorResponse().errorCode(RaftError.EPERM.getNumber()).build();
else if (!target.equals(leader.address()))
resp = FACTORY.errorResponse().errorCode(RaftError.EPERM.getNumber()).leaderId(PeerId.fromPeer(leader).toString()).build();
else
resp = FACTORY.actionResponse().result(new TestResponse()).build();
return completedFuture(resp);
});
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class SqlSchemaManagerTest method testNonExistingTable.
@Test
public void testNonExistingTable() throws NodeStoppingException {
UUID tblId = UUID.randomUUID();
IgniteInternalException ex = assertThrows(IgniteInternalException.class, () -> schemaManager.tableById(tblId, tableVer));
assertThat(ex.getMessage(), containsString("Table not found"));
Mockito.verify(tableManager).table(eq(tblId));
Mockito.verifyNoMoreInteractions(tableManager);
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class IgniteToStringBuilder method toStringImpl0.
/**
* Creates an uniformed string presentation for the given object.
*
* @param cls Class of the object.
* @param buf String builder buffer.
* @param obj Object for which to get string presentation.
* @param addNames Names of additional values to be included.
* @param addVals Additional values to be included.
* @param addSens Sensitive flag of values or {@code null} if all values are not sensitive.
* @param addLen How many additional values will be included.
* @param <T> Type of object.
* @return String presentation of the given object.
*/
private static <T> String toStringImpl0(Class<T> cls, StringBuilderLimitedLength buf, T obj, Object[] addNames, Object[] addVals, @Nullable boolean[] addSens, int addLen) {
try {
ClassDescriptor cd = getClassDescriptor(cls);
assert cd != null;
buf.app(cd.getSimpleClassName());
EntryReference ref = savedObjects.get().get(obj);
if (ref != null && ref.hashNeeded) {
buf.app(identity(obj));
ref.hashNeeded = false;
}
buf.app(" [");
boolean first = true;
for (FieldDescriptor fd : cd.getFields()) {
if (!first) {
buf.app(", ");
} else {
first = false;
}
buf.app(fd.getName()).app('=');
final VarHandle fH = fd.varHandle();
switch(fd.type()) {
case FieldDescriptor.FIELD_TYPE_OBJECT:
try {
toString(buf, fd.fieldClass(), fH.get(obj));
} catch (RuntimeException e) {
if (IGNORE_RUNTIME_EXCEPTION) {
buf.app("Runtime exception was caught when building string representation: " + e.getMessage());
} else {
throw e;
}
}
break;
case FieldDescriptor.FIELD_TYPE_BYTE:
buf.app((byte) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_BOOLEAN:
buf.app((boolean) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_CHAR:
buf.app((char) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_SHORT:
buf.app((short) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_INT:
buf.app((int) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_FLOAT:
buf.app((float) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_LONG:
buf.app((long) fH.get(obj));
break;
case FieldDescriptor.FIELD_TYPE_DOUBLE:
buf.app((double) fH.get(obj));
break;
default:
break;
}
}
appendVals(buf, first, addNames, addVals, addSens, addLen);
buf.app(']');
return buf.toString();
} catch (Exception e) {
// Specifically catching all exceptions.
// Remove entry from cache to avoid potential memory leak
// in case new class loader got loaded under the same identity hash.
classCache.remove(cls.getName() + System.identityHashCode(cls.getClassLoader()));
// No other option here.
throw new IgniteInternalException(e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class UnsafeMemoryProvider method nextRegion.
/**
* {@inheritDoc}
*/
@Override
public DirectMemoryRegion nextRegion() {
if (used == sizes.length) {
return null;
}
if (used < regions.size()) {
return regions.get(used++);
}
long chunkSize = sizes[regions.size()];
long ptr;
try {
ptr = allocator.allocateMemory(chunkSize);
} catch (IllegalArgumentException e) {
String msg = "Failed to allocate next memory chunk: " + IgniteUtils.readableSize(chunkSize, true) + ". Check if chunkSize is too large and 32-bit JVM is used.";
if (regions.isEmpty()) {
throw new IgniteInternalException(msg, e);
}
LOG.error(msg);
return null;
}
if (ptr <= 0) {
LOG.error("Failed to allocate next memory chunk: " + IgniteUtils.readableSize(chunkSize, true));
return null;
}
DirectMemoryRegion region = new UnsafeChunk(ptr, chunkSize);
regions.add(region);
used++;
return region;
}
use of org.apache.ignite.lang.IgniteInternalException 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