use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgniteClusterImpl method setBaselineTopology.
/**
* {@inheritDoc}
*/
@Override
public void setBaselineTopology(long topVer) {
guard();
try {
if (isInMemoryMode())
return;
Collection<ClusterNode> top = topology(topVer);
if (top == null)
throw new IgniteException("Topology version does not exist: " + topVer);
Collection<BaselineNode> target = new ArrayList<>(top.size());
for (ClusterNode node : top) {
if (!node.isClient())
target.add(node);
}
validateBeforeBaselineChange(target);
ctx.state().changeGlobalState(true, target, true).get();
} catch (IgniteCheckedException e) {
throw U.convertException(e);
} finally {
unguard();
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class JdbcThinTcpIo method connect.
/**
* Connect to host.
*
* @param addr Address.
* @param timeout Socket connection timeout in ms.
* @throws IOException On IO error.
* @throws SQLException On connection reject.
*/
private void connect(InetSocketAddress addr, int timeout) throws IOException, SQLException {
Socket sock;
if (ConnectionProperties.SSL_MODE_REQUIRE.equalsIgnoreCase(connProps.getSslMode()))
sock = JdbcThinSSLUtil.createSSLSocket(addr, connProps);
else if (ConnectionProperties.SSL_MODE_DISABLE.equalsIgnoreCase(connProps.getSslMode())) {
sock = new Socket();
try {
sock.connect(addr, timeout);
} catch (IOException e) {
throw new SQLException("Failed to connect to server [host=" + addr.getHostName() + ", port=" + addr.getPort() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
}
} else {
throw new SQLException("Unknown sslMode. [sslMode=" + connProps.getSslMode() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED);
}
if (connProps.getSocketSendBuffer() != 0)
sock.setSendBufferSize(connProps.getSocketSendBuffer());
if (connProps.getSocketReceiveBuffer() != 0)
sock.setReceiveBufferSize(connProps.getSocketReceiveBuffer());
sock.setTcpNoDelay(connProps.isTcpNoDelay());
try {
endpoint = new IpcClientTcpEndpoint(sock);
out = new BufferedOutputStream(endpoint.outputStream());
in = new BufferedInputStream(endpoint.inputStream());
} catch (IgniteCheckedException e) {
throw new SQLException("Failed to connect to server [url=" + connProps.getUrl() + ']', SqlStateCode.CLIENT_CONNECTION_FAILED, e);
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridContinuousProcessor method onDiscoDataReceived.
/**
* @param data received discovery data.
*/
private void onDiscoDataReceived(DiscoveryData data) {
if (!ctx.isDaemon() && data != null) {
for (DiscoveryDataItem item : data.items) {
try {
if (item.prjPred != null)
ctx.resource().injectGeneric(item.prjPred);
// Register handler only if local node passes projection predicate.
if ((item.prjPred == null || item.prjPred.apply(ctx.discovery().localNode())) && !locInfos.containsKey(item.routineId))
registerHandler(data.nodeId, item.routineId, item.hnd, item.bufSize, item.interval, item.autoUnsubscribe, false);
if (!item.autoUnsubscribe)
// Register routine locally.
locInfos.putIfAbsent(item.routineId, new LocalRoutineInfo(item.prjPred, item.hnd, item.bufSize, item.interval, item.autoUnsubscribe));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to register continuous handler.", e);
}
}
for (Map.Entry<UUID, Map<UUID, LocalRoutineInfo>> entry : data.clientInfos.entrySet()) {
UUID clientNodeId = entry.getKey();
if (!ctx.clientNode()) {
Map<UUID, LocalRoutineInfo> clientRoutineMap = entry.getValue();
for (Map.Entry<UUID, LocalRoutineInfo> e : clientRoutineMap.entrySet()) {
UUID routineId = e.getKey();
LocalRoutineInfo info = e.getValue();
try {
if (info.prjPred != null)
ctx.resource().injectGeneric(info.prjPred);
if (info.prjPred == null || info.prjPred.apply(ctx.discovery().localNode())) {
registerHandler(clientNodeId, routineId, info.hnd, info.bufSize, info.interval, info.autoUnsubscribe, false);
}
} catch (IgniteCheckedException err) {
U.error(log, "Failed to register continuous handler.", err);
}
}
}
Map<UUID, LocalRoutineInfo> map = clientInfos.get(entry.getKey());
if (map == null) {
map = new HashMap<>();
clientInfos.put(entry.getKey(), map);
}
map.putAll(entry.getValue());
}
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgniteTxManager method resumeTx.
/**
* Resume transaction in current thread.
* Please don't use directly. Use tx.resume() instead.
*
* @param tx Transaction to be resumed.
*
* @see #suspendTx(GridNearTxLocal)
* @see GridNearTxLocal#suspend()
* @see GridNearTxLocal#resume()
* @throws IgniteCheckedException If failed to resume tx.
*/
public void resumeTx(GridNearTxLocal tx) throws IgniteCheckedException {
assert tx != null && !tx.system() : tx;
if (!tx.state(ACTIVE)) {
throw new IgniteCheckedException("Trying to resume transaction with incorrect state " + "[expected=" + SUSPENDED + ", actual=" + tx.state() + ']');
}
assert !threadMap.containsValue(tx) : tx;
assert !transactionMap(tx).containsValue(tx) : tx;
assert !haveSystemTxForThread(Thread.currentThread().getId());
long threadId = Thread.currentThread().getId();
if (threadMap.putIfAbsent(threadId, tx) != null)
throw new IgniteCheckedException("Thread already has started a transaction.");
if (transactionMap(tx).putIfAbsent(tx.xidVersion(), tx) != null)
throw new IgniteCheckedException("Thread already has started a transaction.");
tx.threadId(threadId);
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgfsIpcHandler method processPathControlRequest.
/**
* Processes path control request.
*
* @param ses Session.
* @param cmd Command.
* @param msg Message.
* @return Response message.
* @throws IgniteCheckedException If failed.
*/
private IgfsMessage processPathControlRequest(final IgfsClientSession ses, final IgfsIpcCommand cmd, IgfsMessage msg) throws IgniteCheckedException {
final IgfsPathControlRequest req = (IgfsPathControlRequest) msg;
if (log.isDebugEnabled())
log.debug("Processing path control request [igfsName=" + igfs.name() + ", req=" + req + ']');
final IgfsControlResponse res = new IgfsControlResponse();
final String userName = req.userName();
assert userName != null;
try {
IgfsUserContext.doAs(userName, new IgniteOutClosure<Object>() {
@Override
public Void apply() {
switch(cmd) {
case EXISTS:
res.response(igfs.exists(req.path()));
break;
case INFO:
res.response(igfs.info(req.path()));
break;
case PATH_SUMMARY:
res.response(igfs.summary(req.path()));
break;
case UPDATE:
res.response(igfs.update(req.path(), req.properties()));
break;
case RENAME:
igfs.rename(req.path(), req.destinationPath());
res.response(true);
break;
case DELETE:
res.response(igfs.delete(req.path(), req.flag()));
break;
case MAKE_DIRECTORIES:
igfs.mkdirs(req.path(), req.properties());
res.response(true);
break;
case LIST_PATHS:
res.paths(igfs.listPaths(req.path()));
break;
case LIST_FILES:
res.files(igfs.listFiles(req.path()));
break;
case SET_TIMES:
igfs.setTimes(req.path(), req.modificationTime(), req.accessTime());
res.response(true);
break;
case AFFINITY:
res.locations(igfs.affinity(req.path(), req.start(), req.length()));
break;
case OPEN_READ:
{
IgfsInputStream igfsIn = !req.flag() ? igfs.open(req.path(), bufSize) : igfs.open(req.path(), bufSize, req.sequentialReadsBeforePrefetch());
long streamId = registerResource(ses, igfsIn);
if (log.isDebugEnabled())
log.debug("Opened IGFS input stream for file read [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
res.response(new IgfsInputStreamDescriptor(streamId, igfsIn.length()));
break;
}
case OPEN_CREATE:
{
long streamId = registerResource(ses, igfs.create(// Path.
req.path(), // Buffer size.
bufSize, // Overwrite if exists.
req.flag(), // Affinity key based on replication factor.
affinityKey(req), // Replication factor.
req.replication(), // Block size.
req.blockSize(), // File properties.
req.properties()));
if (log.isDebugEnabled())
log.debug("Opened IGFS output stream for file create [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
res.response(streamId);
break;
}
case OPEN_APPEND:
{
long streamId = registerResource(ses, igfs.append(// Path.
req.path(), // Buffer size.
bufSize, // Create if absent.
req.flag(), // File properties.
req.properties()));
if (log.isDebugEnabled())
log.debug("Opened IGFS output stream for file append [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
res.response(streamId);
break;
}
default:
assert false : "Unhandled path control request command: " + cmd;
break;
}
return null;
}
});
} catch (IgniteException e) {
throw new IgniteCheckedException(e);
}
if (log.isDebugEnabled())
log.debug("Finished processing path control request [igfsName=" + igfs.name() + ", req=" + req + ", res=" + res + ']');
return res;
}
Aggregations