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