[Commits] Rev 4587: 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 17:34:02 EET 2013


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

------------------------------------------------------------
revno: 4587
revision-id: psergey at askmonty.org-20130201153402-4i4k4cneqk2ntf6g
parent: psergey at askmonty.org-20130201144452-3g0jmd4dkvlb9s3w
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: mysql-5.6-leveldb
timestamp: Fri 2013-02-01 19:34:02 +0400
message:
  MDEV-4122: LevelDB: store key/index numbers, not names
  - Support specifying AUTO_INCREMENT=... in CREATE TABLE, and ALTER TABLE .. AUTO_INCREMENT.
    The value is not persisent across table restarts, still.
=== modified file 'storage/leveldb/ha_leveldb.cc'
--- a/storage/leveldb/ha_leveldb.cc	2013-02-01 14:44:52 +0000
+++ b/storage/leveldb/ha_leveldb.cc	2013-02-01 15:34:02 +0000
@@ -520,12 +520,12 @@ static LEVELDB_SHARE *get_share(const ch
     share->table_name_length=length;
     share->table_name=tmp_name;
     strmov(share->table_name,table_name);
-    share->auto_incr_val= 1;
+    //share->auto_incr_val_= 1;
     if (my_hash_insert(&leveldb_open_tables, (uchar*) share))
       goto error;
     thr_lock_init(&share->lock);
-    mysql_mutex_init(ex_key_mutex_LEVELDB_SHARE_mutex,
-                     &share->mutex, MY_MUTEX_INIT_FAST);
+    //mysql_mutex_init(ex_key_mutex_LEVELDB_SHARE_mutex,
+    //                 &share->mutex, MY_MUTEX_INIT_FAST);
   }
   share->use_count++;
   mysql_mutex_unlock(&leveldb_mutex);
@@ -533,7 +533,7 @@ static LEVELDB_SHARE *get_share(const ch
   return share;
 
 error:
-  mysql_mutex_destroy(&share->mutex);
+ // mysql_mutex_destroy(&share->mutex);
   my_free(share);
 
   return NULL;
@@ -578,10 +578,10 @@ void ha_leveldb::update_auto_incr_val()
   dbug_tmp_restore_column_map(table->read_set, old_map);
 
   /* TODO: switch to compare-and-swap? */
-  mysql_mutex_lock(&share->mutex);
-  if (share->auto_incr_val < new_val)
-    share->auto_incr_val= new_val;
-  mysql_mutex_unlock(&share->mutex);
+  mysql_mutex_lock(&tbl_def->mutex);
+  if (tbl_def->auto_incr_val < new_val)
+    tbl_def->auto_incr_val= new_val;
+  mysql_mutex_unlock(&tbl_def->mutex);
 }
 
 
@@ -598,7 +598,7 @@ static int free_share(LEVELDB_SHARE *sha
   {
     my_hash_delete(&leveldb_open_tables, (uchar*) share);
     thr_lock_delete(&share->lock);
-    mysql_mutex_destroy(&share->mutex);
+    //mysql_mutex_destroy(&share->mutex);
     my_free(share);
   }
   mysql_mutex_unlock(&leveldb_mutex);
@@ -960,14 +960,18 @@ int ha_leveldb::create(const char *name,
   if ((res= create_key_defs(table_arg, strbuf.ptr(), strbuf.length())))
     DBUG_RETURN(res);
   
+  if (create_info->auto_increment_value)
+     tbl_def->auto_incr_val= create_info->auto_increment_value;
+
   /*
     We only support auto_increment at start of the PRIMARY KEY.
-  */ //TODO: this doesn't work (values are all zeros)
-  TABLE_SHARE *share= table_arg->s;
-  if (share->next_number_index != MAX_KEY)
-  {
-    if (share->next_number_index != share->primary_key ||
-        share->next_number_key_offset)
+  */ 
+  Field *field;
+  if ((field= table_arg->next_number_field))
+  {
+    int pk= table_arg->s->primary_key;
+    Field *pk_field= table_arg->key_info[pk].key_part[0].field;
+    if (field->field_index !=  pk_field->field_index)
       DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
   }
   DBUG_RETURN(0);
@@ -2214,7 +2218,9 @@ void ha_leveldb::update_create_info(HA_C
   if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
   {
     table->file->info(HA_STATUS_AUTO);
-   //TODO create_info->auto_increment_value= stats.auto_increment_value;
+    // TODO: the following is basic, we need to actually
+    //  store the specified value somewhere..
+    create_info->auto_increment_value= tbl_def->auto_incr_val;
   }
 }
 
@@ -2227,13 +2233,13 @@ void ha_leveldb::get_auto_increment(ulon
   if (!nb_desired_values)
     nb_desired_values= 1;
 
-  mysql_mutex_lock(&share->mutex);
+  mysql_mutex_lock(&tbl_def->mutex);
   // TODO: increment??
-  *first_value= share->auto_incr_val;
+  *first_value= tbl_def->auto_incr_val;
   *nb_reserved_values= nb_desired_values;
-  share->auto_incr_val += nb_desired_values;
+  tbl_def->auto_incr_val += nb_desired_values;
 
-  mysql_mutex_unlock(&share->mutex);
+  mysql_mutex_unlock(&tbl_def->mutex);
 
 #if 0
   ha_heap::info(HA_STATUS_AUTO);

=== modified file 'storage/leveldb/ha_leveldb.h'
--- a/storage/leveldb/ha_leveldb.h	2013-02-01 14:44:52 +0000
+++ b/storage/leveldb/ha_leveldb.h	2013-02-01 15:34:02 +0000
@@ -36,10 +36,10 @@
 typedef struct st_leveldb_share {
   char *table_name;
   uint table_name_length,use_count;
-  mysql_mutex_t mutex;
+  //mysql_mutex_t mutex;
   THR_LOCK lock;
 
-  longlong auto_incr_val;
+  //longlong auto_incr_val_;
 } LEVELDB_SHARE;
 
 class LDBSE_KEYDEF;

=== modified file 'storage/leveldb/ldb_datadic.cc'
--- a/storage/leveldb/ldb_datadic.cc	2013-02-01 14:44:52 +0000
+++ b/storage/leveldb/ldb_datadic.cc	2013-02-01 15:34:02 +0000
@@ -981,6 +981,7 @@ bool Table_ddl_manager::rename(uchar *fr
 
   new_rec->dbname_tablename.append((char*)to, to_len);
   new_rec->n_keys= rec->n_keys;
+  new_rec->auto_incr_val= rec->auto_incr_val;
   new_rec->key_descr= rec->key_descr;
   rec->key_descr= NULL; /* so that it's not free'd when deleting the old rec */
 

=== modified file 'storage/leveldb/ldb_datadic.h'
--- a/storage/leveldb/ldb_datadic.h	2013-02-01 14:44:52 +0000
+++ b/storage/leveldb/ldb_datadic.h	2013-02-01 15:34:02 +0000
@@ -139,9 +139,13 @@ class LDBSE_KEYDEF
 class LDBSE_TABLE_DEF
 {
 public:
-  LDBSE_TABLE_DEF() : key_descr(NULL) {}
+  LDBSE_TABLE_DEF() : key_descr(NULL), auto_incr_val(1)
+  {
+    mysql_mutex_init(0, &mutex, MY_MUTEX_INIT_FAST);
+  }
   ~LDBSE_TABLE_DEF()
   {
+    mysql_mutex_destroy(&mutex);
     /* Don't free key definitions */
     if (key_descr)
       my_free(key_descr);
@@ -151,6 +155,9 @@ class LDBSE_TABLE_DEF
 
   uint n_keys;
   LDBSE_KEYDEF **key_descr;
+  
+  mysql_mutex_t mutex; // guards the following:
+  longlong auto_incr_val;
 
   void write_to(leveldb::DB *ldb_dict);
 };



More information about the commits mailing list