~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-06-20 03:05:30 UTC
  • mto: (1076.2.5 info-schema-plugin)
  • mto: This revision was merged to the branch mainline in revision 1073.
  • Revision ID: osullivan.padraig@gmail.com-20090620030530-d3tdkf9pbaoiv4i6
Created an I_S plugin. Extracted the PROCESSLIST table into this plugin and
removed any trace of it from show.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1081
1081
  return;
1082
1082
}
1083
1083
 
1084
 
int ProcessListISMethods::fillTable(Session* session, TableList* tables, COND*)
1085
 
{
1086
 
  Table *table= tables->table;
1087
 
  const CHARSET_INFO * const cs= system_charset_info;
1088
 
  char *user;
1089
 
  time_t now= time(NULL);
1090
 
  size_t length;
1091
 
 
1092
 
  if (now == (time_t)-1)
1093
 
    return 1;
1094
 
 
1095
 
  user= NULL;
1096
 
 
1097
 
  pthread_mutex_lock(&LOCK_thread_count);
1098
 
 
1099
 
  if (!session->killed)
1100
 
  {
1101
 
    Session* tmp;
1102
 
 
1103
 
    for( vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it )
1104
 
    {
1105
 
      tmp= *it;
1106
 
      Security_context *tmp_sctx= &tmp->security_ctx;
1107
 
      struct st_my_thread_var *mysys_var;
1108
 
      const char *val;
1109
 
 
1110
 
      if (! tmp->protocol->isConnected())
1111
 
        continue;
1112
 
 
1113
 
      table->restoreRecordAsDefault();
1114
 
      /* ID */
1115
 
      table->field[0]->store((int64_t) tmp->thread_id, true);
1116
 
      /* USER */
1117
 
      val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
1118
 
      table->field[1]->store(val, strlen(val), cs);
1119
 
      /* HOST */
1120
 
      table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1121
 
      /* DB */
1122
 
      if (tmp->db)
1123
 
      {
1124
 
        table->field[3]->store(tmp->db, strlen(tmp->db), cs);
1125
 
        table->field[3]->set_notnull();
1126
 
      }
1127
 
 
1128
 
      if ((mysys_var= tmp->mysys_var))
1129
 
        pthread_mutex_lock(&mysys_var->mutex);
1130
 
      /* COMMAND */
1131
 
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1132
 
        table->field[4]->store(val, strlen(val), cs);
1133
 
      else
1134
 
        table->field[4]->store(command_name[tmp->command].str,
1135
 
                               command_name[tmp->command].length, cs);
1136
 
      /* DRIZZLE_TIME */
1137
 
      table->field[5]->store((uint32_t)(tmp->start_time ?
1138
 
                                      now - tmp->start_time : 0), true);
1139
 
      /* STATE */
1140
 
      val= (char*) (tmp->protocol->isWriting() ?
1141
 
                    "Writing to net" :
1142
 
                    tmp->protocol->isReading() ?
1143
 
                    (tmp->command == COM_SLEEP ?
1144
 
                     NULL : "Reading from net") :
1145
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
1146
 
                    tmp->mysys_var &&
1147
 
                    tmp->mysys_var->current_cond ?
1148
 
                    "Waiting on cond" : NULL);
1149
 
      if (val)
1150
 
      {
1151
 
        table->field[6]->store(val, strlen(val), cs);
1152
 
        table->field[6]->set_notnull();
1153
 
      }
1154
 
 
1155
 
      if (mysys_var)
1156
 
        pthread_mutex_unlock(&mysys_var->mutex);
1157
 
 
1158
 
      length= strlen(tmp->process_list_info);
1159
 
 
1160
 
      if (length)
1161
 
      {
1162
 
        table->field[7]->store(tmp->process_list_info, length, cs);
1163
 
        table->field[7]->set_notnull();
1164
 
      }
1165
 
 
1166
 
      if (schema_table_store_record(session, table))
1167
 
      {
1168
 
        pthread_mutex_unlock(&LOCK_thread_count);
1169
 
        return(1);
1170
 
      }
1171
 
    }
1172
 
  }
1173
 
 
1174
 
  pthread_mutex_unlock(&LOCK_thread_count);
1175
 
  return(0);
1176
 
}
1177
 
 
1178
1084
/*****************************************************************************
1179
1085
  Status functions
1180
1086
*****************************************************************************/
4311
4217
};
4312
4218
 
4313
4219
 
4314
 
ColumnInfo processlist_fields_info[]=
4315
 
{
4316
 
  ColumnInfo("ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE),
4317
 
  ColumnInfo("USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE),
4318
 
  ColumnInfo("HOST", LIST_PROCESS_HOST_LEN,  DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4319
 
   SKIP_OPEN_TABLE),
4320
 
  ColumnInfo("DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE),
4321
 
  ColumnInfo("COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE),
4322
 
  ColumnInfo("TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE),
4323
 
  ColumnInfo("STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE),
4324
 
  ColumnInfo("INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4325
 
   SKIP_OPEN_TABLE),
4326
 
  ColumnInfo()
4327
 
};
4328
 
 
4329
 
 
4330
4220
ColumnInfo plugin_fields_info[]=
4331
4221
{
4332
4222
  ColumnInfo("PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4370
4260
static KeyColUsageISMethods key_col_usage_methods;
4371
4261
static OpenTablesISMethods open_tables_methods;
4372
4262
static PluginsISMethods plugins_methods;
4373
 
static ProcessListISMethods processlist_methods;
4374
4263
static RefConstraintsISMethods ref_constraints_methods;
4375
4264
static SchemataISMethods schemata_methods;
4376
4265
static StatsISMethods stats_methods;
4415
4304
                                     plugin_fields_info,
4416
4305
                                     -1, -1, false, false, 0,
4417
4306
                                     &plugins_methods);
4418
 
static InfoSchemaTable process_list_table("PROCESSLIST",
4419
 
                                          processlist_fields_info,
4420
 
                                          -1, -1, false, false, 0,
4421
 
                                          &processlist_methods);
4422
4307
static InfoSchemaTable ref_constrain_table("REFERENTIAL_CONSTRAINTS",
4423
4308
                                           referential_constraints_fields_info,
4424
4309
                                           1, 9, false, true, OPEN_TABLE_ONLY,
4477
4362
  key_col_usage_table,
4478
4363
  open_tab_table,
4479
4364
  plugins_table,
4480
 
  process_list_table,
4481
4365
  ref_constrain_table,
4482
4366
  schemata_table,
4483
4367
  sess_stat_table,