Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
fix state transition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianyi Chen committed Jan 30, 2018
1 parent 583c427 commit aa3a8a4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
12 changes: 2 additions & 10 deletions src/network/connection_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ DEF_TRANSITION_GRAPH

DEFINE_STATE(PROCESS)
ON(PROCEED) SET_STATE_TO(WRITE) AND_INVOKE(ProcessWrite)
ON(NEED_DATA) SET_STATE_TO(PROCESS) AND_INVOKE(Process)
ON(NEED_DATA) SET_STATE_TO(READ) AND_INVOKE(FillReadBuffer)
ON(GET_RESULT) SET_STATE_TO(GET_RESULT) AND_WAIT
ON(FINISH) SET_STATE_TO(CLOSING) AND_INVOKE(CloseSocket)
END_DEF
Expand Down Expand Up @@ -216,14 +216,6 @@ Transition ConnectionHandle::FillReadBuffer() {
// we use general read function
if (conn_SSL_context != nullptr) {
ERR_clear_error();
// TODO(Yuchen): For the transparent negotiation to succeed, the ssl must have been
// initialized to client or server mode?
// Only when the whole SSL record has been received and processed completely,
// SSL_read() will return reporting success.
// Special case would be: SSL_read() reads the whole SSL record from the network buffer.
// The network buffer becomes empty and data is in SSL buffer. We can't rely on
// libevent read event since the system does not know about the SSL buffer. We need to
// call SSL_pending() to check manually. (See StateMachine)
bytes_read = SSL_read(conn_SSL_context, rbuf_->GetPtr(rbuf_->buf_size),
rbuf_->GetMaxSize() - rbuf_->buf_size);
LOG_TRACE("SSL read successfully");
Expand Down Expand Up @@ -282,7 +274,6 @@ Transition ConnectionHandle::FillReadBuffer() {
} else if (bytes_read == 0) {
return Transition::FINISH;
} else if (bytes_read < 0) {
LOG_ERROR("Error writing: %s", strerror(errno));
// Nothing in the network pipe now
if (errno == EAGAIN || errno == EWOULDBLOCK) {
// return whatever results we have
Expand All @@ -292,6 +283,7 @@ Transition ConnectionHandle::FillReadBuffer() {
continue;
} else {
// some other error occured
LOG_ERROR("Error writing: %s", strerror(errno));
throw NetworkProcessException("Error when filling read buffer " +
std::to_string(errno));
}
Expand Down
5 changes: 3 additions & 2 deletions src/network/postgres_protocol_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,12 @@ bool PostgresProtocolHandler::ProcessInitialPacket(InputPacket *pkt, Client clie

// TODO(Yuchen): consider more about return value
if (proto_version == SSL_MESSAGE_VERNO) {
LOG_TRACE("process SSL MESSAGE");
LOG_DEBUG("process SSL MESSAGE");
ProcessSSLRequestPacket(ssl_able, ssl_handshake);
return true;
}
else {
LOG_TRACE("process startup packet");
LOG_DEBUG("process startup packet");
return ProcessStartupPacket(pkt, proto_version, client, finish_startup_packet);
}
}
Expand Down Expand Up @@ -1156,6 +1156,7 @@ bool PostgresProtocolHandler::ProcessStartupPacket(InputPacket* pkt, int32_t pro
// TODO(Yuchen): Peloton does not do any kind of trust authentication now.
// For example, no password authentication.
SendInitialResponse();
LOG_DEBUG("Initial done");

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions test/network/select_all_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void *SelectAllTest(int port) {
txn1.commit();

pqxx::work txn2(C);
for (int i = 0; i < 2000; i++) {
for (int i = 0; i < 20; i++) {
std::string s = "INSERT INTO template VALUES (" + std::to_string(i) + ")";
LOG_INFO("Start sending query");
txn2.exec(s);
}

pqxx::result R = txn2.exec("SELECT * from template;");
txn2.commit();
EXPECT_EQ(R.size(), 2000);
EXPECT_EQ(R.size(), 20);
} catch (const std::exception &e) {
LOG_INFO("[SelectAllTest] Exception occurred: %s", e.what());
EXPECT_TRUE(false);
Expand Down
6 changes: 3 additions & 3 deletions test/network/ssl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void *BasicTest(int port) {

pqxx::result R = txn2.exec("SELECT name FROM employee where id=1;");
txn2.commit();

EXPECT_EQ(R.size(), 1);

// SSL large write test
Expand All @@ -73,15 +73,15 @@ void *BasicTest(int port) {
txn3.commit();

pqxx::work txn4(C);
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 10; i++) {
std::string s = "INSERT INTO template VALUES (" + std::to_string(i) + ")";
txn4.exec(s);
}

R = txn4.exec("SELECT * from template;");
txn4.commit();

EXPECT_EQ(R.size(), 1000);
EXPECT_EQ(R.size(), 10);

} catch (const std::exception &e) {
LOG_INFO("[SSLTest] Exception occurred: %s", e.what());
Expand Down

0 comments on commit aa3a8a4

Please sign in to comment.