Search in sources :

Example 26 with IgniteInternalException

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

the class RocksDbKeyValueStorage method getAndRemoveAll.

/**
 * {@inheritDoc}
 */
@NotNull
@Override
public Collection<Entry> getAndRemoveAll(List<byte[]> keys) {
    Collection<Entry> res = new ArrayList<>(keys.size());
    rwLock.writeLock().lock();
    try (WriteBatch batch = new WriteBatch()) {
        long curRev = rev + 1;
        List<byte[]> existingKeys = new ArrayList<>(keys.size());
        List<byte[]> vals = new ArrayList<>(keys.size());
        for (byte[] key : keys) {
            Entry e = doGet(key, LATEST_REV, false);
            res.add(e);
            if (e.empty() || e.tombstone()) {
                continue;
            }
            existingKeys.add(key);
            vals.add(TOMBSTONE);
        }
        long counter = addAllToBatch(batch, existingKeys, vals, curRev);
        for (byte[] key : existingKeys) {
            updateKeysIndex(batch, key, curRev);
        }
        fillAndWriteBatch(batch, curRev, counter);
    } catch (RocksDBException e) {
        throw new IgniteInternalException(e);
    } finally {
        rwLock.writeLock().unlock();
    }
    return res;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Entry(org.apache.ignite.internal.metastorage.server.Entry) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ArrayList(java.util.ArrayList) WriteBatch(org.rocksdb.WriteBatch) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with IgniteInternalException

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

the class WatchCursor method hasNext.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasNext() {
    storage.lock().readLock().lock();
    try {
        if (currentHasNext) {
            return true;
        }
        if (!nativeIterator.isValid()) {
            nativeIterator.refresh();
            nativeIterator.seek(longToBytes(currentRevision));
        }
        // Check all keys to see if any one of them match the predicate.
        currentHasNext = RocksUtils.find(nativeIterator, (rocksKey, value) -> {
            byte[] key = rocksKeyToBytes(rocksKey);
            if (predicate.test(key)) {
                // We may have jumped to the next revision if there were no matching keys in previous.
                currentRevision = revisionFromRocksKey(rocksKey);
                return true;
            }
            return false;
        });
        return currentHasNext;
    } catch (RocksDBException e) {
        throw new IgniteInternalException(e);
    } finally {
        storage.lock().readLock().unlock();
    }
}
Also used : Value(org.apache.ignite.internal.metastorage.server.Value) ReadOptions(org.rocksdb.ReadOptions) RocksUtils.checkIterator(org.apache.ignite.internal.rocksdb.RocksUtils.checkIterator) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) EntryEvent(org.apache.ignite.internal.metastorage.server.EntryEvent) RocksStorageUtils.rocksKeyToBytes(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.rocksKeyToBytes) Cursor(org.apache.ignite.internal.util.Cursor) RocksStorageUtils.revisionFromRocksKey(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.revisionFromRocksKey) RocksIterator(org.rocksdb.RocksIterator) ArrayList(java.util.ArrayList) List(java.util.List) RocksStorageUtils.longToBytes(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.longToBytes) WatchEvent(org.apache.ignite.internal.metastorage.server.WatchEvent) Entry(org.apache.ignite.internal.metastorage.server.Entry) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) RocksDBException(org.rocksdb.RocksDBException) NoSuchElementException(java.util.NoSuchElementException) RocksUtils(org.apache.ignite.internal.rocksdb.RocksUtils) RocksStorageUtils.bytesToValue(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.bytesToValue) RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Example 28 with IgniteInternalException

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

the class ConnectionManager method start.

/**
 * Starts the server.
 *
 * @throws IgniteInternalException If failed to start.
 */
public void start() throws IgniteInternalException {
    try {
        boolean wasStarted = started.getAndSet(true);
        if (wasStarted) {
            throw new IgniteInternalException("Attempted to start an already started connection manager");
        }
        if (stopped.get()) {
            throw new IgniteInternalException("Attempted to start an already stopped connection manager");
        }
        server.start().get();
        LOG.info("Connection created [address=" + server.address() + ']');
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        throw new IgniteInternalException("Failed to start the connection manager: " + cause.getMessage(), cause);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IgniteInternalException("Interrupted while starting the connection manager", e);
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ExecutionException(java.util.concurrent.ExecutionException)

Example 29 with IgniteInternalException

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

the class RaftGroupService method start.

/**
 * Starts the raft group service, returns the raft node.
 */
public synchronized Node start() {
    if (this.started) {
        return this.node;
    }
    if (this.serverId == null || this.serverId.getEndpoint() == null || this.serverId.getEndpoint().equals(new Endpoint(Utils.IP_ANY, 0))) {
        throw new IllegalArgumentException("Blank serverId:" + this.serverId);
    }
    if (StringUtils.isBlank(this.groupId)) {
        throw new IllegalArgumentException("Blank group id" + this.groupId);
    }
    assert this.nodeOptions.getRpcClient() != null;
    this.node = new NodeImpl(groupId, serverId);
    if (!this.node.init(this.nodeOptions)) {
        LOG.warn("Stopping partially started node [groupId={}, serverId={}]", groupId, serverId);
        this.node.shutdown();
        try {
            this.node.join();
        } catch (InterruptedException e) {
            throw new IgniteInternalException(e);
        }
        throw new IgniteInternalException("Fail to init node, please see the logs to find the reason.");
    }
    this.nodeManager.add(this.node);
    this.started = true;
    LOG.info("Start the RaftGroupService successfully {}", this.node.getNodeId());
    return this.node;
}
Also used : Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) NodeImpl(org.apache.ignite.raft.jraft.core.NodeImpl) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Example 30 with IgniteInternalException

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

the class IgniteTestUtils method setFieldValue.

/**
 * Set object field value via reflection.
 *
 * @param obj       Object to set field value to.
 * @param fieldName Field name to set value for.
 * @param val       New field value.
 * @throws IgniteInternalException In case of error.
 */
public static void setFieldValue(Object obj, String fieldName, Object val) throws IgniteInternalException {
    assert obj != null;
    assert fieldName != null;
    try {
        Class<?> cls = obj instanceof Class ? (Class) obj : obj.getClass();
        Field field = cls.getDeclaredField(fieldName);
        boolean isFinal = (field.getModifiers() & Modifier.FINAL) != 0;
        boolean isStatic = (field.getModifiers() & Modifier.STATIC) != 0;
        /*
             * http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.5.3
             * If a final field is initialized to a compile-time constant in the field declaration,
             *   changes to the final field may not be observed.
             */
        if (isFinal && isStatic) {
            throw new IgniteInternalException("Modification of static final field through reflection.");
        }
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
        field.set(obj, val);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new IgniteInternalException("Failed to set object field [obj=" + obj + ", field=" + fieldName + ']', e);
    }
}
Also used : Field(java.lang.reflect.Field) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

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