[Commits] Rev 4585: MDEV-4122: LevelDB: store key/index numbers, not names in file:///home/psergey/dev2/mysql-5.6-leveldb/

Sergey Petrunya psergey at askmonty.org
Fri Feb 1 15:37:48 EET 2013


At file:///home/psergey/dev2/mysql-5.6-leveldb/

------------------------------------------------------------
revno: 4585
revision-id: psergey at askmonty.org-20130201133747-eqmzcu1ivj0msm6u
parent: psergey at askmonty.org-20130201133037-nc555rilct4v9yg7
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: mysql-5.6-leveldb
timestamp: Fri 2013-02-01 17:37:47 +0400
message:
  MDEV-4122: LevelDB: store key/index numbers, not names
  - Wrap Table_ddl_manager in read/write locks.
    (just to get it to work safely. Perhaps, we'll move to memcmp'able 
     keys and this whole class will go away).
=== modified file 'storage/leveldb/ldb_datadic.cc'
--- a/storage/leveldb/ldb_datadic.cc	2013-02-01 13:30:37 +0000
+++ b/storage/leveldb/ldb_datadic.cc	2013-02-01 13:37:47 +0000
@@ -841,6 +841,7 @@ void Table_ddl_manager::free_hash_elem(v
 
 bool Table_ddl_manager::init(leveldb::DB *ldb_dict, Keydef_store *keydef_store)
 {
+  mysql_rwlock_init(0, &rwlock);
   (void) my_hash_init(&ddl_hash, /*system_charset_info*/&my_charset_bin, 32,0,0,
                       (my_hash_get_key) Table_ddl_manager::get_hash_key,
                       Table_ddl_manager::free_hash_elem, 0);
@@ -910,11 +911,17 @@ bool Table_ddl_manager::init(leveldb::DB
 }
 
 
-LDBSE_TABLE_DEF* Table_ddl_manager::find(uchar *table_name, uint table_name_len)
+LDBSE_TABLE_DEF* Table_ddl_manager::find(uchar *table_name, 
+                                         uint table_name_len, 
+                                         bool lock)
 {
   LDBSE_TABLE_DEF *rec;
+  if (lock)
+    mysql_rwlock_rdlock(&rwlock);
   rec= (LDBSE_TABLE_DEF*)my_hash_search(&ddl_hash, (uchar*)table_name,
                                         table_name_len);
+  if (lock)
+    mysql_rwlock_unlock(&rwlock);
   return rec;
 }
 
@@ -924,19 +931,20 @@ LDBSE_TABLE_DEF* Table_ddl_manager::find
 int Table_ddl_manager::put(LDBSE_TABLE_DEF *tbl)
 {
   LDBSE_TABLE_DEF *rec;
+  my_bool result;
+
+  mysql_rwlock_wrlock(&rwlock);
   rec= (LDBSE_TABLE_DEF*)find((uchar*)tbl->dbname_tablename.c_ptr(),
-                               tbl->dbname_tablename.length());
+                               tbl->dbname_tablename.length(), false);
   if (rec)
   {
     // this will free the old record.
     my_hash_delete(&ddl_hash, (uchar*) rec);
   }
+  result= my_hash_insert(&ddl_hash, (uchar*)tbl);
 
-  if (my_hash_insert(&ddl_hash, (uchar*)tbl))
-  {
-    return 1;
-  }
-  return 0;
+  mysql_rwlock_unlock(&rwlock);
+  return result;
 }
 
 
@@ -953,5 +961,6 @@ void Table_ddl_manager::remove(LDBSE_TAB
 void Table_ddl_manager::cleanup()
 {
   my_hash_free(&ddl_hash);
+  mysql_rwlock_destroy(&rwlock);
 }
 

=== modified file 'storage/leveldb/ldb_datadic.h'
--- a/storage/leveldb/ldb_datadic.h	2013-02-01 13:30:37 +0000
+++ b/storage/leveldb/ldb_datadic.h	2013-02-01 13:37:47 +0000
@@ -230,12 +230,13 @@ class Keydef_store 
 class Table_ddl_manager
 {
   HASH ddl_hash; // Contains LDBSE_TABLE_DEF elements
+  mysql_rwlock_t rwlock;
 public:
   bool init(leveldb::DB *ldb_dict, Keydef_store *keydef_store);
   void cleanup();
   int put(LDBSE_TABLE_DEF *key_descr);
   void remove(LDBSE_TABLE_DEF *rec, leveldb::DB *ldb_dict);
-  LDBSE_TABLE_DEF *find(uchar *table_name, uint len);
+  LDBSE_TABLE_DEF *find(uchar *table_name, uint len, bool lock=true);
 
 private:
   static uchar* get_hash_key(LDBSE_TABLE_DEF *rec, size_t *length,



More information about the commits mailing list