Commit a6cafe64 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2204] cleanup: removed unused func, and renamed "ClientList" with "DataSrc".

getClientListClasses() was removed.  It's not used anymore.
a few methods named with "ClientList" were renamed with adding "DataSrc".
The resulting names are a bit long, but since there's no namespace
qualification, simply saying "client" can be confusing (it could be
interpreted to mean DNS clients, for example).
parent 52272e79
......@@ -271,7 +271,9 @@ public:
/// The data source client list
AuthSrv::DataSrcClientListsPtr datasrc_client_lists_;
shared_ptr<ConfigurableClientList> getClientList(const RRClass& rrclass) {
shared_ptr<ConfigurableClientList> getDataSrcClientList(
const RRClass& rrclass)
{
// TODO: Debug-build only check
if (!mutex_.locked()) {
isc_throw(isc::Unexpected, "Not locked!");
......@@ -646,13 +648,13 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
}
// Lock the client lists and keep them under the lock until the processing
// and rendering is done (this is the same mutex as from
// AuthSrv::getClientListMutex()).
// AuthSrv::getDataSrcClientListMutex()).
isc::util::thread::Mutex::Locker locker(mutex_);
try {
const ConstQuestionPtr question = *message.beginQuestion();
const shared_ptr<datasrc::ClientList>
list(getClientList(question->getClass()));
list(getDataSrcClientList(question->getClass()));
if (list) {
const RRType& qtype = question->getType();
const Name& qname = question->getName();
......@@ -942,28 +944,12 @@ AuthSrv::swapDataSrcClientLists(DataSrcClientListsPtr new_lists) {
}
shared_ptr<ConfigurableClientList>
AuthSrv::getClientList(const RRClass& rrclass) {
return (impl_->getClientList(rrclass));
}
vector<RRClass>
AuthSrv::getClientListClasses() const {
// TODO: Debug-build only check
if (!impl_->mutex_.locked()) {
isc_throw(isc::Unexpected, "Not locked");
}
vector<RRClass> result;
for (std::map<RRClass, shared_ptr<ConfigurableClientList> >::
const_iterator it(impl_->datasrc_client_lists_->begin());
it != impl_->datasrc_client_lists_->end(); ++it) {
result.push_back(it->first);
}
return (result);
AuthSrv::getDataSrcClientList(const RRClass& rrclass) {
return (impl_->getDataSrcClientList(rrclass));
}
util::thread::Mutex&
AuthSrv::getClientListMutex() const {
AuthSrv::getDataSrcClientListMutex() const {
return (impl_->mutex_);
}
......
......@@ -302,6 +302,7 @@ public:
/// If there was no forwarder yet, this method does nothing.
void destroyDDNSForwarder();
/// \brief Shortcut typedef used for swapDataSrcClientLists().
typedef boost::shared_ptr<std::map<
isc::dns::RRClass, boost::shared_ptr<
isc::datasrc::ConfigurableClientList> > >
......@@ -318,7 +319,7 @@ public:
///
/// This method is intended to be used by a separate method to update
/// the data source configuration "at once". The caller must hold
/// a lock for the mutex object returned by \c getClientListMutex()
/// a lock for the mutex object returned by \c getDataSrcClientListMutex()
/// before calling this method.
///
/// The ownership of the returned pointer is transferred to the caller.
......@@ -340,13 +341,7 @@ public:
/// \param rrclass The class for which to get the list.
/// \return The list, or NULL if no list is set for the class.
boost::shared_ptr<isc::datasrc::ConfigurableClientList>
getClientList(const isc::dns::RRClass& rrclass);
/// \brief Returns a list of classes that have a client list.
///
/// \return List of classes for which a non-NULL client list
/// has been set by setClientList.
std::vector<isc::dns::RRClass> getClientListClasses() const;
getDataSrcClientList(const isc::dns::RRClass& rrclass);
/// \brief Return a mutex for the client lists.
///
......@@ -357,9 +352,9 @@ public:
/// is correct:
/// \code
/// {
/// Mutex::Locker locker(auth->getClientListMutex());
/// Mutex::Locker locker(auth->getDataSrcClientListMutex());
/// boost::shared_ptr<isc::datasrc::ConfigurableClientList>
/// list(auth->getClientList(RRClass::IN()));
/// list(auth->getDataSrcClientList(RRClass::IN()));
/// // Do some processing here
/// }
/// \endcode
......@@ -368,8 +363,8 @@ public:
/// \code
/// boost::shared_ptr<isc::datasrc::ConfigurableClientList> list;
/// {
/// Mutex::Locker locker(auth->getClientListMutex());
/// list = auth->getClientList(RRClass::IN()));
/// Mutex::Locker locker(auth->getDataSrcClientListMutex());
/// list = auth->getDataSrcClientList(RRClass::IN()));
/// }
/// // Do some processing here
/// \endcode
......@@ -378,7 +373,7 @@ public:
/// (lock) the mutex. It's because locking of the mutex is not really
/// a modification of the server object and it is needed to protect the
/// lists even on read-only operations.
isc::util::thread::Mutex& getClientListMutex() const;
isc::util::thread::Mutex& getDataSrcClientListMutex() const;
/// \brief Sets the timeout for incoming TCP connections
///
......
......@@ -128,7 +128,7 @@ public:
QueryBenchMark(queries, query_message, buffer)
{
isc::util::thread::Mutex::Locker locker(
server_->getClientListMutex());
server_->getDataSrcClientListMutex());
server_->swapDataSrcClientLists(
configureDataSource(
Element::fromJSON("{\"IN\":"
......@@ -149,7 +149,7 @@ public:
QueryBenchMark(queries, query_message, buffer)
{
isc::util::thread::Mutex::Locker locker(
server_->getClientListMutex());
server_->getDataSrcClientListMutex());
server_->swapDataSrcClientLists(
configureDataSource(
Element::fromJSON("{\"IN\":"
......
......@@ -192,9 +192,10 @@ public:
// We're going to work with the client lists. They may be used
// from a different thread too, protect them.
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
const boost::shared_ptr<isc::datasrc::ConfigurableClientList>
list(server.getClientList(zone_class));
list(server.getDataSrcClientList(zone_class));
if (!list) {
isc_throw(AuthCommandError, "There's no client list for "
......
......@@ -114,7 +114,7 @@ datasrcConfigHandler(AuthSrv* server, bool* first_time,
// swap.
{
isc::util::thread::Mutex::Locker locker(
server->getClientListMutex());
server->getDataSrcClientListMutex());
lists = server->swapDataSrcClientLists(lists);
}
// The previous lists are destroyed here. Note that it's outside
......
......@@ -729,7 +729,7 @@ void
installDataSrcClientLists(AuthSrv& server,
AuthSrv::DataSrcClientListsPtr lists)
{
thread::Mutex::Locker locker(server.getClientListMutex());
thread::Mutex::Locker locker(server.getDataSrcClientListMutex());
server.swapDataSrcClientLists(lists);
}
......@@ -1439,10 +1439,11 @@ TEST_F(AuthSrvTest,
// Set real inmem client to proxy
updateInMemory(server, "example.", CONFIG_INMEMORY_EXAMPLE);
{
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
boost::shared_ptr<isc::datasrc::ConfigurableClientList>
list(new FakeList(server.getClientList(RRClass::IN()), THROW_NEVER,
false));
list(new FakeList(server.getDataSrcClientList(RRClass::IN()),
THROW_NEVER, false));
AuthSrv::DataSrcClientListsPtr lists(new std::map<RRClass, ListPtr>);
lists->insert(pair<RRClass, ListPtr>(RRClass::IN(), list));
server.swapDataSrcClientLists(lists);
......@@ -1469,10 +1470,11 @@ setupThrow(AuthSrv& server, ThrowWhen throw_when, bool isc_exception,
{
updateInMemory(server, "example.", CONFIG_INMEMORY_EXAMPLE);
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
boost::shared_ptr<isc::datasrc::ConfigurableClientList>
list(new FakeList(server.getClientList(RRClass::IN()), throw_when,
isc_exception, rrset));
list(new FakeList(server.getDataSrcClientList(RRClass::IN()),
throw_when, isc_exception, rrset));
AuthSrv::DataSrcClientListsPtr lists(new std::map<RRClass, ListPtr>);
lists->insert(pair<RRClass, ListPtr>(RRClass::IN(), list));
server.swapDataSrcClientLists(lists);
......@@ -1787,7 +1789,8 @@ TEST_F(AuthSrvTest, clientList) {
// We need to lock the mutex to make the (get|set)ClientList happy.
// There's a debug-build only check in them to make sure everything
// locks them and we call them directly here.
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
AuthSrv::DataSrcClientListsPtr lists; // initially empty
......@@ -1804,8 +1807,8 @@ TEST_F(AuthSrvTest, clientList) {
server.swapDataSrcClientLists(lists);
// And the lists can be retrieved.
EXPECT_EQ(list, server.getClientList(RRClass::IN()));
EXPECT_EQ(list2, server.getClientList(RRClass::CH()));
EXPECT_EQ(list, server.getDataSrcClientList(RRClass::IN()));
EXPECT_EQ(list2, server.getDataSrcClientList(RRClass::CH()));
// Replace the lists with new lists containing only one list.
lists.reset(new std::map<RRClass, ListPtr>);
......@@ -1817,19 +1820,20 @@ TEST_F(AuthSrvTest, clientList) {
EXPECT_EQ(2, lists->size());
// The CH list really got deleted.
EXPECT_EQ(list, server.getClientList(RRClass::IN()));
EXPECT_FALSE(server.getClientList(RRClass::CH()));
EXPECT_EQ(list, server.getDataSrcClientList(RRClass::IN()));
EXPECT_FALSE(server.getDataSrcClientList(RRClass::CH()));
}
// We just test the mutex can be locked (exactly once).
TEST_F(AuthSrvTest, mutex) {
isc::util::thread::Mutex::Locker l1(server.getClientListMutex());
isc::util::thread::Mutex::Locker l1(server.getDataSrcClientListMutex());
// TODO: Once we have non-debug build, this one will not work, since
// we currently use the fact that we can't lock twice from the same
// thread. In the non-debug mode, this would deadlock.
// Skip then.
EXPECT_THROW({
isc::util::thread::Mutex::Locker l2(server.getClientListMutex());
isc::util::thread::Mutex::Locker l2(
server.getDataSrcClientListMutex());
}, isc::InvalidOperation);
}
......
......@@ -176,17 +176,18 @@ TEST_F(AuthCommandTest, shutdownIncorrectPID) {
// zones, and checks the zones are correctly loaded.
void
zoneChecks(AuthSrv& server) {
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
EXPECT_EQ(ZoneFinder::SUCCESS, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test1.example")).finder_->
find(Name("ns.test1.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::NXRRSET, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test1.example")).finder_->
find(Name("ns.test1.example"), RRType::AAAA())->code);
EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test2.example")).finder_->
find(Name("ns.test2.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::NXRRSET, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test2.example")).finder_->
find(Name("ns.test2.example"), RRType::AAAA())->code);
}
......@@ -195,7 +196,8 @@ void
installDataSrcClientLists(AuthSrv& server,
AuthSrv::DataSrcClientListsPtr lists)
{
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
server.swapDataSrcClientLists(lists);
}
......@@ -225,20 +227,22 @@ configureZones(AuthSrv& server) {
void
newZoneChecks(AuthSrv& server) {
isc::util::thread::Mutex::Locker locker(server.getClientListMutex());
EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
isc::util::thread::Mutex::Locker locker(
server.getDataSrcClientListMutex());
EXPECT_EQ(ZoneFinder::SUCCESS, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test1.example")).finder_->
find(Name("ns.test1.example"), RRType::A())->code);
// now test1.example should have ns/AAAA
EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test1.example")).finder_->
find(Name("ns.test1.example"), RRType::AAAA())->code);
// test2.example shouldn't change
EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS, server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test2.example")).finder_->
find(Name("ns.test2.example"), RRType::A())->code);
EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::NXRRSET,
server.getDataSrcClientList(RRClass::IN())->
find(Name("ns.test2.example")).finder_->
find(Name("ns.test2.example"), RRType::AAAA())->code);
}
......@@ -284,9 +288,11 @@ TEST_F(AuthCommandTest,
installDataSrcClientLists(server_, configureDataSource(config));
{
isc::util::thread::Mutex::Locker locker(server_.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server_.getDataSrcClientListMutex());
// Check that the A record at www.example.org does not exist
EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::NXDOMAIN,
server_.getDataSrcClientList(RRClass::IN())->
find(Name("example.org")).finder_->
find(Name("www.example.org"), RRType::A())->code);
......@@ -306,7 +312,8 @@ TEST_F(AuthCommandTest,
sql_updater->addRRset(*rrset);
sql_updater->commit();
EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::NXDOMAIN,
server_.getDataSrcClientList(RRClass::IN())->
find(Name("example.org")).finder_->
find(Name("www.example.org"), RRType::A())->code);
}
......@@ -318,9 +325,11 @@ TEST_F(AuthCommandTest,
checkAnswer(0, "Successful load");
{
isc::util::thread::Mutex::Locker locker(server_.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server_.getDataSrcClientListMutex());
// And now it should be present too.
EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS,
server_.getDataSrcClientList(RRClass::IN())->
find(Name("example.org")).finder_->
find(Name("www.example.org"), RRType::A())->code);
}
......@@ -331,9 +340,11 @@ TEST_F(AuthCommandTest,
checkAnswer(1, "example.com");
{
isc::util::thread::Mutex::Locker locker(server_.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server_.getDataSrcClientListMutex());
// The previous zone is not hurt in any way
EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS,
server_.getDataSrcClientList(RRClass::IN())->
find(Name("example.org")).finder_->
find(Name("example.org"), RRType::SOA())->code);
}
......@@ -352,9 +363,11 @@ TEST_F(AuthCommandTest,
Element::fromJSON("{\"origin\": \"example.com\"}"));
checkAnswer(1, "Unreadable");
isc::util::thread::Mutex::Locker locker(server_.getClientListMutex());
isc::util::thread::Mutex::Locker locker(
server_.getDataSrcClientListMutex());
// The previous zone is not hurt in any way
EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
EXPECT_EQ(ZoneFinder::SUCCESS,
server_.getDataSrcClientList(RRClass::IN())->
find(Name("example.org")).finder_->
find(Name("example.org"), RRType::SOA())->code);
}
......
......@@ -79,7 +79,7 @@ datasrcConfigHandler(DatasrcConfigTest* fake_server, const std::string&,
class DatasrcConfigTest : public ::testing::Test {
public:
// These pretend to be the server
isc::util::thread::Mutex& getClientListMutex() const {
isc::util::thread::Mutex& getDataSrcClientListMutex() const {
return (mutex_);
}
void swapDataSrcClientLists(shared_ptr<std::map<dns::RRClass, ListPtr> >
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment