use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class SingleNodeHandler method okResponse.
@Override
public void okResponse(byte[] data, MySQLConnection conn) {
boolean executeResponse = false;
try {
executeResponse = conn.syncAndExcute();
} catch (UnsupportedEncodingException e) {
executeException(conn);
}
if (executeResponse) {
conn.setRunning(false);
ServerConnection source = session.getSource();
if (source.isAutocommit()) {
session.clearConnections();
}
endRunning();
OkPacket ok = new OkPacket();
ok.read(data);
source.setLastInsertId(ok.insertId);
buffer = source.writeToBuffer(data, buffer);
source.write(buffer);
}
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class SingleNodeHandler method connectionError.
@Override
public void connectionError(Throwable e, MySQLConnection conn) {
if (!session.closeConnection(route)) {
conn.close();
}
endRunning();
ErrorPacket err = new ErrorPacket();
err.packetId = ++packetId;
err.errno = ErrorCode.ER_YES;
err.message = StringUtil.encode(e.getMessage(), session.getSource().getCharset());
ServerConnection source = session.getSource();
source.write(err.write(buffer, source));
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class SingleNodeHandler method fieldEofResponse.
@Override
public void fieldEofResponse(byte[] header, List<byte[]> fields, byte[] eof, MySQLConnection conn) {
ServerConnection source = session.getSource();
buffer = session.getSource().allocate();
++packetId;
buffer = source.writeToBuffer(header, buffer);
for (int i = 0, len = fields.size(); i < len; ++i) {
++packetId;
buffer = source.writeToBuffer(fields.get(i), buffer);
}
++packetId;
buffer = source.writeToBuffer(eof, buffer);
source.write(buffer);
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class MultiNodeExecutor method handleSuccessOK.
/**
* @throws nothing never throws any exception
*/
private void handleSuccessOK(BlockingSession ss, RouteResultsetNode rrn, boolean autocommit, OkPacket ok) {
if (decrementCountAndIsZero()) {
if (isFail.get()) {
notifyFailure(ss);
return;
}
try {
ServerConnection source = ss.getSource();
// OK_PACKET
ok.packetId = ++packetId;
ok.affectedRows = affectedRows;
if (insertId > 0) {
ok.insertId = insertId;
source.setLastInsertId(insertId);
}
if (source.isAutocommit()) {
if (!autocommit) {
// 前端非事务模式,后端事务模式,则需要自动递交后端事务。
icExecutor.commit(ok, ss, ss.getTarget().size());
} else {
ss.release();
ok.write(source);
}
} else {
ok.write(source);
}
source.recycle(buffer);
} catch (Exception e) {
LOGGER.warn("exception happens in success notification: " + ss.getSource(), e);
}
}
}
use of com.alibaba.cobar.server.ServerConnection in project cobar by alibaba.
the class MultiNodeExecutor method handleRowData.
/**
* 处理RowData数据
*/
private void handleRowData(final RouteResultsetNode rrn, Channel c, BlockingSession ss) throws IOException {
final ServerConnection source = ss.getSource();
BinaryPacket bin = null;
int size = 0;
for (; ; ) {
bin = ((MySQLChannel) c).receive();
switch(bin.data[0]) {
case ErrorPacket.FIELD_COUNT:
c.setRunning(false);
handleFailure(ss, rrn, new BinaryErrInfo(((MySQLChannel) c), bin, source, rrn));
return;
case EOFPacket.FIELD_COUNT:
c.setRunning(false);
if (source.isAutocommit()) {
c = ss.getTarget().remove(rrn);
if (c != null) {
if (isFail.get() || source.isClosed()) {
/**
* this {@link Channel} might be closed by other
* thread in this condition, so that do not release
* this channel
*/
c.close();
} else {
c.release();
}
}
}
handleSuccessEOF(ss, bin);
return;
default:
// ROWS
bin.packetId = ++packetId;
buffer = bin.write(buffer, source);
size += bin.packetLength;
if (size > RECEIVE_CHUNK_SIZE) {
handleNext(rrn, c, ss);
return;
}
}
}
}
Aggregations