From: John David Duncan Date: April 7 2011 12:00am Subject: bzr push into mysql-5.1-telco-7.2 branch (john.duncan:4151 to 4152) List-Archive: http://lists.mysql.com/commits/134879 Message-Id: <201104070001.p3701LB3005875@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4152 John David Duncan 2011-04-06 Use genhash instead of std::map in configuration. modified: storage/ndb/memcache/include/Configuration.h storage/ndb/memcache/src/Configuration.cc 4151 John David Duncan 2011-04-05 [merge] Merge removed: storage/ndb/memcache/src/schedulers/Dispatch.cc storage/ndb/memcache/src/schedulers/Dispatch.h storage/ndb/memcache/src/schedulers/flex.cc storage/ndb/memcache/src/schedulers/flex.h added: storage/ndb/memcache/src/schedulers/Flex.cc storage/ndb/memcache/src/schedulers/Flex.h storage/ndb/memcache/src/schedulers/Flex_broker.cc storage/ndb/memcache/src/schedulers/Flex_broker.h storage/ndb/memcache/src/schedulers/Flex_cluster.cc storage/ndb/memcache/src/schedulers/Flex_cluster.h storage/ndb/memcache/src/schedulers/Flex_thread_spec.h modified: storage/ndb/memcache/Makefile.am storage/ndb/memcache/README storage/ndb/memcache/include/ClusterConnectionPool.h storage/ndb/memcache/include/NdbInstance.h storage/ndb/memcache/include/Operation.h storage/ndb/memcache/include/QueryPlan.h storage/ndb/memcache/include/Scheduler.h storage/ndb/memcache/include/ndb_pipeline.h storage/ndb/memcache/include/ndb_worker.h storage/ndb/memcache/include/ndbmemcache_global.h storage/ndb/memcache/include/workitem.h storage/ndb/memcache/scripts/metadata.sql storage/ndb/memcache/src/Configuration.cc storage/ndb/memcache/src/NdbInstance.cc storage/ndb/memcache/src/ndb_engine.c storage/ndb/memcache/src/ndb_pipeline.cc storage/ndb/memcache/src/ndb_worker.cc storage/ndb/memcache/src/schedulers/3thread.cc storage/ndb/memcache/src/schedulers/3thread.h storage/ndb/memcache/src/schedulers/Stockholm.cc storage/ndb/memcache/src/schedulers/Stockholm.h storage/ndb/memcache/src/workitem.c storage/ndb/memcache/unit/Makefile.am storage/ndb/memcache/xcode/ndbmemcache.xcodeproj/project.pbxproj === modified file 'storage/ndb/memcache/include/Configuration.h' --- a/storage/ndb/memcache/include/Configuration.h 2011-03-30 06:54:53 +0000 +++ b/storage/ndb/memcache/include/Configuration.h 2011-04-06 23:52:36 +0000 @@ -25,7 +25,6 @@ #endif #include -#include #include @@ -124,12 +123,6 @@ class Configuration { }; -/* strless is a function object used for std::map */ -class strless { -public: bool operator()(char *s1, char *s2) { return strcmp(s1, s2) < 0; }; -}; - - class config_v0 { public: /* Methods */ @@ -161,16 +154,13 @@ private: void set_initial_cas(); /* Private instance variables */ - /* Uses std::map, but actually just needs an unordered hash table. */ Configuration &conf; int server_role_id; - Uint64 signon_gci; - - std::map cluster_ids; - std::map::const_iterator cluster_ids_iterator; - std::map policies; - std::map::const_iterator policies_iterator; - genhash_t *containers; + Uint64 signon_gci; + int nclusters; + int cluster_ids[MAX_CLUSTERS]; + genhash_t *policies_map; + genhash_t *containers_map; }; /* Inline methods */ === modified file 'storage/ndb/memcache/src/Configuration.cc' --- a/storage/ndb/memcache/src/Configuration.cc 2011-04-06 04:31:28 +0000 +++ b/storage/ndb/memcache/src/Configuration.cc 2011-04-06 23:52:36 +0000 @@ -385,7 +385,11 @@ bool config_v0::read_configuration() { bool config_v1::read_configuration() { DEBUG_ENTER(); - containers = genhash_init(10, str_hash_ops); + nclusters = 0; + for(int i = 0 ; i < MAX_CLUSTERS ; i++) cluster_ids[i] = 0; + + containers_map = genhash_init(10, str_hash_ops); + policies_map = genhash_init(10, str_dup_hash_ops); bool success = false; server_role_id = get_server_role_id(); @@ -474,45 +478,45 @@ bool config_v1::get_policies() { success = false; } while((res = scan->nextResult((const char **) &op.buffer, true, false) == 0)) { - /* Add the policy to the internal map */ + prefix_info_t * info = (prefix_info_t *) calloc(1, sizeof(prefix_info_t)); char name[41]; // `policy_name` VARCHAR(40) NOT NULL op.copyValue(COL_STORE_KEY, name); - prefix_info_t info = policies[strdup(name)]; /* copy the name */ /* ENUM('cache_only','ndb_only','caching','disabled') NOT NULL is: 1 2 3 4 */ unsigned int get_policy = op.getIntValue(COL_STORE_VALUE+0); assert((get_policy > 0) && (get_policy < 5)); - if(get_policy == 1 || get_policy == 3) info.do_mc_read = 1; - if(get_policy == 2 || get_policy == 3) info.do_db_read = 1; + if(get_policy == 1 || get_policy == 3) info->do_mc_read = 1; + if(get_policy == 2 || get_policy == 3) info->do_db_read = 1; unsigned int set_policy = op.getIntValue(COL_STORE_VALUE+1); assert((set_policy > 0) && (set_policy < 5)); - if(set_policy == 1 || set_policy == 3) info.do_mc_write = 1; - if(set_policy == 2 || set_policy == 3) info.do_db_write = 1; + if(set_policy == 1 || set_policy == 3) info->do_mc_write = 1; + if(set_policy == 2 || set_policy == 3) info->do_db_write = 1; unsigned int del_policy = op.getIntValue(COL_STORE_VALUE+2); assert((del_policy > 0) && (del_policy < 5)); - if(del_policy == 1 || del_policy == 3) info.do_mc_delete = 1; - if(del_policy == 2 || del_policy == 3) info.do_db_delete = 1; + if(del_policy == 1 || del_policy == 3) info->do_mc_delete = 1; + if(del_policy == 2 || del_policy == 3) info->do_db_delete = 1; /* `flush_from_db` ENUM('false', 'true') NOT NULL DEFAULT 'false' is: 1 2 */ int flush_policy = op.getIntValue(COL_STORE_VALUE+3); - if(flush_policy == 2) info.do_db_flush = 1; + if(flush_policy == 2) info->do_db_flush = 1; + + DEBUG_PRINT("%s: get-%d set-%d del-%d flush-%d addr-%p", + name, get_policy, set_policy, del_policy, flush_policy, info); - DEBUG_PRINT("%s: get-%d set-%d del-%d flush-%d", - name, get_policy, set_policy, del_policy, flush_policy); + genhash_store(policies_map, name, strlen(name), info, sizeof(prefix_info_t *)); - policies[name] = info; } if(res == -1) { logger->log(LOG_WARNING, 0, scan->getNdbError().message); success = false; } - DEBUG_PRINT("map size: %d", policies.size()); + DEBUG_PRINT("map size: %d", genhash_size(policies_map)); tx->close(); @@ -569,14 +573,14 @@ bool config_v1::get_connections() { DEBUG_PRINT("[%d]: { %d => \"%s\" [rtt: %d]}", connection_idx, cfg_data_id, str_is_null ? "" : connectstring, rtt); - /* Add an item to the metadata_id => connection_index map */ - cluster_ids[cfg_data_id] = connection_idx; + nclusters++; + cluster_ids[connection_idx] = cfg_data_id; } if(res == -1) { logger->log(LOG_WARNING, 0, scan->getNdbError().message); success = false; } - DEBUG_PRINT("map size: %d", cluster_ids.size()); + DEBUG_PRINT("clusters: %d", nclusters); tx->close(); return success; } @@ -585,10 +589,10 @@ bool config_v1::get_connections() { TableSpec * config_v1::get_container(char *name) { TableSpec *c; - c = (TableSpec *) genhash_find(containers, name, strlen(name)); + c = (TableSpec *) genhash_find(containers_map, name, strlen(name)); if(c == NULL) { c = get_container_record(name); - genhash_store(containers, name, strlen(name), c, sizeof(TableSpec)); + genhash_store(containers_map, name, strlen(name), c, sizeof(TableSpec)); } else { DEBUG_PRINT("\"%s\" found in local map (\"%s\").", name, c->table_name); @@ -770,16 +774,18 @@ bool config_v1::store_prefix(const char char *cache_policy) { DEBUG_PRINT("%s", name); KeyPrefix prefix(name); - - policies_iterator = policies.find(cache_policy); - if(policies_iterator == policies.end()) { + prefix_info_t * info_ptr; + + info_ptr = (prefix_info_t *) genhash_find(policies_map, + cache_policy, strlen(cache_policy)); + if(info_ptr == 0) { /* policy from key_prefixes doesn't exist in cache_policies */ logger->log(LOG_WARNING, 0, "Invalid cache policy \"%s\" named in " "key prefix \"%s\"\n", cache_policy, name); return false; } - prefix.info = (*policies_iterator).second; + memcpy(& prefix.info, info_ptr, sizeof(prefix_info_t)); if(prefix.info.do_db_read || prefix.info.do_db_write || prefix.info.do_db_delete || prefix.info.do_db_flush) { @@ -806,15 +812,20 @@ bool config_v1::store_prefix(const char } /* The cluster_id must refer to a known cluster: */ - cluster_ids_iterator = cluster_ids.find(cluster_id); - if(cluster_ids_iterator == cluster_ids.end()) { + int internal_cluster_idx = -1; + for(int i = 0 ; i < nclusters ; i++) + if(cluster_ids[i] == cluster_id) + internal_cluster_idx = i; + + if(internal_cluster_idx == -1) { logger->log(LOG_WARNING, 0, "Error at key prefix \"%s\": cluster_id %d " - "does not exist in ndb_clusters table.\n", name, cluster_id); - return false; + "does not exist in ndb_clusters table.\n", + name, cluster_id); + return false; } - + /* Tie it all together */ - prefix.info.cluster_id = (*cluster_ids_iterator).second; + prefix.info.cluster_id = internal_cluster_idx; prefix.table = table; prefix.info.usable = 1; @@ -823,6 +834,7 @@ bool config_v1::store_prefix(const char */ prefix.info.prefix_id = conf.storePrefix(prefix); + return true; } No bundle (reason: useless for push emails).