[Commits] Rev 4583: 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 14:36:00 EET 2013


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

------------------------------------------------------------
revno: 4583
revision-id: psergey at askmonty.org-20130201123559-w6rler9dilc7fo66
parent: psergey at askmonty.org-20130201101208-tmts96q8d5jk8rmv
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: mysql-5.6-leveldb
timestamp: Fri 2013-02-01 16:35:59 +0400
message:
  MDEV-4122: LevelDB: store key/index numbers, not names
  - Support proper DROP TABLE. After this patch, it should be ok
    to DROP a table and then do a CREATE TABLE with a different DDL.
=== modified file 'storage/leveldb/ha_leveldb.cc'
--- a/storage/leveldb/ha_leveldb.cc	2013-02-01 10:12:08 +0000
+++ b/storage/leveldb/ha_leveldb.cc	2013-02-01 12:35:59 +0000
@@ -2062,13 +2062,12 @@ int ha_leveldb::external_lock(THD *thd, 
   this->table==NULL, pk_key_descr==NULL, etc. 
 
   tablename points to line in form "./dbname/tablename".
-  
-  We store keys in leveldb in form 'dbname.tablename\0'.
 */
 
 int ha_leveldb::delete_table(const char *tablename)
 {
   DBUG_ENTER("ha_leveldb::delete_table");
+
   DBUG_ASSERT(tablename[0] == '.' && tablename[1] == '/');
   tablename += 2;
 
@@ -2082,33 +2081,47 @@ int ha_leveldb::delete_table(const char 
     }
   }
   /* Note: this will delete all indexes, primary and secondary */
-  StringBuffer<512> strbuf;
+  StringBuffer<256> strbuf;
   strbuf.append(tablename, p - tablename);
   strbuf.append('.');
   strbuf.append(p + 1);
 
-  /*
-    psergey-todo: should handle possible crashes in the middle of the following
-    loop:
-  */
+  /* Find the table in the hash */
+  LDBSE_TABLE_DEF *tbl;
+  if (!(tbl= ddl_manager.find((uchar*)strbuf.c_ptr(), strbuf.length())))
+    DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
+
   leveldb::Iterator* it= ldb->NewIterator(leveldb::ReadOptions());
-  leveldb::Slice table_key(strbuf.c_ptr_safe(), strbuf.length());
-  it->Seek(table_key);
-  while (it->Valid())
+  
+  char key_buf[MAX_KEY_LENGTH];
+  uint key_len;
+  /* 
+    Remove all records in each index 
+    psergey-todo: should handle possible crashes in the middle of the loop.
+  */
+  for (uint i= 0; i < tbl->n_keys ; i++)
   {
-    leveldb::Slice key= it->key();
-    if (key.size() < table_key.size() || 
-        memcmp(key.data(), table_key.data(), table_key.size()))
+    tbl->key_descr[i]->get_infimum_key((uchar*)key_buf, &key_len);
+
+    leveldb::Slice table_key(key_buf, key_len);
+    it->Seek(table_key);
+    while (it->Valid())
     {
-      /* Got a key that's not from this table. Stop the scan */
-      break;
+      leveldb::Slice key= it->key();
+      if (!tbl->key_descr[i]->in_table(key.data(), key.size()))
+        break;
+      ldb->Delete(leveldb::WriteOptions(), key);
+      it->Next();
     }
-    ldb->Delete(leveldb::WriteOptions(), key);
-
-    it->Next();
   }
   delete it;
 
+  /* 
+    Remove the table entry in data dictionary (this will also remove it from
+    the persistent data dictionary).
+  */
+  ddl_manager.remove(tbl, ldb_dict);
+
   DBUG_RETURN(0);
 }
 

=== modified file 'storage/leveldb/ldb_datadic.cc'
--- a/storage/leveldb/ldb_datadic.cc	2013-02-01 10:12:08 +0000
+++ b/storage/leveldb/ldb_datadic.cc	2013-02-01 12:35:59 +0000
@@ -858,7 +858,8 @@ bool Table_ddl_manager::init(leveldb::DB
     
     if (val.size() < LDBSE_KEYDEF::INDEX_NUMBER_SIZE)
     {
-      sql_print_error("LevelDB: Table_store: no keys defined in %s", key.data());
+      sql_print_error("LevelDB: Table_store: no keys defined in %*s",
+                      key.size(), key.data());
       return true;
     }
     if (val.size() % LDBSE_KEYDEF::INDEX_NUMBER_SIZE)
@@ -932,10 +933,13 @@ int Table_ddl_manager::put(LDBSE_TABLE_D
 }
 
 
-void Table_ddl_manager::remove(LDBSE_TABLE_DEF *tbl)
+void Table_ddl_manager::remove(LDBSE_TABLE_DEF *tbl, leveldb::DB *ldb_dict)
 {
+  leveldb::Slice tkey(tbl->dbname_tablename.ptr(), tbl->dbname_tablename.length());
+  ldb_dict->Delete(leveldb::WriteOptions(), tkey); 
+
+  /* The following will also delete the object: */
   my_hash_delete(&ddl_hash, (uchar*) tbl);
-  delete tbl;
 }
 
 

=== modified file 'storage/leveldb/ldb_datadic.h'
--- a/storage/leveldb/ldb_datadic.h	2013-02-01 10:12:08 +0000
+++ b/storage/leveldb/ldb_datadic.h	2013-02-01 12:35:59 +0000
@@ -139,6 +139,13 @@ class LDBSE_KEYDEF
 class LDBSE_TABLE_DEF
 {
 public:
+  LDBSE_TABLE_DEF() : key_descr(NULL) {}
+  ~LDBSE_TABLE_DEF()
+  {
+    /* Don't free key definitions */
+    if (key_descr)
+      my_free(key_descr);
+  }
   /* Stores 'dbname.tablename' */
   StringBuffer<64> dbname_tablename;
 
@@ -225,7 +232,7 @@ class Table_ddl_manager
   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);
+  void remove(LDBSE_TABLE_DEF *rec, leveldb::DB *ldb_dict);
   LDBSE_TABLE_DEF *find(uchar *table_name, uint len);
 
 private:



More information about the commits mailing list