From 20b52e669118bac8f86c71b71d9a4aa00029e02c Mon Sep 17 00:00:00 2001
From: Zardosht Kasheff <zardosht@tokutek.com>
Date: Wed, 17 Apr 2013 00:02:11 -0400
Subject: [PATCH] [t:4920], in ha_tokudb.cc, protect indexer->close and
 indexer->abort with shanre->num_DBs_lock

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@44159 c7de825b-a66e-492c-adef-691d508d4ae1
---
 storage/tokudb/ha_tokudb.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/storage/tokudb/ha_tokudb.cc b/storage/tokudb/ha_tokudb.cc
index 20678ba21a4..cf1e2308da0 100644
--- a/storage/tokudb/ha_tokudb.cc
+++ b/storage/tokudb/ha_tokudb.cc
@@ -3896,7 +3896,7 @@ int ha_tokudb::write_row(uchar * record) {
         }
     }
     
-    txn = create_sub_trans ? sub_trans : transaction;    
+    txn = create_sub_trans ? sub_trans : transaction;
 
     if (tokudb_debug & TOKUDB_DEBUG_CHECK_KEY) {
         test_row_packing(record,&prim_key,&row);
@@ -7484,7 +7484,9 @@ int ha_tokudb::tokudb_add_index(
         error = indexer->build(indexer);
         if (error) { goto cleanup; }
 
+        rw_wrlock(&share->num_DBs_lock);
         error = indexer->close(indexer);
+        rw_unlock(&share->num_DBs_lock);
         if (error) { goto cleanup; }
         indexer = NULL;
     }
@@ -7660,7 +7662,9 @@ int ha_tokudb::tokudb_add_index(
     if (indexer != NULL) {
         sprintf(status_msg, "aborting creation of indexes.");
         thd_proc_info(thd, status_msg);
+        rw_wrlock(&share->num_DBs_lock);
         indexer->abort(indexer);
+        rw_unlock(&share->num_DBs_lock);
     }
     if (error == DB_LOCK_NOTGRANTED && ((tokudb_debug & TOKUDB_DEBUG_HIDE_DDL_LOCK_ERRORS) == 0)) {
         sql_print_error("Could not add indexes to table %s because \
-- 
2.30.9