本文整理汇总了C++中DB_HOST::enumerate方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_HOST::enumerate方法的具体用法?C++ DB_HOST::enumerate怎么用?C++ DB_HOST::enumerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_HOST
的用法示例。
在下文中一共展示了DB_HOST::enumerate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scan_db
void HR_INFO::scan_db() {
DB_HOST host;
int retval;
int i, n=0;
double sum=0, sum_sqr=0;
while (1) {
retval = host.enumerate("where expavg_credit>1");
if (retval) break;
if (host.p_fpops > 1e7 && host.p_fpops < 1e13) {
n++;
sum += host.p_fpops;
sum_sqr += host.p_fpops*host.p_fpops;
}
//printf("host %d: %s | %s | %s\n", host.id, host.os_name, host.p_vendor, host.p_model);
for (i=1; i<HR_NTYPES; i++) {
if (hr_unknown_class(host, i)) {
//printf("type %d: unknown\n", i);
continue;
}
int hrc = hr_class(host, i);
//printf("type %d: class %d\n", i, hrc);
if (!hrc) continue;
rac_per_class[i][hrc] += host.expavg_credit;
}
}
if (retval != ERR_DB_NOT_FOUND) {
fprintf(stderr, "host enum: %d", retval);
exit(1);
}
}
示例2: scan_hosts
// handle timed-out hosts
//
bool scan_hosts() {
DB_HOST h;
char buf[256];
int retval;
bool found = false;
sprintf(buf, "where cpu_efficiency < %f", dtime());
while (1) {
retval = h.enumerate(buf);
if (retval == ERR_DB_NOT_FOUND) break;
if (retval) {
log_messages.printf(MSG_CRITICAL, "host.enumerate() failed\n");
exit(1);
}
found = true;
retval = handle_host(h);
if (retval) {
log_messages.printf(MSG_CRITICAL, "handle_host() failed: %d\n", retval);
exit(1);
}
retval = h.update_field("cpu_efficiency=1e12");
if (retval) {
log_messages.printf(MSG_CRITICAL, "h.update_field() failed: %d\n", retval);
exit(1);
}
}
return found;
}
示例3: update_hosts
int update_hosts() {
DB_HOST host;
int retval;
char buf[256];
while (1) {
retval = host.enumerate("where expavg_credit>0.1");
if (retval) {
if (retval != ERR_DB_NOT_FOUND) {
log_messages.printf(MSG_CRITICAL, "lost DB conn\n");
exit(1);
}
break;
}
if (host.expavg_time > update_time_cutoff) continue;
update_average(0, 0, CREDIT_HALF_LIFE, host.expavg_credit, host.expavg_time);
sprintf(
buf,"expavg_credit=%f, expavg_time=%f",
host.expavg_credit, host.expavg_time
);
retval = host.update_field(buf);
if (retval) {
log_messages.printf(MSG_CRITICAL, "Can't update host %d\n", host.id);
return retval;
}
}
return 0;
}
示例4: main
int main() {
if ( boinc_db.open("predictor", "boinc", NULL, NULL) ) {
printf("Open failed\n");
return 0;
}
DB_WORKUNIT workunit;
char buf[256];
while (!workunit.enumerate()) {
printf("workunit %d wsn %d\n", workunit.id, workunit.workseq_next);
DB_RESULT result;
sprintf(buf, "where workunitid=%d", workunit.id);
if ( !result.enumerate(buf) ) {
DB_HOST host;
sprintf(buf, "where id=%d", result.hostid);
if ( !host.enumerate(buf) ) {
workunit.workseq_next = OS(host) + CPU(host);
if ( workunit.update() ) printf("Update failed!\n");
}
}
}
};
示例5: find_host_by_cpid
// find the user's most recently-created host with given host CPID
//
static bool find_host_by_cpid(DB_USER& user, char* host_cpid, DB_HOST& host) {
char buf[1024], buf2[256];
sprintf(buf, "%s%s", host_cpid, user.email_addr);
md5_block((const unsigned char*)buf, strlen(buf), buf2);
sprintf(buf,
"where userid=%d and host_cpid='%s' order by id desc", user.id, buf2
);
if (!host.enumerate(buf)) {
host.end_enumerate();
return true;
}
return false;
}
示例6: find_host_by_other
// find the user's most recently-created host with given various characteristics
//
static bool find_host_by_other(DB_USER& user, HOST req_host, DB_HOST& host) {
char buf[2048];
char dn[512], ip[512], os[512], pm[512];
// don't dig through hosts of these users
// prevents flooding the DB with slow queries from users with many hosts
//
for (unsigned int i=0; i < config.dont_search_host_for_userid.size(); i++) {
if (user.id == config.dont_search_host_for_userid[i]) {
return false;
}
}
// Only check if all the fields are populated
//
if (strlen(req_host.domain_name) && strlen(req_host.last_ip_addr) && strlen(req_host.os_name) && strlen(req_host.p_model)) {
safe_strcpy(dn, req_host.domain_name);
escape_string(dn, sizeof(dn));
safe_strcpy(ip, req_host.last_ip_addr);
escape_string(ip, sizeof(ip));
safe_strcpy(os, req_host.os_name);
escape_string(os, sizeof(os));
safe_strcpy(pm, req_host.p_model);
escape_string(pm, sizeof(pm));
sprintf(buf,
"where userid=%d and id>%d and domain_name='%s' and last_ip_addr = '%s' and os_name = '%s' and p_model = '%s'"
" and m_nbytes = %lf order by id desc", user.id, req_host.id, dn, ip, os, pm, req_host.m_nbytes
);
if (!host.enumerate(buf)) {
host.end_enumerate();
return true;
}
}
return false;
}
示例7: choose_host
// Pick a host to send a chunk of this file to.
// The host must:
// 1) be alive (recent RPC time)
// 2) not have any chunks of this file
//
// We maintain a cache of such hosts
// The policy is:
//
// - scan the cache, removing hosts that are no longer alive;
// return if find a live host
// - pick a random starting point in host ID space,
// and enumerate 100 live hosts; wrap around if needed.
// Return one and put the rest in cache
//
int VDA_FILE_AUX::choose_host() {
int retval;
DB_HOST host;
return 467;
// replenish cache if needed
//
if (!available_hosts.size()) {
int nhosts_scanned = 0;
int rand_id;
for (int i=0; i<2; i++) {
char buf[256];
if (i == 0) {
retval = host.max_id(rand_id, "");
if (retval) {
log_messages.printf(MSG_CRITICAL, "host.max_id() failed\n");
return 0;
}
rand_id = (int)(((double)id)*drand());
sprintf(buf,
"where %s and id>=%d order by id limit 100",
host_alive_clause(), rand_id
);
} else {
sprintf(buf,
"where %s and id<%d order by id limit %d",
host_alive_clause(), rand_id, 100-nhosts_scanned
);
}
while (1) {
retval = host.enumerate(buf);
if (retval == ERR_DB_NOT_FOUND) break;
if (retval) {
log_messages.printf(MSG_CRITICAL, "host enum failed\n");
return 0;
}
nhosts_scanned++;
DB_VDA_CHUNK_HOST ch;
char buf2[256];
int count;
sprintf(buf2, "where vda_file_id=%d and host_id=%d", id, host.id);
#if 0
retval = ch.count(count, buf2);
if (retval) {
log_messages.printf(MSG_CRITICAL, "ch.count failed\n");
return 0;
}
#else
count = 0;
#endif
if (count == 0) {
available_hosts.push_back(host.id);
}
if (nhosts_scanned == 100) break;
}
if (nhosts_scanned == 100) break;
}
}
while (available_hosts.size()) {
int hostid = available_hosts.back();
available_hosts.pop_back();
retval = host.lookup_id(hostid);
if (retval || !alive(host)) {
continue;
}
return hostid;
}
log_messages.printf(MSG_CRITICAL, "No hosts available\n");
return 0;
}