diff --git a/c/rt.c b/c/rt.c index 484ea28..6ff9d79 100755 --- a/c/rt.c +++ b/c/rt.c @@ -1,6 +1,8 @@ -//Wiby slave replication server tracker +//Wiby replication server tracker //Admin creates file 'servers.csv' containing only IP and database name, one per line -//Tracker will check status of slave databases by attempting to connect to all listed every few seconds +//When executing, include the expected number of search results per page (eg: ./rt 12) so that a +//divisible list of available servers is allocated to the core application by the tracker. +//Tracker will check status of replica databases by attempting to connect to all listed every few seconds //Tracker will create a copy of this file called 'res.csv' and display only the confirmed online servers //as well as ID ranges divided across all servers so each has the same number of rows. @@ -38,11 +40,30 @@ void handle_error(MYSQL *con) fclose(error); mysql_close(con); } +int isnum(char *source){ + int sourcelength = strlen(source); + for(int i=0;i < sourcelength; i++){ + if(source[i] < 48 || source[i] > 57){ + return 0; + } + } + return 1; +} int main(int argc, char **argv) { - int timetest=0,reportinit=0,running=0; - printf("\nStarting Replication Tracker:\n\nConnection Latency\n--------------------------------\n"); + int timetest=0,reportinit=0,running=0,pagelim=12; + if(argc == 2 && isnum(argv[1])==1){ + pagelim=atoi(argv[1]); + printf("\nStarting Replication Tracker:\n--------------------------------"); + }else{ + printf("\nStarting Replication Tracker:\n--------------------------------"); + printf("\n\nNo page limit was set, will use a default of 12.\n\nUsage: rt page_limit\n\nWhere page_limit is the expected number of search results per page."); + printf("\nMake sure you have setup servers.csv, see the install guide for more info."); + } + + printf("\n\nConnection Latency\n--------------------------------\n"); + while(1) { long bytecount=0; @@ -97,6 +118,7 @@ int main(int argc, char **argv) memset(resfiletext,0,10000); //conect to each listed server and verify it works + int last=0; for (i=0;ionlineServers){ + //compute number of servers to harness + while(pagelim % coreAssigned != 0){ + coreAssigned--; + } + }else if(pagelim