From: jonas Date: March 7 2007 11:14am Subject: bk commit into 5.1 tree (jonas:1.2427) List-Archive: http://lists.mysql.com/commits/21353 Message-Id: <20070307111427.66CD16CBA94@perch.ndb.mysql.com> Below is the list of changes that have just been committed into a local 5.1 repository of jonas. When jonas does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-03-07 12:14:22+01:00, jonas@stripped +6 -0 ndb - Add new interface to iterate over existing ndb objects using a Ndb_cluster_connection storage/ndb/include/ndbapi/ndb_cluster_connection.hpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +22 -0 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection storage/ndb/src/ndbapi/NdbImpl.hpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +2 -1 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection storage/ndb/src/ndbapi/Ndbinit.cpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +7 -1 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection storage/ndb/src/ndbapi/ndb_cluster_connection.cpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +71 -2 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +6 -0 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection storage/ndb/test/ndbapi/testNdbApi.cpp@stripped, 2007-03-07 12:14:20+01:00, jonas@stripped +59 -0 Add new interface to iterate over existing ndb object using a Ndb_cluster_connection # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: jonas # Host: perch.ndb.mysql.com # Root: /home/jonas/src/51-work --- 1.21/storage/ndb/src/ndbapi/NdbImpl.hpp 2007-03-07 12:14:27 +01:00 +++ 1.22/storage/ndb/src/ndbapi/NdbImpl.hpp 2007-03-07 12:14:27 +01:00 @@ -57,7 +57,8 @@ int send_event_report(Uint32 *data, Uint32 length); Ndb &m_ndb; - + Ndb * m_next_ndb_object, * m_prev_ndb_object; + Ndb_cluster_connection_impl &m_ndb_cluster_connection; TransporterFacade *m_transporter_facade; --- 1.44/storage/ndb/src/ndbapi/Ndbinit.cpp 2007-03-07 12:14:27 +01:00 +++ 1.45/storage/ndb/src/ndbapi/Ndbinit.cpp 2007-03-07 12:14:27 +01:00 @@ -119,6 +119,8 @@ } } + theImpl->m_ndb_cluster_connection.link_ndb_object(this); + DBUG_VOID_RETURN; } @@ -160,6 +162,8 @@ theCommitAckSignal = NULL; } + theImpl->m_ndb_cluster_connection.unlink_ndb_object(this); + delete theImpl; #ifdef POORMANSPURIFY @@ -199,7 +203,9 @@ theNdbObjectIdMap(m_transporter_facade->theMutexPtr, 1024,1024), theNoOfDBnodes(0), - m_ev_op(0) + m_ev_op(0), + m_next_ndb_object(0), + m_prev_ndb_object(0) { int i; for (i = 0; i < MAX_NDB_NODES; i++) { --- 1.24/storage/ndb/test/ndbapi/testNdbApi.cpp 2007-03-07 12:14:27 +01:00 +++ 1.25/storage/ndb/test/ndbapi/testNdbApi.cpp 2007-03-07 12:14:27 +01:00 @@ -1249,6 +1249,61 @@ return result; } +static +Uint32 +do_cnt(Ndb_cluster_connection* con) +{ + Uint32 cnt = 0; + const Ndb* p = 0; + con->lock_ndb_objects(); + while ((p = con->get_next_ndb_object(p)) != 0) cnt++; + con->unlock_ndb_objects(); + return cnt; +} + +int runCheckNdbObjectList(NDBT_Context* ctx, NDBT_Step* step) +{ + const NdbDictionary::Table* pTab = ctx->getTab(); + + Ndb_cluster_connection* con = &ctx->m_cluster_connection; + + Uint32 cnt1 = do_cnt(con); + Vector objs; + for (Uint32 i = 0; i<100; i++) + { + Uint32 add = 1 + (rand() % 5); + for (Uint32 j = 0; jm_cluster_connection, "TEST_DB"); + if (pNdb == NULL){ + ndbout << "pNdb == NULL" << endl; + return NDBT_FAILED; + } + objs.push_back(pNdb); + } + if (do_cnt(con) != (cnt1 + objs.size())) + return NDBT_FAILED; + } + + for (Uint32 i = 0; i<100 && objs.size(); i++) + { + Uint32 sub = 1 + rand() % objs.size(); + for (Uint32 j = 0; j; @@ -1341,6 +1396,10 @@ INITIALIZER(runLoadTable); INITIALIZER(runScan_4006); FINALIZER(runClearTable); +} +TESTCASE("CheckNdbObjectList", + ""){ + INITIALIZER(runCheckNdbObjectList); } NDBT_TESTSUITE_END(testNdbApi); --- 1.19/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp 2007-03-07 12:14:27 +01:00 +++ 1.20/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp 2007-03-07 12:14:27 +01:00 @@ -31,6 +31,8 @@ unsigned char cur_pos; }; +class Ndb; + /** * @class Ndb_cluster_connection * @brief Represents a connection to a cluster of storage nodes. @@ -99,6 +101,26 @@ int wait_until_ready(int timeout_for_first_alive, int timeout_after_first_alive); + /** + * Lock creation of ndb-objects + * Needed to iterate over created ndb objects + */ + void lock_ndb_objects(); + + /** + * Unlock creation of ndb-objects + */ + void unlock_ndb_objects(); + + /** + * Iterator of ndb-objects + * @param p Pointer to last returned ndb-object + * NULL - returns first object + * @note lock_ndb_objects should be used before using this function + * and unlock_ndb_objects should be used after + */ + const Ndb* get_next_ndb_object(const Ndb* p); + #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL int get_no_ready(); const char *get_connectstring(char *buf, int buf_sz) const; --- 1.47/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp 2007-03-07 12:14:27 +01:00 +++ 1.48/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp 2007-03-07 12:14:27 +01:00 @@ -267,14 +267,16 @@ m_name(0), m_run_connect_thread(0), m_event_add_drop_mutex(0), - m_latest_trans_gci(0) + m_latest_trans_gci(0), + m_first_ndb_object(0) { DBUG_ENTER("Ndb_cluster_connection"); DBUG_PRINT("enter",("Ndb_cluster_connection this=0x%lx", (long) this)); if (!m_event_add_drop_mutex) m_event_add_drop_mutex= NdbMutex_Create(); - + m_new_delete_ndb_mutex = NdbMutex_Create(); + g_eventLogger.createConsoleHandler(); g_eventLogger.setCategory("NdbApi"); g_eventLogger.enable(Logger::LL_ON, Logger::LL_ERROR); @@ -397,7 +399,74 @@ if (m_event_add_drop_mutex) NdbMutex_Destroy(m_event_add_drop_mutex); + NdbMutex_Destroy(m_new_delete_ndb_mutex); + m_new_delete_ndb_mutex = 0; + DBUG_VOID_RETURN; +} + +void +Ndb_cluster_connection::lock_ndb_objects() +{ + NdbMutex_Lock(m_impl.m_new_delete_ndb_mutex); +} + +void +Ndb_cluster_connection::unlock_ndb_objects() +{ + NdbMutex_Unlock(m_impl.m_new_delete_ndb_mutex); +} + +const Ndb* +Ndb_cluster_connection::get_next_ndb_object(const Ndb* p) +{ + if (p == 0) + return m_impl.m_first_ndb_object; + + return p->theImpl->m_next_ndb_object; +} + +void +Ndb_cluster_connection_impl::link_ndb_object(Ndb* p) +{ + lock_ndb_objects(); + if (m_first_ndb_object != 0) + { + m_first_ndb_object->theImpl->m_prev_ndb_object = p; + } + + p->theImpl->m_next_ndb_object = m_first_ndb_object; + m_first_ndb_object = p; + + unlock_ndb_objects(); +} + +void +Ndb_cluster_connection_impl::unlink_ndb_object(Ndb* p) +{ + lock_ndb_objects(); + Ndb* prev = p->theImpl->m_prev_ndb_object; + Ndb* next = p->theImpl->m_next_ndb_object; + + if (prev == 0) + { + assert(m_first_ndb_object == p); + m_first_ndb_object = next; + } + else + { + prev->theImpl->m_next_ndb_object = next; + } + + if (next) + { + next->theImpl->m_prev_ndb_object = prev; + } + + p->theImpl->m_prev_ndb_object = 0; + p->theImpl->m_next_ndb_object = 0; + + unlock_ndb_objects(); } void --- 1.9/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp 2007-03-07 12:14:27 +01:00 +++ 1.10/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp 2007-03-07 12:14:27 +01:00 @@ -28,6 +28,7 @@ class ConfigRetriever; class NdbThread; class ndb_mgm_configuration; +class Ndb; extern "C" { void* run_ndb_cluster_connection_connect_thread(void*); @@ -81,6 +82,11 @@ int m_run_connect_thread; NdbMutex *m_event_add_drop_mutex; Uint64 m_latest_trans_gci; + + NdbMutex* m_new_delete_ndb_mutex; + Ndb* m_first_ndb_object; + void link_ndb_object(Ndb*); + void unlink_ndb_object(Ndb*); }; #endif