/* * as_pg_roll_usage - rollup usage information * * IN pg_conn: database connection * IN sent_start: start time * IN sent_end: end time * IN archive_data: whether to archive usage data * RET: error code */ extern int as_pg_roll_usage(pgsql_conn_t *pg_conn, time_t sent_start, time_t sent_end, uint16_t archive_data) { int rc = SLURM_SUCCESS; if (check_db_connection(pg_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; slurm_mutex_lock(&usage_rollup_lock); FOR_EACH_CLUSTER(NULL) { rc |= _cluster_rollup_usage(pg_conn, cluster_name, sent_start, sent_end, archive_data); } END_EACH_CLUSTER; slurm_mutex_unlock(&usage_rollup_lock); return rc; }
extern int as_mysql_roll_usage(mysql_conn_t *mysql_conn, time_t sent_start, time_t sent_end, uint16_t archive_data) { int rc = SLURM_SUCCESS; int rolledup = 0; char *cluster_name = NULL; ListIterator itr; pthread_mutex_t rolledup_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t rolledup_cond; //DEF_TIMERS; if (check_connection(mysql_conn) != SLURM_SUCCESS) return ESLURM_DB_CONNECTION; slurm_mutex_lock(&usage_rollup_lock); slurm_mutex_init(&rolledup_lock); pthread_cond_init(&rolledup_cond, NULL); //START_TIMER; slurm_mutex_lock(&as_mysql_cluster_list_lock); itr = list_iterator_create(as_mysql_cluster_list); while ((cluster_name = list_next(itr))) { /* pthread_t rollup_tid; */ /* pthread_attr_t rollup_attr; */ local_rollup_t *local_rollup = xmalloc(sizeof(local_rollup_t)); local_rollup->archive_data = archive_data; local_rollup->cluster_name = cluster_name; local_rollup->mysql_conn = mysql_conn; local_rollup->rc = &rc; local_rollup->rolledup = &rolledup; local_rollup->rolledup_lock = &rolledup_lock; local_rollup->rolledup_cond = &rolledup_cond; local_rollup->sent_end = sent_end; local_rollup->sent_start = sent_start; /* _cluster_rollup_usage is responsible for freeing this local_rollup */ _cluster_rollup_usage(local_rollup); /* It turns out doing this with threads only buys a very small victory, and can skew the timings. So just doing them one after the other isn't too bad. If you really want to do this in threads you can just uncomment this, and comment the call above. */ /* slurm_attr_init(&rollup_attr); */ /* if (pthread_create(&rollup_tid, &rollup_attr, */ /* _cluster_rollup_usage, */ /* (void *)local_rollup)) */ /* fatal("pthread_create: %m"); */ /* slurm_attr_destroy(&rollup_attr); */ } slurm_mutex_lock(&rolledup_lock); list_iterator_destroy(itr); slurm_mutex_unlock(&as_mysql_cluster_list_lock); while (rolledup < list_count(as_mysql_cluster_list)) { pthread_cond_wait(&rolledup_cond, &rolledup_lock); debug2("Got %d rolled up", rolledup); } slurm_mutex_unlock(&rolledup_lock); debug2("Everything rolled up"); slurm_mutex_destroy(&rolledup_lock); pthread_cond_destroy(&rolledup_cond); /* END_TIMER; */ /* info("total time was %s", TIME_STR); */ slurm_mutex_unlock(&usage_rollup_lock); return rc; }