0

Rubyを使用してデータベースにファイルをロードしようとしています。約15 Mbの大きなファイルです...しばらくの間、レコードを適切にコピーしました....しかし、いくつかのレコードをコピーした後、エラーはありませんが、データベースにレコードを挿入しません....別のコンソールでMsqlプロンプトに接続すると...エラーが発生します:

mysql> desc testdb2.test_descriptions;
ERROR 2006 (HY000): MySQL server has gone away                                                                                                                                                                                                                                 
No connection. Trying to reconnect...                                                                                                                                                                                                                                          
Connection id:    52

この後、Mysqlデータベースに接続できます.......そして、スクリプトがデータベースへのレコードの書き込みを開始します.....

アプリの実行中にデータベースとの接続を維持する方法はありますか?

それがタイムアウトの問題なのか何かなのかわかりません....私を修正してください....

def simulate_datasets
    Log.initialize

      data_folders = ["Jun_06_2013"];
      data_folders.each do |data_folder|

        add(data_folder);
      end
      render :text => Log.dump
  end

def add (data_folder)
     @dataset  = Dataset.initialize
     @dataset.created_at=Date.new(2013,06,06)
     @dataset.save

     current_root = "script/datasets/"+data_folder+"/"
     strip_string = "/development/A/"
     population_time = {}
     total_time = 0

     clusters = Cluster.find(:all, :order=>"created_at DESC");
     if clusters.empty?
       Log.info "No Clusters found"
       Cluster.initialize
       clusters = Cluster.find(:all, :order=>"created_at DESC");
     end

     clusters.each do |cluster|
        cluster_path = cluster.path
        root = current_root + cluster.name+'/' 
        total_time += populate_file_or_folder(root+"fileListWithMLintMetrics.txt", cluster_path)
     end

end            

populate_file_or_folder メソッドを使用してデータベースに入力しています

mysql> show variables like '%time%';
+----------------------------+-------------------+
| Variable_name              | Value             |
+----------------------------+-------------------+
| connect_timeout            | 10                |
| datetime_format            | %Y-%m-%d %H:%i:%s |
| delayed_insert_timeout     | 300               |
| flush_time                 | 0                 |
| innodb_lock_wait_timeout   | 50                |
| innodb_rollback_on_timeout | OFF               |
| interactive_timeout        | 28800             |
| lc_time_names              | en_US             |
| long_query_time            | 10.000000         |
| net_read_timeout           | 30                |
| net_write_timeout          | 60                |
| slave_net_timeout          | 3600              |
| slow_launch_time           | 2                 |
| system_time_zone           | EDT               |
| table_lock_wait_timeout    | 50                |
| time_format                | %H:%i:%s          |
| time_zone                  | SYSTEM            |
| timed_mutexes              | OFF               |
| timestamp                  | 1372869659        |
| wait_timeout               | 28800             |
+----------------------------+-------------------+
20 rows in set (0.00 sec)

def self.populate_file_or_folder(fileName, cluster_path)

    counter = 0                                                      
    # Reading directly from the CSV library
    CSV.foreach(fileName) do |line|
      counter = counter+1
      completePath = line[0]                                                
      completePath = cluster_path+ '/'+completePath

   newStructure = FileOrFolder.new
    newStructure.fullpath = path
    pathbits = path.split('/')
    newStructure.name = pathbits.last
    newStructure.save
    end
  end
4

0 に答える 0