ceph/branches/riccardo/monitor2/test/rushtest.cc
riccardo80 07ac5d3e74 creating branch for distributed monitor
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1068 29311d96-e01e-0410-9327-a35deaab8ce9
2007-02-01 05:43:23 +00:00

50 lines
1.1 KiB
C++

//
// $Id$
//
#include <stdio.h>
#include <stdlib.h>
#include "../osd/rush.h"
main (int argc, char *argv[])
{
Rush rush;
char buf[200];
int i, j, k, numClusters;
int numKeys = 5;
int numReplicas = 4;
int curSize;
double curWeight;
int servers[1000];
if (argc > 1) {
numKeys = atoi (argv[1]);
}
if (argc > 2) {
numReplicas = atoi (argv[2]);
}
fgets (buf, sizeof (buf) - 2, stdin);
sscanf (buf, "%d", &numClusters);
for (i = 0; i < numClusters; i++) {
fgets (buf, sizeof (buf) - 2, stdin);
sscanf (buf, "%d %lf", &curSize, &curWeight);
rush.AddCluster (curSize, curWeight);
if (rush.Servers () < numReplicas) {
fprintf (stderr, "ERROR: must have at least %d disks in the system!\n",
rush.Clusters ());
exit (-1);
}
for (j = 0; j < numKeys; j++) {
rush.GetServersByKey (j, numReplicas, servers);
#if 0
printf ("%-3d %-6d ", i, j);
for (k = 0; k < numReplicas; k++) {
printf ("%-5d ", servers[k]);
}
putchar ('\n');
#endif
}
}
}