int main(int argc, char **argv)
{
  if(argc==1){
	printf("Usage: %s <ketama.servers file>\n", *argv);
	return 1;
  }

  ketama_continuum c;
  serverinfo* serverinfo;
  ketama_roll( &c, *++argv, serverinfo );

  printf( "%s\n", ketama_error() );

  int i;
  for ( i = 0; i < 1000000; i++ )
  {
    char k[10];
    sprintf( k, "%d", i );
    unsigned int kh = ketama_hashi( k );
    mcs* m = ketama_get_server( k, c );

    printf( "%u %u %s\n", kh, m->point, m->ip );
  }
  ketama_smoke(c);
  return 0;
}
Exemple #2
0
static int pyketama_Continuum_init(PyObject *self, PyObject *args,
        PyObject *kwds) {
    char *filename;
    pyketama_Continuum *pkc = (pyketama_Continuum *)self;

    if (!PyArg_ParseTuple(args, "s", &filename)) {
        return -1;
    }

    /* libketama doesn't really handle long filenames. */
    if (strlen(filename) > 255) {
        PyErr_SetString(PyExc_ValueError,
            "filename must not be over 255 bytes long");
        return -1;
    }

    /* I'm not entirely sure if you need this, but I do it. */
    if(!(pkc->filename = strdup(filename))) {
        PyErr_NoMemory();
        return -1;
    }

    if (!ketama_roll(&(pkc->cont), pkc->filename)) {
        PyErr_SetString(pyketama_error, ketama_error());
        return -1;
    }

    return 0;
}
Exemple #3
0
static int
lketama_roll(lua_State *L){
	size_t fsiz;
	char *filename = (char *)luaL_checklstring(L, 1, &fsiz);
	if( fsiz > 255 ) return luaL_argerror(L, 1, "filename must not be longer than 255 bytes");
	contdata *data = lua_newuserdata(L, sizeof(*data));
	if(!data) return default_error(L);
	if(ketama_roll((ketama_continuum*)&data->cont, filename) == 0) return nil_error(L, 0, "continuum fail");
	luaL_getmetatable(L, MT_NAME);
   lua_setmetatable(L, -2);
   return 1;
}