]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2211] use DataSrcClientsMgr for query processing
authorJINMEI Tatuya <jinmei@isc.org>
Sat, 20 Oct 2012 05:27:30 +0000 (22:27 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Sat, 20 Oct 2012 05:27:30 +0000 (22:27 -0700)
src/bin/auth/auth_srv.cc
src/bin/auth/command.cc
src/bin/auth/datasrc_clients_mgr.h
src/bin/auth/tests/auth_srv_unittest.cc
src/bin/auth/tests/datasrc_clients_mgr_unittest.cc

index f90b1160285926c9f967c8be618f4d003f580590..e27098258e454c46df39317564396d55f2d786a4 100644 (file)
@@ -654,15 +654,15 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
         local_edns->setUDPSize(AuthSrvImpl::DEFAULT_LOCAL_UDPSIZE);
         message.setEDNS(local_edns);
     }
-    // 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::getDataSrcClientListMutex()).
-    isc::util::thread::Mutex::Locker locker(mutex_);
+    // Get access to data source client list through the holder and keep thek
+    // holder until the processing and rendering is done to avoid inter-thread
+    // race.
+    auth::DataSrcClientsMgr::Holder datasrc_holder(datasrc_clients_mgr_);
 
     try {
         const ConstQuestionPtr question = *message.beginQuestion();
         const shared_ptr<datasrc::ClientList>
-            list(getDataSrcClientList(question->getClass()));
+            list(datasrc_holder.findClientList(question->getClass()));
         if (list) {
             const RRType& qtype = question->getType();
             const Name& qname = question->getName();
index 6ee616870c08be39d13aac7b59944e8646e8a05f..6b8b0ce2676176bac374bbccb1ae7f0aca9b5359 100644 (file)
@@ -192,9 +192,10 @@ public:
         const Name origin(origin_elem->stringValue());
 
         DataSrcClientsMgr::Holder holder(server.getDataSrcClientsMgr());
-        ConfigurableClientList* list = holder.findClientList(zone_class);
+        boost::shared_ptr<ConfigurableClientList> list =
+            holder.findClientList(zone_class);
 
-        if (list == NULL) {
+        if (!list) {
             isc_throw(AuthCommandError, "There's no client list for "
                       "class " << zone_class);
         }
index 937365b0d076882c61de300ff8a432a530ab8578..01c346f43ba53c65fee64ef1ad3fd80e1d9524bc 100644 (file)
@@ -116,15 +116,15 @@ public:
         /// otherwise it returns NULL.  The manager keeps the ownership of
         /// the pointed object.  Also, it's not safe to get access to the
         /// object beyond the scope of the holder object.
-        datasrc::ConfigurableClientList* findClientList(
+        boost::shared_ptr<datasrc::ConfigurableClientList> findClientList(
             const dns::RRClass& rrclass)
         {
             const ClientListsMap::const_iterator
                 it = mgr_.clients_map_->find(rrclass);
             if (it == mgr_.clients_map_->end()) {
-                return (NULL);
+                return (boost::shared_ptr<datasrc::ConfigurableClientList>());
             } else {
-                return (it->second.get());
+                return (it->second);
             }
         }
     private:
index a202c13fb67ac15ca3662a30e3355096c407e636..0781d578b56c0fa60b2da8187e15c9b9b8c02d47 100644 (file)
@@ -70,6 +70,7 @@ using namespace isc::util::unittests;
 using namespace isc::dns::rdata;
 using namespace isc::data;
 using namespace isc::xfr;
+using namespace isc::auth;
 using namespace isc::asiodns;
 using namespace isc::asiolink;
 using namespace isc::testutils;
@@ -726,11 +727,11 @@ TEST_F(AuthSrvTest, notifyWithSessionMessageError) {
 }
 
 void
-installDataSrcClientLists(AuthSrv& server,
-                          DataSrcClientListsPtr lists)
-{
-    thread::Mutex::Locker locker(server.getDataSrcClientListMutex());
-    server.swapDataSrcClientLists(lists);
+installDataSrcClientLists(AuthSrv& server, DataSrcClientListsPtr lists) {
+    // For now, we use explicit swap than reconfigure() because the latter
+    // involves a separate thread and cannot guarantee the new config is
+    // available for the subsequent test.
+    server.getDataSrcClientsMgr().swapDataSrcClientLists(lists);
 }
 
 void
@@ -1438,16 +1439,16 @@ TEST_F(AuthSrvTest,
 {
     // Set real inmem client to proxy
     updateInMemory(server, "example.", CONFIG_INMEMORY_EXAMPLE);
+    boost::shared_ptr<isc::datasrc::ConfigurableClientList> list;
+    DataSrcClientsMgr& mgr = server.getDataSrcClientsMgr();
     {
-        isc::util::thread::Mutex::Locker locker(
-            server.getDataSrcClientListMutex());
-        boost::shared_ptr<isc::datasrc::ConfigurableClientList>
-            list(new FakeList(server.getDataSrcClientList(RRClass::IN()),
-                              THROW_NEVER, false));
-        DataSrcClientListsPtr lists(new std::map<RRClass, ListPtr>);
-        lists->insert(pair<RRClass, ListPtr>(RRClass::IN(), list));
-        server.swapDataSrcClientLists(lists);
+        DataSrcClientsMgr::Holder holder(mgr);
+        list.reset(new FakeList(holder.findClientList(RRClass::IN()),
+                                THROW_NEVER, false));
     }
+    DataSrcClientListsPtr lists(new std::map<RRClass, ListPtr>);
+    lists->insert(pair<RRClass, ListPtr>(RRClass::IN(), list));
+    server.getDataSrcClientsMgr().swapDataSrcClientLists(lists);
 
     createDataFromFile("nsec3query_nodnssec_fromWire.wire");
     server.processMessage(*io_message, *parse_message, *response_obuffer,
@@ -1470,14 +1471,16 @@ setupThrow(AuthSrv& server, ThrowWhen throw_when, bool isc_exception,
 {
     updateInMemory(server, "example.", CONFIG_INMEMORY_EXAMPLE);
 
-    isc::util::thread::Mutex::Locker locker(
-        server.getDataSrcClientListMutex());
-    boost::shared_ptr<isc::datasrc::ConfigurableClientList>
-        list(new FakeList(server.getDataSrcClientList(RRClass::IN()),
-                          throw_when, isc_exception, rrset));
+    boost::shared_ptr<isc::datasrc::ConfigurableClientList> list;
+    DataSrcClientsMgr& mgr = server.getDataSrcClientsMgr();
+    {           // we need to limit the scope so swap is outside of it
+        DataSrcClientsMgr::Holder holder(mgr);
+        list.reset(new FakeList(holder.findClientList(RRClass::IN()),
+                                throw_when, isc_exception, rrset));
+    }
     DataSrcClientListsPtr lists(new std::map<RRClass, ListPtr>);
     lists->insert(pair<RRClass, ListPtr>(RRClass::IN(), list));
-    server.swapDataSrcClientLists(lists);
+    mgr.swapDataSrcClientLists(lists);
 }
 
 TEST_F(AuthSrvTest,
index 1258a04c67526079ae1b1d223f4f881223d96505..7dbee06d4a7fc76a987ac65182bb96335a09563b 100644 (file)
@@ -154,10 +154,8 @@ TEST(DataSrcClientsMgrTest, holder) {
     {
         // Initially it's empty, so findClientList() will always return NULL
         TestDataSrcClientsMgr::Holder holder(mgr);
-        EXPECT_EQ(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::IN()));
-        EXPECT_EQ(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::CH()));
+        EXPECT_FALSE(holder.findClientList(RRClass::IN()));
+        EXPECT_FALSE(holder.findClientList(RRClass::CH()));
         // map should be protected here
         EXPECT_EQ(1, FakeDataSrcClientsBuilder::map_mutex->lock_count);
         EXPECT_EQ(0, FakeDataSrcClientsBuilder::map_mutex->unlock_count);
@@ -174,10 +172,8 @@ TEST(DataSrcClientsMgrTest, holder) {
     mgr.reconfigure(reconfigure_arg);
     {
         TestDataSrcClientsMgr::Holder holder(mgr);
-        EXPECT_NE(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::IN()));
-        EXPECT_NE(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::CH()));
+        EXPECT_TRUE(holder.findClientList(RRClass::IN()));
+        EXPECT_TRUE(holder.findClientList(RRClass::CH()));
     }
     // We need to clear command queue by hand
     FakeDataSrcClientsBuilder::command_queue->clear();
@@ -190,10 +186,8 @@ TEST(DataSrcClientsMgrTest, holder) {
     mgr.reconfigure(reconfigure_arg);
     {
         TestDataSrcClientsMgr::Holder holder(mgr);
-        EXPECT_NE(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::IN()));
-        EXPECT_EQ(static_cast<ConfigurableClientList*>(NULL),
-                  holder.findClientList(RRClass::CH()));
+        EXPECT_TRUE(holder.findClientList(RRClass::IN()));
+        EXPECT_FALSE(holder.findClientList(RRClass::CH()));
     }
 }