This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push:
new b3759a9 Using MT_hashtable for VC lookup.
b3759a9 is described below
commit b3759a9addf8709c0552cbc282f048f8bbda8614
Author: Jordy Liu <[email protected]>
AuthorDate: Sat Mar 3 17:39:14 2018 +0800
Using MT_hashtable for VC lookup.
---
iocore/net/P_QUICPacketHandler.h | 2 +-
iocore/net/QUICPacketHandler.cc | 9 ++++++--
iocore/net/quic/QUICConfig.cc | 10 ++++++++-
iocore/net/quic/QUICConfig.h | 3 ++-
iocore/net/quic/QUICConnectionTable.cc | 39 ++++++++++++++++++++--------------
iocore/net/quic/QUICConnectionTable.h | 14 ++++++------
mgmt/RecordsConfig.cc | 2 ++
7 files changed, 52 insertions(+), 27 deletions(-)
diff --git a/iocore/net/P_QUICPacketHandler.h b/iocore/net/P_QUICPacketHandler.h
index 70b3048..886ce70 100644
--- a/iocore/net/P_QUICPacketHandler.h
+++ b/iocore/net/P_QUICPacketHandler.h
@@ -74,7 +74,7 @@ public:
private:
void _recv_packet(int event, UDPPacket *udp_packet) override;
- QUICConnectionTable _ctable;
+ QUICConnectionTable *_ctable = nullptr;
SSL_CTX *_ssl_ctx;
};
diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc
index 49ae711..2561005 100644
--- a/iocore/net/QUICPacketHandler.cc
+++ b/iocore/net/QUICPacketHandler.cc
@@ -91,10 +91,15 @@ QUICPacketHandler::_read_connection_id(IOBufferBlock *block)
QUICPacketHandlerIn::QUICPacketHandlerIn(const NetProcessor::AcceptOptions
&opt, SSL_CTX *ctx) : NetAccept(opt), _ssl_ctx(ctx)
{
this->mutex = new_ProxyMutex();
+ // create Connection Table
+ QUICConfig::scoped_config params;
+ _ctable = new QUICConnectionTable(params->connection_table_size());
}
QUICPacketHandlerIn::~QUICPacketHandlerIn()
{
+ // TODO: clear all values before destory the table.
+ delete _ctable;
}
NetProcessor *
@@ -175,7 +180,7 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket
*udp_packet)
}
QUICConnection *qc =
- this->_ctable.lookup(reinterpret_cast<const uint8_t *>(block->buf()),
{udp_packet->from, udp_packet->to, SOCK_DGRAM});
+ this->_ctable->lookup(reinterpret_cast<const uint8_t *>(block->buf()),
{udp_packet->from, udp_packet->to, SOCK_DGRAM});
vc = static_cast<QUICNetVConnection *>(qc);
// 7.1. Matching Packets to Connections
@@ -204,7 +209,7 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket
*udp_packet)
// Create a new NetVConnection
QUICConnectionId original_cid = this->_read_connection_id(block);
vc = static_cast<QUICNetVConnection
*>(getNetProcessor()->allocate_vc(nullptr));
- vc->init(original_cid, udp_packet->getConnection(), this, &this->_ctable);
+ vc->init(original_cid, udp_packet->getConnection(), this, this->_ctable);
vc->id = net_next_connection_number();
vc->con.move(con);
vc->submit_time = Thread::get_hrtime();
diff --git a/iocore/net/quic/QUICConfig.cc b/iocore/net/quic/QUICConfig.cc
index a3ff6ec..8bcf9c9 100644
--- a/iocore/net/quic/QUICConfig.cc
+++ b/iocore/net/quic/QUICConfig.cc
@@ -25,7 +25,8 @@
#include <records/I_RecHttp.h>
-int QUICConfig::_config_id = 0;
+int QUICConfig::_config_id = 0;
+int QUICConfigParams::_connection_table_size = 65521;
//
// QUICConfigParams
@@ -38,6 +39,7 @@ QUICConfigParams::initialize()
REC_EstablishStaticConfigInt32U(this->_initial_max_data,
"proxy.config.quic.initial_max_data");
REC_EstablishStaticConfigInt32U(this->_initial_max_stream_data,
"proxy.config.quic.initial_max_stream_data");
REC_EstablishStaticConfigInt32U(this->_server_id,
"proxy.config.quic.server_id");
+ REC_EstablishStaticConfigInt32(_connection_table_size,
"proxy.config.quic.connection_table.size");
}
uint32_t
@@ -58,6 +60,12 @@ QUICConfigParams::server_id() const
return this->_server_id;
}
+int
+QUICConfigParams::connection_table_size()
+{
+ return _connection_table_size;
+}
+
uint32_t
QUICConfigParams::initial_max_data() const
{
diff --git a/iocore/net/quic/QUICConfig.h b/iocore/net/quic/QUICConfig.h
index 0371774..a7a4f60 100644
--- a/iocore/net/quic/QUICConfig.h
+++ b/iocore/net/quic/QUICConfig.h
@@ -24,7 +24,6 @@
#pragma once
#include "ProxyConfig.h"
-
class QUICConfigParams : public ConfigInfo
{
public:
@@ -39,6 +38,7 @@ public:
uint32_t initial_max_stream_id_uni_in() const;
uint32_t initial_max_stream_id_uni_out() const;
uint32_t server_id() const;
+ static int connection_table_size();
private:
// FIXME Fill appropriate default values in RecordsConfig.cc
@@ -47,6 +47,7 @@ private:
uint32_t _initial_max_data = 0;
uint32_t _initial_max_stream_data = 0;
uint32_t _server_id = 0;
+ static int _connection_table_size;
uint32_t _initial_max_stream_id_bidi_in = 100;
uint32_t _initial_max_stream_id_bidi_out = 101;
diff --git a/iocore/net/quic/QUICConnectionTable.cc
b/iocore/net/quic/QUICConnectionTable.cc
index eb048d7..5f860b0 100644
--- a/iocore/net/quic/QUICConnectionTable.cc
+++ b/iocore/net/quic/QUICConnectionTable.cc
@@ -23,29 +23,35 @@
#include "QUICConnectionTable.h"
-int
+QUICConnectionTable::~QUICConnectionTable()
+{
+ // TODO: clear all values.
+}
+
+QUICConnection *
QUICConnectionTable::insert(QUICConnectionId cid, QUICConnection *connection)
{
- this->_connections.put(cid, connection);
- // if (this->_cids.get(connection->endpoint()) == nullptr) {
- // this->_cids.put(connection->endpoint(), cid);
- // }
- return 0;
+ SCOPED_MUTEX_LOCK(lock, _connections.lock_for_key(cid), this_ethread());
+ // To check whether the return value is nullptr by caller in case memory
leak.
+ // The return value isn't nullptr, the new value will take up the slot and
return old value.
+ return _connections.insert_entry(cid, connection);
}
void
QUICConnectionTable::erase(QUICConnectionId cid, QUICConnection *connection)
{
- QUICConnection *qc = this->_connections.get(cid);
- if (qc == nullptr) {
- return;
+ SCOPED_MUTEX_LOCK(lock, _connections.lock_for_key(cid), this_ethread());
+ QUICConnection *ret_connection = _connections.remove_entry(cid);
+ if (ret_connection) {
+ ink_assert(ret_connection == connection);
}
- ink_assert(qc == connection);
- Debug("quic_ctable", "ctable erase cid: [%" PRIx64 "] ",
static_cast<uint64_t>(cid));
- // if (this->_cids.get(connection->endpoint(), connection->connection_id())
== cid) {
- // this->_cids.put(connection->endpoint(), nullptr);
- // }
- this->_connections.put(cid, nullptr);
+}
+
+QUICConnection *
+QUICConnectionTable::erase(QUICConnectionId cid)
+{
+ SCOPED_MUTEX_LOCK(lock, _connections.lock_for_key(cid), this_ethread());
+ return _connections.remove_entry(cid);
}
QUICConnection *
@@ -59,5 +65,6 @@ QUICConnectionTable::lookup(const uint8_t *packet,
QUICFiveTuple endpoint)
// cid = this->_cids.get(endpoint);
ink_assert(false);
}
- return this->_connections.get(cid);
+ SCOPED_MUTEX_LOCK(lock, _connections.lock_for_key(cid), this_ethread());
+ return _connections.lookup_entry(cid);
}
diff --git a/iocore/net/quic/QUICConnectionTable.h
b/iocore/net/quic/QUICConnectionTable.h
index 6bc4b75..0ead233 100644
--- a/iocore/net/quic/QUICConnectionTable.h
+++ b/iocore/net/quic/QUICConnectionTable.h
@@ -25,7 +25,7 @@
#include "QUICTypes.h"
#include "QUICConnection.h"
-#include "ts/Map.h"
+#include "ts/MT_hashtable.h"
class QUICFiveTuple
{
@@ -43,12 +43,15 @@ private:
class QUICConnectionTable
{
public:
+ QUICConnectionTable(int hash_table_size = 65521) :
_connections(hash_table_size) {}
+ ~QUICConnectionTable();
/*
* Insert an entry
*
- * Return 1 if it is the only connection or the first connection from the
endpoint.
+ * Return zero if it is the only connection or the first connection from the
endpoint.
+ * Caller is responsible for memory management.
*/
- int insert(QUICConnectionId cid, QUICConnection *connection);
+ QUICConnection *insert(QUICConnectionId cid, QUICConnection *connection);
/*
* Remove an entry
@@ -56,6 +59,7 @@ public:
* Fails if CID is not associated to a specified connection
*/
void erase(QUICConnectionId cid, QUICConnection *connection);
+ QUICConnection *erase(QUICConnectionId cid);
/*
* Lookup QUICConnection
@@ -65,7 +69,5 @@ public:
QUICConnection *lookup(const uint8_t *packet, QUICFiveTuple endpoint);
private:
- // FIXME Use another map impl. that has good support for concurrent access
- Map<int64_t, QUICConnection *> _connections;
- // Map<QUICFiveTuple, QUICConnectionId> _cids;
+ MTHashTable<uint64_t, QUICConnection *> _connections;
};
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index b6b3172..4f39a42 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -1326,6 +1326,8 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.config.quic.server_id", RECD_INT, "0", RECU_DYNAMIC,
RR_NULL, RECC_STR, "^-?[0-9]+$", RECA_NULL}
,
+ {RECT_CONFIG, "proxy.config.quic.connection_table.size", RECD_INT, "65521",
RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-536870909]", RECA_NULL}
+ ,
//# Add LOCAL Records Here
{RECT_LOCAL, "proxy.local.incoming_ip_to_bind", RECD_STRING, nullptr,
RECU_NULL, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
--
To stop receiving notification emails like this one, please contact
[email protected].