use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridH2TreeIndex method getRowCount.
/** {@inheritDoc} */
@Override
public long getRowCount(@Nullable Session ses) {
IndexingQueryFilter f = threadLocalFilter();
int seg = threadLocalSegment();
// Fast path if we don't need to perform any filtering.
if (f == null || f.forCache((getTable()).cacheName()) == null)
try {
return treeForRead(seg).size();
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
GridCursor<GridH2Row> cursor = doFind(null, false, null);
long size = 0;
try {
while (cursor.next()) size++;
} catch (IgniteCheckedException e) {
throw DbException.convert(e);
}
return size;
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class JdbcThinTcpIo method start.
/**
* @throws IgniteCheckedException On error.
* @throws IOException On IO error in handshake.
*/
public void start() throws IgniteCheckedException, IOException {
Socket sock = new Socket();
if (sockSndBuf != 0)
sock.setSendBufferSize(sockSndBuf);
if (sockRcvBuf != 0)
sock.setReceiveBufferSize(sockRcvBuf);
sock.setTcpNoDelay(tcpNoDelay);
try {
sock.connect(new InetSocketAddress(host, port));
} catch (IOException e) {
throw new IgniteCheckedException("Failed to connect to server [host=" + host + ", port=" + port + ']', e);
}
endpoint = new IpcClientTcpEndpoint(sock);
out = new BufferedOutputStream(endpoint.outputStream());
in = new BufferedInputStream(endpoint.inputStream());
handshake();
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class JdbcThinTcpIo method handshake.
/**
* @throws IOException On error.
* @throws IgniteCheckedException On error.
*/
public void handshake() throws IOException, IgniteCheckedException {
BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
writer.writeByte((byte) SqlListenerRequest.HANDSHAKE);
writer.writeShort(CURRENT_VER.major());
writer.writeShort(CURRENT_VER.minor());
writer.writeShort(CURRENT_VER.maintenance());
writer.writeByte(SqlListenerNioListener.JDBC_CLIENT);
writer.writeBoolean(distributedJoins);
writer.writeBoolean(enforceJoinOrder);
send(writer.array());
BinaryReaderExImpl reader = new BinaryReaderExImpl(null, new BinaryHeapInputStream(read()), null, null, false);
boolean accepted = reader.readBoolean();
if (accepted)
return;
short maj = reader.readShort();
short min = reader.readShort();
short maintenance = reader.readShort();
String err = reader.readString();
SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(maj, min, maintenance);
throw new IgniteCheckedException("Handshake failed [driverProtocolVer=" + CURRENT_VER + ", remoteNodeProtocolVer=" + ver + ", err=" + err + ']');
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridEventStorageManager method waitForEvent.
/**
*
* @param timeout Timeout.
* @param c Optional continuation.
* @param p Optional predicate.
* @param types Event types to wait for.
* @return Event.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public Event waitForEvent(long timeout, @Nullable Runnable c, @Nullable final IgnitePredicate<? super Event> p, int... types) throws IgniteCheckedException {
assert timeout >= 0;
final GridFutureAdapter<Event> fut = new GridFutureAdapter<>();
addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
if (p == null || p.apply(evt)) {
fut.onDone(evt);
removeLocalEventListener(this);
}
}
}, types);
try {
if (c != null)
c.run();
} catch (Exception e) {
throw new IgniteCheckedException(e);
}
return fut.get(timeout);
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class GridCacheIoManager method safeSend.
/**
* Sends message and automatically accounts for lefts nodes.
*
* @param nodes Nodes to send to.
* @param msg Message to send.
* @param plc IO policy.
* @param fallback Callback for failed nodes.
* @throws IgniteCheckedException If send failed.
*/
@SuppressWarnings({ "BusyWait", "unchecked" })
public void safeSend(Collection<? extends ClusterNode> nodes, GridCacheMessage msg, byte plc, @Nullable IgnitePredicate<ClusterNode> fallback) throws IgniteCheckedException {
assert nodes != null;
assert msg != null;
if (nodes.isEmpty()) {
if (log.isDebugEnabled())
log.debug("Message will not be sent as collection of nodes is empty: " + msg);
return;
}
if (!onSend(msg, null))
return;
if (log.isDebugEnabled())
log.debug("Sending cache message [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
final Collection<UUID> leftIds = new GridLeanSet<>();
int cnt = 0;
while (cnt < retryCnt) {
try {
Collection<? extends ClusterNode> nodesView = F.view(nodes, new P1<ClusterNode>() {
@Override
public boolean apply(ClusterNode e) {
return !leftIds.contains(e.id());
}
});
cctx.gridIO().sendToGridTopic(nodesView, TOPIC_CACHE, msg, plc);
boolean added = false;
// ignored the message during stopping.
for (ClusterNode n : nodes) {
if (!leftIds.contains(n.id()) && !cctx.discovery().alive(n.id())) {
leftIds.add(n.id());
if (fallback != null && !fallback.apply(n))
// If fallback signalled to stop.
return;
added = true;
}
}
if (added) {
if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
if (log.isDebugEnabled())
log.debug("Message will not be sent because all nodes left topology [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
return;
}
}
break;
} catch (IgniteCheckedException e) {
boolean added = false;
for (ClusterNode n : nodes) {
if (!leftIds.contains(n.id()) && (!cctx.discovery().alive(n.id()) || !cctx.discovery().pingNode(n.id()))) {
leftIds.add(n.id());
if (fallback != null && !fallback.apply(n))
// If fallback signalled to stop.
return;
added = true;
}
}
if (!added) {
cnt++;
if (cnt == retryCnt)
throw e;
U.sleep(retryDelay);
}
if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
if (log.isDebugEnabled())
log.debug("Message will not be sent because all nodes left topology [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
return;
}
if (log.isDebugEnabled())
log.debug("Message send will be retried [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ", leftIds=" + leftIds + ']');
}
}
if (log.isDebugEnabled())
log.debug("Sent cache message [msg=" + msg + ", nodes=" + U.toShortString(nodes) + ']');
}
Aggregations