Search in sources :

Example 11 with IgniteInternalException

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);
    });
}
Also used : NetworkAddress(org.apache.ignite.network.NetworkAddress) ActionRequest(org.apache.ignite.raft.jraft.rpc.ActionRequest) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ArgumentMatcher(org.mockito.ArgumentMatcher) ConnectException(java.net.ConnectException)

Example 12 with IgniteInternalException

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);
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 13 with IgniteInternalException

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);
    }
}
Also used : VarHandle(java.lang.invoke.VarHandle) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ConcurrentModificationException(java.util.ConcurrentModificationException)

Example 14 with IgniteInternalException

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;
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) DirectMemoryRegion(org.apache.ignite.internal.pagememory.mem.DirectMemoryRegion)

Example 15 with IgniteInternalException

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

IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)58 RocksDBException (org.rocksdb.RocksDBException)19 IOException (java.io.IOException)11 Path (java.nio.file.Path)10 ArrayList (java.util.ArrayList)10 NotNull (org.jetbrains.annotations.NotNull)10 WriteBatch (org.rocksdb.WriteBatch)9 List (java.util.List)7 Entry (org.apache.ignite.internal.metastorage.server.Entry)7 NoSuchElementException (java.util.NoSuchElementException)6 NetworkAddress (org.apache.ignite.network.NetworkAddress)6 Test (org.junit.jupiter.api.Test)6 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)5 Nullable (org.jetbrains.annotations.Nullable)5 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)4 ReadOptions (org.rocksdb.ReadOptions)4 RocksIterator (org.rocksdb.RocksIterator)4 CompletableFuture (java.util.concurrent.CompletableFuture)3