Esempio n. 1
0
bool CheckUnqiueAndPrimaryKey(const TableInfo& table, const std::vector<std::string>& values){
  IndexManager index_manager;
  RecordManager record_manager;
  std::vector<std::string> attributes_to_be_checked;
  attributes_to_be_checked = table.unique();
  attributes_to_be_checked.push_back(table.primary_key());

  for (auto it : attributes_to_be_checked){
    int attribute_index = table.attribute_index(it);

    if (!table.attribute(it).index_names().empty()){//has index
      std::string index_name = table.attribute(it).index_names().at(0);
      IndexInfo index_info(index_name, table.table_name(), it);
      if (index_manager.FindValue(table,index_info,values.at(attribute_index))){ // has value
        return false;
      }
    }
    else{
      WhereClause where;
      where.kColumnName = it;
      where.kOperator ="=";
      where.kCondition = values.at(attribute_index);
      if (!record_manager.FindRecordsWithNoIndex(table,where).empty()){
        return false;
      }
    }
  }
  return true;
}
Esempio n. 2
0
/*
 * Print info about atom tables
 */
void atom_info(int to, void *to_arg)
{
    int lock = !ERTS_IS_CRASH_DUMPING;
    if (lock)
	atom_read_lock();
    index_info(to, to_arg, &erts_atom_table);
    if (lock)
	atom_read_unlock();
}
Esempio n. 3
0
Info API::CreateIndex(SqlCommandCreateIndex* command){
  IndexManager index_manager;
  CatalogManager catalog_manager;
  RecordManager record_manager;
  std::string index_name = command->index_name();
  std::string attribute_name = command->column_name();
  std::string table_name = command->table_name();

  if (catalog_manager.HasIndex(index_name)){
    std::string error_info;
    error_info = "Index \"" + index_name + "\" already exists.";
    return Info(error_info);
  }
  if (!catalog_manager.HasTable(table_name)){
    std::string error_info;
    error_info = "table \"" + table_name + "\" not exists.";
    return Info(error_info);
  }
  TableInfo table = catalog_manager.GetTableInfo(table_name);

  if(!table.HasAttribute(attribute_name)){
    std::string error_info;
    error_info = "attribute \"" + attribute_name + "\" not exists.";
    return Info(error_info);
  }
  if (!table.attribute(attribute_name).is_unique() && !table.attribute(attribute_name).is_primary_key()){
    std::string error_info;
    error_info = "attribute \"" + attribute_name + "\" is not an unique attribute.";
    return Info(error_info);
  }
  else{
    IndexInfo index_info(index_name, table_name, attribute_name);
    //create index in index manager
    if(index_manager.CreateIndex(table.attribute(attribute_name).type(),table.attribute(attribute_name).length(), index_info)){
      auto all_records = record_manager.SelectAllRecords(table);

      for (auto record : all_records){
          if(!index_manager.AddRecord(table,index_info,record.first.at(table.attribute_index(index_info.attribute_name())),record.second)){
          return Info("Update index failed.");
        }
      }
      if (!catalog_manager.RegisterIndex(index_info))
      {
        return Info("Register Index failed.");
      }
      //update table info in catalog manager
      table.add_index(attribute_name, index_name);
      catalog_manager.WriteTableInfo(table);
      return Info();
    }
    else{
      return Info("Create index failed.");
    }
  }
}
bool raw_index_info::CreateIndex(void) const {
  IndexInfo index_info(index_name, index_oid, table_name, method_type,
                       constraint_type, unique_keys, key_column_names);

  bool status = DDLIndex::CreateIndex(index_info);

  if (status == false) {
    elog(ERROR, "Could not create index \"%s\" in Peloton", index_name.c_str());
  }

  return status;
}
Esempio n. 5
0
File: atom.c Progetto: AlainODea/otp
/*
 * Print info about atom tables
 */
void atom_info(int to, void *to_arg)
{
    int lock = !ERTS_IS_CRASH_DUMPING;
    if (lock)
	atom_read_lock();
    index_info(to, to_arg, &erts_atom_table);
#ifdef ERTS_ATOM_PUT_OPS_STAT
    erts_print(to, to_arg, "atom_put_ops: %ld\n",
	       erts_smp_atomic_read(&atom_put_ops));
#endif

    if (lock)
	atom_read_unlock();
}
Esempio n. 6
0
void
export_info(int to, void *to_arg)
{
#ifdef ERTS_SMP
    int lock = !ERTS_IS_CRASH_DUMPING;
    if (lock)
	export_staging_lock();
#endif
    index_info(to, to_arg, &export_tables[erts_active_code_ix()]);
    hash_info(to, to_arg, &export_tables[erts_staging_code_ix()].htable);
#ifdef ERTS_SMP
    if (lock)
	export_staging_unlock();
#endif
}
Esempio n. 7
0
void module_info(int to, void *to_arg)
{
    index_info(to, to_arg, &module_table);
}
Esempio n. 8
0
/*
 * This is the function called from the main polling loop.
 *
 * It calls command functions to get strings of data, and sends them to the server.
 *
*/
int collect_and_send_metrics(int cycle) {
	int retval;
	char* command;
	
	StringInfoData commands;
	
	pgstat_report_activity(STATE_RUNNING, "Collecting metrics");
	
	initStringInfo(&commands);
	/*
	 * Populate first cycle command data.	These are executed on the first cycle
	 *	 of a restart.	The bgworker restars every N cycles, as listed at the bottom
	 *	 of the main loop in pgsampler.c.	
	 */
	if (cycle == 0) {
	
		command = restart_gucs();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("restart_gucs", command);			
		pfree(command);

		command = relation_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_class", command);
		pfree(command);

		command = database_list();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("databases", command);
		pfree(command);
		
		command = column_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("columns", command);
		pfree(command);

		command = index_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("indexes", command);
		pfree(command);

		command = column_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_column", command);
		pfree(command);

		command = db_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_database", command);
		pfree(command);

	}

	/* HEARTBEAT */
	if (cycle % heartbeat_seconds == 0) {
		command = heartbeat();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("heartbeats", command);
		pfree(command);
	}

	/* SYSTEM INFO */
	if (cycle % system_seconds == 0) {
		command = system_info();	
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_system", command);
		pfree(command);

		command = fs_info();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_filesystem", command);
		pfree(command);
	}

	/* */
	if (cycle % activity_seconds == 0) {
		command = activity_stats(); 
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_activity", command);
		pfree(command);
	}

	if (cycle % replication_seconds == 0) {
		command = replication_stats(); 
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_replication", command);
		pfree(command);
	}

	/*	*/
	if (cycle % bgwriter_seconds == 0) {
		command = bgwriter_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_bgwriter", command);
		pfree(command);
	}
	
	if (cycle % guc_seconds == 0) {
		command = transient_gucs();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("transient_gucs", command);
		pfree(command);
	}
	
	if (cycle % statements_seconds == 0) {
		command = stat_statements();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_statements", command);
		pfree(command);
	}

	/* */	
	if (cycle % relation_seconds == 0) {
		command = table_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_table", command);
		pfree(command);
		
		command = index_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_index", command);
		pfree(command);
		
		command = table_io_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("statio_user_tables", command);
		pfree(command);

		command = index_io_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("statio_user_indexes", command);
		pfree(command);

		command = function_stats();
		appendStringInfoString(&commands, command);
		if (strcmp(output_mode, "csv") == 0) 
			write_to_csv("stat_function", command);
		pfree(command);
	}



	/* Send / Write metrics based on output_mode */
	if (strcmp(output_mode, "network") == 0) {
		pgstat_report_activity(STATE_RUNNING, "Sending metrics to antenna");
		retval = send_data(commands.data);
		if (retval == NO_DATA_SENT) { //close socket and retry establishing connection and sending data.
		 	// elog(LOG, "reseting..."); //just a note to say reseting socket
			if (sockfd != 0) 
				shutdown(sockfd, SHUT_RDWR);

			sockfd = 0;
			retval = send_data(commands.data); // we ignore success or failure here.	drops data if fails.
		}
	}

	return 0;
}
Esempio n. 9
0
    void set_format(const hold_string_type & format) {
        // format too big
        BOOST_ASSERT( format.size() < 64);
        m_format.clear();

        m_day = -1; m_month = -1; m_yy = -1; m_yyyy = -1; m_hour = -1; m_min = -1; m_sec = -1;m_millisec = -1;m_microsec = -1;m_nanosec = -1;

        typedef hold_string_type::size_type uint;
        uint day_idx    = format.find(BOOST_LOG_STR("$dd"));
        uint month_idx  = format.find(BOOST_LOG_STR("$MM"));
        uint yy_idx     = format.find(BOOST_LOG_STR("$yy"));
        uint yyyy_idx   = format.find(BOOST_LOG_STR("$yyyy"));
        uint hour_idx   = format.find(BOOST_LOG_STR("$hh"));
        uint min_idx    = format.find(BOOST_LOG_STR("$mm"));
        uint sec_idx    = format.find(BOOST_LOG_STR("$ss"));
        uint millisec_idx    = format.find(BOOST_LOG_STR("$mili"));
        uint microsec_idx    = format.find(BOOST_LOG_STR("$micro"));
        uint nanosec_idx    = format.find(BOOST_LOG_STR("$nano"));

        typedef std::vector<index_info> array;
        array indexes;
        if ( day_idx != hold_string_type::npos)
            indexes.push_back( index_info(day_idx, &m_day) );
        if ( month_idx != hold_string_type::npos)
            indexes.push_back( index_info(month_idx, &m_month) );

        if ( yy_idx != hold_string_type::npos || yyyy_idx != hold_string_type::npos) {
            if ( yyyy_idx  != hold_string_type::npos)
                indexes.push_back( index_info(yyyy_idx, &m_yyyy, 4) );
            else
                indexes.push_back( index_info(yy_idx, &m_yy) );
        }

        if ( hour_idx != hold_string_type::npos)
            indexes.push_back( index_info(hour_idx, &m_hour ) );
        if ( min_idx != hold_string_type::npos)
            indexes.push_back( index_info(min_idx, &m_min) );
        if ( sec_idx != hold_string_type::npos)
            indexes.push_back( index_info(sec_idx, &m_sec) );
        if ( millisec_idx != hold_string_type::npos)
            indexes.push_back( index_info(millisec_idx, &m_millisec, 4, 3) );
        if ( microsec_idx != hold_string_type::npos)
            indexes.push_back( index_info(microsec_idx, &m_microsec, 5, 6) );
        if ( nanosec_idx != hold_string_type::npos)
            indexes.push_back( index_info(nanosec_idx, &m_nanosec, 4, 9) );

        std::sort( indexes.begin(), indexes.end(), index_info::by_index);
        
        // create the format string, that we can actually pass to sprintf 
        uint prev_idx = 0;
        int idx = 0;
        for ( array::iterator begin = indexes.begin(), end = indexes.end(); begin != end; ++begin) {
            m_format += format.substr( prev_idx, begin->src_idx - prev_idx);
            *begin->format_idx = idx;
            std::basic_ostringstream<char_type> cur_sprintf_format;
            cur_sprintf_format << BOOST_LOG_STR("%0") << begin->size << BOOST_LOG_STR("d");
            m_format += cur_sprintf_format.str();
            prev_idx = begin->src_idx + begin->advance_size + 1;
            ++idx;
        }

        m_format += format.substr(prev_idx);
    }
Esempio n. 10
0
void module_info(fmtfn_t to, void *to_arg)
{
    index_info(to, to_arg, &module_tables[erts_active_code_ix()]);
}