ptupitsyn commented on a change in pull request #9713:
URL: https://github.com/apache/ignite/pull/9713#discussion_r781165695
##########
File path: modules/platforms/cpp/thin-client-test/src/sql_fields_query_test.cpp
##########
@@ -340,12 +340,12 @@ BOOST_AUTO_TEST_CASE(Select10000Values)
for (int64_t i = 0; i < num; ++i)
{
- BOOST_CHECK(cursor.HasNext());
+// BOOST_CHECK(cursor.HasNext());
Review comment:
Should we remove commented code?
##########
File path:
modules/platforms/cpp/network/os/linux/src/network/linux_async_client.cpp
##########
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#include <sys/epoll.h>
+#include <unistd.h>
+
+#include <algorithm>
+
+#include <ignite/common/utils.h>
+#include <ignite/network/utils.h>
+
+#include "network/sockets.h"
+#include "network/linux_async_client.h"
+
+namespace ignite
+{
+ namespace network
+ {
+ LinuxAsyncClient::LinuxAsyncClient(int fd, const EndPoint &addr, const
TcpRange &range) :
+ state(State::CONNECTED),
+ fd(fd),
+ epoll(-1),
+ id(0),
+ addr(addr),
+ range(range),
+ sendPackets(),
+ sendCs(),
+ recvPacket(),
+ closeErr(IgniteError::IGNITE_SUCCESS)
+ {
+ // No-op.
+ }
+
+ LinuxAsyncClient::~LinuxAsyncClient()
+ {
+ Shutdown(0);
+
+ Close();
+ }
+
+ bool LinuxAsyncClient::Shutdown(const IgniteError* err)
+ {
+ common::concurrent::CsLockGuard lock(sendCs);
+ if (state != State::CONNECTED)
+ return false;
+
+ closeErr = err ? *err :
IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Connection closed by
application");
+ shutdown(fd, SHUT_RDWR);
+ state = State::SHUTDOWN;
+
+ return true;
+ }
+
+ bool LinuxAsyncClient::Close()
+ {
+ State::Type stateBefore = state;
+
+ if (state != State::CLOSED)
+ {
+ StopMonitoring();
+ close(fd);
+ fd = -1;
+ state = State::CLOSED;
+ }
+
+ return stateBefore == State::CONNECTED;
+ }
+
+ bool LinuxAsyncClient::Send(const DataBuffer& data)
+ {
+ common::concurrent::CsLockGuard lock(sendCs);
+
+ sendPackets.push_back(data);
+
+ if (sendPackets.size() > 1)
+ return true;
+
+ return SendNextPacketLocked();
+ }
+
+ bool LinuxAsyncClient::SendNextPacketLocked()
+ {
+ if (sendPackets.empty())
+ return true;
+
+ DataBuffer& packet = sendPackets.front();
+
+ ssize_t ret = send(fd, packet.GetData(), packet.GetSize(), 0);
+ if (ret < 0)
+ return false;
+
+ packet.Skip(static_cast<int32_t>(ret));
+
+ EnableSendNotifications();
+
+ return true;
+ }
+
+ DataBuffer LinuxAsyncClient::Receive()
+ {
+ using namespace impl::interop;
+
+ if (!recvPacket.IsValid())
+ {
+ recvPacket = SP_InteropMemory(new
InteropUnpooledMemory(BUFFER_SIZE));
+ recvPacket.Get()->Length(BUFFER_SIZE);
+ }
+
+ ssize_t res = recv(fd, recvPacket.Get()->Data(),
recvPacket.Get()->Length(), 0);
+ if (res < 0)
+ return DataBuffer();
+
+ return DataBuffer(recvPacket, 0, static_cast<int32_t>(res));
+ }
+
+ bool LinuxAsyncClient::StartMonitoring(int epoll0)
+ {
+ if (epoll0 < 0)
+ return false;
+
+ epoll_event event;
+ std::memset(&event, 0, sizeof(event));
+ event.data.ptr = this;
+ event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
+
+ int res = epoll_ctl(epoll0, EPOLL_CTL_ADD, fd, &event);
+ if (res < 0)
+ return false;
+
+ epoll = epoll0;
+
+ return true;
+ }
+
+ void LinuxAsyncClient::StopMonitoring()
+ {
+ epoll_event event;
+ std::memset(&event, 0, sizeof(event));
+
+ epoll_ctl(epoll, EPOLL_CTL_DEL, fd, &event);
+ }
+
+ void LinuxAsyncClient::EnableSendNotifications()
+ {
+ epoll_event event;
+ std::memset(&event, 0, sizeof(event));
+ event.data.ptr = this;
+ event.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP;
+
+ epoll_ctl(epoll, EPOLL_CTL_MOD, fd, &event);
+ }
+
+ void LinuxAsyncClient::DisableSendNotifications()
+ {
+ epoll_event event;
+ std::memset(&event, 0, sizeof(event));
+ event.data.ptr = this;
+ event.events = EPOLLIN | EPOLLRDHUP;
+
+ epoll_ctl(epoll, EPOLL_CTL_MOD, fd, &event);
+ }
+
+ bool LinuxAsyncClient::ProcessSent()
+ {
+ common::concurrent::CsLockGuard lock(sendCs);
+
+ if (sendPackets.empty())
+ {
+ DisableSendNotifications();
+
+ return true;
+ }
+
+ DataBuffer& front = sendPackets.front();
+
+ if (front.IsEmpty())
+ sendPackets.pop_front();
+
+ return SendNextPacketLocked();
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Review comment:
Unnecessary blank lines.
##########
File path:
modules/platforms/cpp/network/os/linux/src/network/linux_async_client_pool.cpp
##########
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <algorithm>
+
+#include <ignite/common/utils.h>
+#include <ignite/network/utils.h>
+
+#include "network/sockets.h"
+#include "network/linux_async_client_pool.h"
+
+namespace ignite
+{
+ namespace network
+ {
+ LinuxAsyncClientPool::LinuxAsyncClientPool() :
+ stopping(true),
+ asyncHandler(0),
+ workerThread(*this),
+ idGen(0),
+ clientsCs(),
+ clientIdMap()
+ {
+ // No-op.
+ }
+
+ LinuxAsyncClientPool::~LinuxAsyncClientPool()
+ {
+ InternalStop();
+ }
+
+ void LinuxAsyncClientPool::Start(const std::vector<TcpRange> &addrs,
uint32_t connLimit)
+ {
+ if (!stopping)
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, "Client
pool is already started");
+
+ idGen = 0;
+ stopping = false;
+
+ try
+ {
+ workerThread.Start0(connLimit, addrs);
+ }
+ catch (...)
+ {
+ Stop();
+
+ throw;
+ }
+ }
+
+ void LinuxAsyncClientPool::Stop()
+ {
+ InternalStop();
+ }
+
+ bool LinuxAsyncClientPool::Send(uint64_t id, const DataBuffer &data)
+ {
+ if (stopping)
+ return false;
+
+ SP_LinuxAsyncClient client = FindClient(id);
+ if (!client.IsValid())
+ return false;
+
+ return client.Get()->Send(data);
+ }
+
+ void LinuxAsyncClientPool::Close(uint64_t id, const IgniteError *err)
+ {
+ if (stopping)
+ return;
+
+ SP_LinuxAsyncClient client = FindClient(id);
+ if (!client.IsValid() || client.Get()->IsClosed())
+ return;
+
+ client.Get()->Shutdown(err);
+ }
+
+ void LinuxAsyncClientPool::CloseAndRelease(uint64_t id, const
IgniteError *err)
+ {
+ if (stopping)
+ return;
+
+ SP_LinuxAsyncClient client;
+ {
+ common::concurrent::CsLockGuard lock(clientsCs);
+
+ std::map<uint64_t, SP_LinuxAsyncClient>::iterator it =
clientIdMap.find(id);
+ if (it == clientIdMap.end())
+ return;
+
+ client = it->second;
+
+ clientIdMap.erase(it);
+ }
+
+ bool closed = client.Get()->Close();
+ if (closed)
+ HandleConnectionClosed(id, err);
+ }
+
+ bool LinuxAsyncClientPool::AddClient(SP_LinuxAsyncClient &client)
+ {
+ if (stopping)
+ return false;
+
+ LinuxAsyncClient& clientRef = *client.Get();
+ {
+ common::concurrent::CsLockGuard lock(clientsCs);
+
+ uint64_t id = ++idGen;
+ clientRef.SetId(id);
+
+ clientIdMap[id] = client;
+ }
+
+ HandleConnectionSuccess(clientRef.GetAddress(), clientRef.GetId());
+
+ return true;
+ }
+
+ void LinuxAsyncClientPool::HandleConnectionError(const EndPoint &addr,
const IgniteError &err)
+ {
+ AsyncHandler* asyncHandler0 = asyncHandler;
+ if (asyncHandler0)
+ asyncHandler0->OnConnectionError(addr, err);
+ }
+
+ void LinuxAsyncClientPool::HandleConnectionSuccess(const EndPoint
&addr, uint64_t id)
+ {
+ AsyncHandler* asyncHandler0 = asyncHandler;
+ if (asyncHandler0)
+ asyncHandler0->OnConnectionSuccess(addr, id);
+ }
+
+ void LinuxAsyncClientPool::HandleConnectionClosed(uint64_t id, const
IgniteError *err)
+ {
+ AsyncHandler* asyncHandler0 = asyncHandler;
+ if (asyncHandler0)
+ asyncHandler0->OnConnectionClosed(id, err);
+ }
+
+ void LinuxAsyncClientPool::HandleMessageReceived(uint64_t id, const
DataBuffer &msg)
+ {
+ AsyncHandler* asyncHandler0 = asyncHandler;
+ if (asyncHandler0)
+ asyncHandler0->OnMessageReceived(id, msg);
+ }
+
+ void LinuxAsyncClientPool::HandleMessageSent(uint64_t id)
+ {
+ AsyncHandler* asyncHandler0 = asyncHandler;
+ if (asyncHandler0)
+ asyncHandler0->OnMessageSent(id);
+ }
+
+ void LinuxAsyncClientPool::InternalStop()
+ {
+ stopping = true;
+ workerThread.Stop();
+
+ {
+ common::concurrent::CsLockGuard lock(clientsCs);
+
+ std::map<uint64_t, SP_LinuxAsyncClient>::iterator it;
+ for (it = clientIdMap.begin(); it != clientIdMap.end(); ++it)
+ {
+ LinuxAsyncClient& client = *it->second.Get();
+
+ IgniteError err(IgniteError::IGNITE_ERR_GENERIC, "Client
stopped");
+ HandleConnectionClosed(client.GetId(), &err);
+ }
+
+ clientIdMap.clear();
+ }
+ }
+
+ SP_LinuxAsyncClient LinuxAsyncClientPool::FindClient(uint64_t id) const
+ {
+ common::concurrent::CsLockGuard lock(clientsCs);
+
+ std::map<uint64_t, SP_LinuxAsyncClient>::const_iterator it =
clientIdMap.find(id);
+ if (it == clientIdMap.end())
+ return SP_LinuxAsyncClient();
+
+ return it->second;
+ }
+ }
+}
+
+
Review comment:
Extra blank lines.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]