[xiph-commits] r11930 - trunk/icecast2yp/src
oddsock at svn.xiph.org
oddsock at svn.xiph.org
Fri Oct 20 13:12:36 PDT 2006
Author: oddsock
Date: 2006-10-20 13:12:35 -0700 (Fri, 20 Oct 2006)
New Revision: 11930
Modified:
trunk/icecast2yp/src/yp_clean.c
trunk/icecast2yp/src/yp_routines.c
Log:
commit of performance enhancements for the yp directory.
Modified: trunk/icecast2yp/src/yp_clean.c
===================================================================
--- trunk/icecast2yp/src/yp_clean.c 2006-10-20 13:48:32 UTC (rev 11929)
+++ trunk/icecast2yp/src/yp_clean.c 2006-10-20 20:12:35 UTC (rev 11930)
@@ -96,7 +96,7 @@
memset(sql, '\000', sizeof(sql));
- sprintf(sql,"SELECT id FROM servers_touch");
+ sprintf(sql,"SELECT id FROM server_details");
if(mysql_real_query(&dbase,sql,strlen(sql))) {
strcpy(error, mysql_error(&dbase));
return(YP_ERROR);
@@ -128,15 +128,6 @@
row2 = mysql_fetch_row(result2);
if (row2[0]) {
if (atoi(row2[0]) == 0) {
- sprintf(sql,"delete from servers_touch where id = '%s'", row[0]);
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers: %s", mysql_error(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- mysql_free_result(result);
- mysql_free_result(result2);
- return(YP_ERROR);
- }
sprintf(sql,"delete from server_details where parent_id = %s", parent_id);
if (mysql_real_query(&dbase,sql,strlen(sql))) {
sprintf(error, "servers: %s", mysql_error(&dbase));
@@ -192,31 +183,6 @@
row = mysql_fetch_row(result);
if (row[0]) {
sprintf(id, "%s-%s", row[1], row[0]);
- sprintf(sql,"SELECT count(*) FROM servers_touch where id = '%s'", id);
- if(mysql_real_query(&dbase,sql,strlen(sql))) {
- strcpy(error, mysql_error(&dbase));
- return(YP_ERROR);
- }
- result2 = mysql_store_result(&dbase);
- nrows2 = mysql_num_rows(result2);
- if(nrows2 != 0) {
- row2 = mysql_fetch_row(result2);
- if (row2[0]) {
- if (atoi(row2[0]) == 0) {
- sprintf(sql,"delete from server_details where id = '%s'", row[0]);
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers: %s", mysql_error(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- mysql_free_result(result);
- mysql_free_result(result2);
- return(YP_ERROR);
- }
- LogMessage(LOG_INFO, "Server Details (%s)(%s) because it didn't have a record (%s) in servers_touch", row[0], row[1], id);
- }
- }
- }
- mysql_free_result(result2);
sprintf(sql,"SELECT count(*) FROM servers where id = %s", row[1]);
if(mysql_real_query(&dbase,sql,strlen(sql))) {
strcpy(error, mysql_error(&dbase));
@@ -439,7 +405,7 @@
memset(sql, '\000', sizeof(sql));
- sprintf(sql,"select id from servers_touch where last_touch < NOW() - INTERVAL 5 MINUTE");
+ sprintf(sql,"select id, parent_id from server_details where last_touch < NOW() - INTERVAL 5 MINUTE");
if(mysql_real_query(&dbase,sql,strlen(sql))) {
strcpy(error, mysql_error(&dbase));
return(YP_ERROR);
@@ -455,11 +421,15 @@
if (row[0]) {
memset(parent_id, '\000', sizeof(parent_id));
memset(detail_id, '\000', sizeof(detail_id));
+ strcpy(detail_id, row[0]);
+ strcpy(parent_id, row[1]);
+ /*
p1 = strchr(row[0], '-');
if (p1) {
strncpy(parent_id, row[0], p1-row[0]);
strcpy(detail_id, p1+1);
}
+ */
sprintf(sql,"delete from server_details where id = '%s'", detail_id);
if (mysql_real_query(&dbase,sql,strlen(sql))) {
@@ -489,14 +459,6 @@
else {
Log(LOG_DEBUG, "Yep, so lets NOT delete the parent...");
}
-
- sprintf(sql,"delete from servers_touch where id = '%s'", row[0]);
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers: %s", mysql_error(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- return(YP_ERROR);
- }
}
}
mysql_free_result(result);
@@ -517,7 +479,7 @@
memset(error, '\000', sizeof(error));
- setErrorType(LM_INFO);
+ setErrorType(LM_ERROR);
setLogFile(YP_LOGDIR"yp-clean.log");
if (connectToDB()) {
Modified: trunk/icecast2yp/src/yp_routines.c
===================================================================
--- trunk/icecast2yp/src/yp_routines.c 2006-10-20 13:48:32 UTC (rev 11929)
+++ trunk/icecast2yp/src/yp_routines.c 2006-10-20 20:12:35 UTC (rev 11930)
@@ -712,7 +712,8 @@
bitrate, \
listeners, \
samplerate, \
- channels) \
+ channels, \
+ last_touch) \
values (%s, \
'%s', \
'%s', \
@@ -729,7 +730,8 @@
'%s', \
0, \
'%s', \
- '%s')", parent_id, server_name_esc, listing_ip, desc_esc, genre_esc, sid, cluster_password_esc, url_esc, "", listenurl_esc, cluster_id, server_type_esc, server_subtype_esc, bitrate_esc, samplerate_esc, channels_esc);
+ '%s', \
+ NOW())", parent_id, server_name_esc, listing_ip, desc_esc, genre_esc, sid, cluster_password_esc, url_esc, "", listenurl_esc, cluster_id, server_type_esc, server_subtype_esc, bitrate_esc, samplerate_esc, channels_esc);
Log(LOG_DEBUG, sql);
if (mysql_real_query(&dbase,sql,strlen(sql))) {
sprintf(error, "servers: %s", mysql_error(&dbase));
@@ -747,17 +749,6 @@
setLogSid(sid);
- Log(LOG_DEBUG, "Going to insert into servers_touch now...");
- sprintf(sql,"insert into servers_touch (id, server_name, listing_ip, last_touch) values ('%s', '%s', '%s', NOW())", sid, server_name_esc, listing_ip);
-
- Log(LOG_DEBUG, sql);
-
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers_info: %s", mysql_error(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- return(YP_ERROR);
- }
sprintf(sql,"COMMIT");
mysql_real_query(&dbase,sql,strlen(sql));
Log(LOG_DEBUG, "Everything is good");
@@ -865,134 +856,64 @@
strcpy(detail_id, p1+1);
}
- sprintf(sql,"select listing_ip from servers_touch where id = \'%s\'",sid);
- if(mysql_real_query(&dbase,sql,strlen(sql))) {
- strcpy(error, mysql_error(&dbase));
+ song_esc = malloc(strlen(song)*2 + 1);
+ memset(song_esc, '\000', strlen(song)*2 + 1);
+ mysql_real_escape_string(&dbase, song_esc, song, strlen(song));
+
+ server_subtype_esc = malloc(strlen(server_subtype)*2 + 1);
+ memset(server_subtype_esc, '\000', strlen(server_subtype)*2 + 1);
+ mysql_real_escape_string(&dbase, server_subtype_esc, server_subtype, strlen(server_subtype));
+
+ sprintf(sql,"update server_details set current_song = \'%s\', server_subtype = \'%s\', last_touch = NOW() where id = %s and listing_ip = '%s'", song_esc, server_subtype_esc, detail_id, touchip);
+
+ Log(LOG_DEBUG, sql);
+ if (mysql_real_query(&dbase,sql,strlen(sql))) {
+ sprintf(error, "servers: %s", mysql_error(&dbase));
+ Log(LOG_ERROR, error);
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
goto TouchError;
}
- result = mysql_store_result(&dbase);
- nrows = mysql_num_rows(result);
- if(nrows == 0) {
+ if (mysql_affected_rows(&dbase) <= 0) {
+ // something squirly...
+ sprintf(error, "Error updating server info, %d records updated", mysql_affected_rows(&dbase));
+ Log(LOG_INFO, error);
+ sprintf(sql,"ROLLBACK");
+ mysql_real_query(&dbase,sql,strlen(sql));
goto TouchError;
}
- else {
- row = mysql_fetch_row(result);
- if (row[0]) {
- if (strcmp(touchip, row[0])) {
- strcpy(error, "trying to touch from a different IP than was added");
- return(YP_ERROR);
- }
- }
- mysql_free_result(result);
- song_esc = malloc(strlen(song)*2 + 1);
- memset(song_esc, '\000', strlen(song)*2 + 1);
- mysql_real_escape_string(&dbase, song_esc, song, strlen(song));
+ sprintf(sql,"COMMIT");
+ mysql_real_query(&dbase,sql,strlen(sql));
- server_subtype_esc = malloc(strlen(server_subtype)*2 + 1);
- memset(server_subtype_esc, '\000', strlen(server_subtype)*2 + 1);
- mysql_real_escape_string(&dbase, server_subtype_esc, server_subtype, strlen(server_subtype));
-
- sprintf(sql,"update server_details set current_song = \'%s\', server_subtype = \'%s\', listeners = %d where id = %s", song_esc, server_subtype_esc, atol(listeners), detail_id);
-
- Log(LOG_DEBUG, sql);
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers: %s", mysql_error(&dbase));
- Log(LOG_ERROR, error);
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- goto TouchError;
- }
- if (mysql_affected_rows(&dbase) < 0) {
- // something squirly...
- sprintf(error, "Error updating server info, %d records updated", mysql_affected_rows(&dbase));
- Log(LOG_ERROR, error);
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- goto TouchError;
- }
-
- sprintf(sql,"update servers_touch set last_touch = NOW() where id = '%s'", sid);
-
- Log(LOG_DEBUG, sql);
-
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers_touch: %s", mysql_error(&dbase));
- Log(LOG_ERROR, error);
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- goto TouchError;
- }
- if (mysql_affected_rows(&dbase) < 0) {
- // something squirly...
- sprintf(error, "Error updating server touch info, %d records updated", mysql_affected_rows(&dbase));
- Log(LOG_ERROR, error);
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- goto TouchError;
- }
- sprintf(sql,"COMMIT");
- mysql_real_query(&dbase,sql,strlen(sql));
-
-
- sprintf(sql,"select sum(listeners) from server_details where parent_id = %s",parent_id);
- if(mysql_real_query(&dbase,sql,strlen(sql))) {
- strcpy(error, mysql_error(&dbase));
- goto TouchError;
- }
- result = mysql_store_result(&dbase);
- nrows = mysql_num_rows(result);
- if(nrows == 0) {
- goto TouchError;
- }
- else {
- row = mysql_fetch_row(result);
- if (row[0]) {
- sprintf(sql,"update servers set listeners = %s where id = %s", row[0], parent_id);
-
- Log(LOG_DEBUG, sql);
-
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers_touch: %s", mysql_error(&dbase));
- Log(LOG_ERROR, error);
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- goto TouchError;
- }
- }
- }
-
- mysql_free_result(result);
-
- Log(LOG_DEBUG, "YP Touched");
- if (song_esc) {
- free(song_esc);
- }
- if (genre_esc) {
- free(genre_esc);
- }
- if (listenurl_esc) {
- free(listenurl_esc);
- }
- if (server_type_esc) {
- free(server_type_esc);
- }
- if (server_subtype_esc) {
- free(server_subtype_esc);
- }
- if (bitrate_esc) {
- free(bitrate_esc);
- }
- if (desc_esc) {
- free(desc_esc);
- }
- if (server_name_esc) {
- free(server_name_esc);
- }
- endTime = GetCurrentTime();
- //Log(LOG_ERROR, "TOUCH: %f", endTime - startTime);
- return(YP_TOUCHED);
+ Log(LOG_DEBUG, "YP Touched");
+ if (song_esc) {
+ free(song_esc);
}
+ if (genre_esc) {
+ free(genre_esc);
+ }
+ if (listenurl_esc) {
+ free(listenurl_esc);
+ }
+ if (server_type_esc) {
+ free(server_type_esc);
+ }
+ if (server_subtype_esc) {
+ free(server_subtype_esc);
+ }
+ if (bitrate_esc) {
+ free(bitrate_esc);
+ }
+ if (desc_esc) {
+ free(desc_esc);
+ }
+ if (server_name_esc) {
+ free(server_name_esc);
+ }
+ endTime = GetCurrentTime();
+ //Log(LOG_ERROR, "TOUCH: %f", endTime - startTime);
+ return(YP_TOUCHED);
TouchError:
if (song_esc) {
free(song_esc);
@@ -1045,7 +966,7 @@
memset(sql, '\000', sizeof(sql));
- sprintf(sql,"select listing_ip from servers_touch where id = '%s'",sid);
+ sprintf(sql,"select listing_ip from server_details where id = '%s'",detail_id);
if(mysql_real_query(&dbase,sql,strlen(sql))) {
strcpy(error, mysql_error(&dbase));
return(YP_ERROR);
@@ -1127,21 +1048,6 @@
Log(LOG_DEBUG, "Yep, so lets NOT delete the parent...");
}
- sprintf(sql,"delete from servers_touch where id = '%s'", sid);
-
- if (mysql_real_query(&dbase,sql,strlen(sql))) {
- sprintf(error, "servers_info: %s", mysql_error(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- return(YP_ERROR);
- }
- if (mysql_affected_rows(&dbase) < 0) {
- // something squirly...
- sprintf(error, "Error removing server info, %d records deleted", mysql_affected_rows(&dbase));
- sprintf(sql,"ROLLBACK");
- mysql_real_query(&dbase,sql,strlen(sql));
- return(YP_ERROR);
- }
sprintf(sql,"COMMIT");
mysql_real_query(&dbase,sql,strlen(sql));
return(YP_TOUCHED);
@@ -1178,10 +1084,11 @@
if (type == ICECAST2_RESPONSE) {
if (strlen(msg) == 0) {
printf("YPResponse: 0\r\nYPMessage: NAK\r\n\r\n", errorcode);
- Log(LOG_DEBUG, "Sending NAK");
+ Log(LOG_INFO, "Sending NAK");
}
else {
printf("YPResponse: %d\r\nYPMessage: %s\r\n\r\n", errorcode, msg);
+ Log(LOG_INFO, "Sending %s", msg);
}
}
}
More information about the commits
mailing list