Exemple #1
0
static void
__simple_checks(struct radix_tree_root *tree, unsigned long index, int tag)
{
	unsigned long first = 0;
	int ret;

	item_check_absent(tree, index);
	assert(item_tag_get(tree, index, tag) == 0);

	item_insert(tree, index);
	assert(item_tag_get(tree, index, tag) == 0);
	item_tag_set(tree, index, tag);
	ret = item_tag_get(tree, index, tag);
	assert(ret != 0);
	ret = tag_tagged_items(tree, NULL, first, ~0UL, 10, tag, !tag);
	assert(ret == 1);
	ret = item_tag_get(tree, index, !tag);
	assert(ret != 0);
	ret = item_delete(tree, index);
	assert(ret != 0);
	item_insert(tree, index);
	ret = item_tag_get(tree, index, tag);
	assert(ret == 0);
	ret = item_delete(tree, index);
	assert(ret != 0);
	ret = item_delete(tree, index);
	assert(ret == 0);
}
Exemple #2
0
/*
** get the head of list
**
*/
long  list_gethead(LIST *list, void *data, long *dlen)
{
  long rval = -1L;
  
  if ( data && dlen && *dlen > 0 ) {
    if ( list ) {
      pthread_mutex_lock(list->l_lock);
      if ( list->l_head && list->l_head->i_data && list->l_head->i_size <= *dlen ) {
	ITEM *pi = list->l_head;
	memcpy(data, pi->i_data, pi->i_size);
	*dlen = pi->i_size;
	if ( list->l_head != list->l_tail ) /* more than 1 items */
	  list->l_head = pi->i_next;
	else			/* single item */
	  list->l_head = list->l_tail = NULL;

	pi->i_next = NULL;
	item_delete(pi);
	
	list->l_count--;
	rval = 	0L;
      }
      pthread_mutex_unlock(list->l_lock);
    }
  }

  return rval;
}
Exemple #3
0
void			cli_requests_process(t_server *s, t_world *w)
{
  t_item		*current;
  t_item		*next;

  current = list_get_head(s->request_list);
  while (current != NULL)
    {
      next = current->next;
      if (T_REQUEST(current)->type->func != NULL
	  && T_REQUEST(current)->data != NULL
	  && s->tick >= T_REQUEST(current)->tick)
        {
	  T_REQUEST(current)->type->func(T_REQUEST(current)->data, s, w);
	  log_show("cli_requests_process", "",
		   "Request '%s' implemented on %dth tick",
		   T_REQUEST(current)->data->message, s->tick);
	  --(T_REQUEST(current)->data->user->request_counter);
	  free(T_REQUEST(current)->data->message);
	  s->diff = 1;
	  item_delete(s->request_list, current);
        }
      current = next;
    }
}
Exemple #4
0
static void leak_check(void)
{
	RADIX_TREE(tree, GFP_KERNEL);

	item_insert(&tree, 1000000);
	item_delete(&tree, 1000000);
	item_kill_tree(&tree);
}
Exemple #5
0
void
item_insert(struct item *it, const struct bstring *key)
{
    ASSERT(it != NULL && key != NULL);

    item_delete(key);

    _item_link(it);
    log_verb("insert it %p of id %"PRIu8" for key %.*s", it, it->id, key->len,
        key->data);
}
Exemple #6
0
static void __leak_check(void)
{
	RADIX_TREE(tree, GFP_KERNEL);

	printf("%d: nr_allocated=%d\n", __LINE__, nr_allocated);
	item_insert(&tree, 1000000);
	printf("%d: nr_allocated=%d\n", __LINE__, nr_allocated);
	item_delete(&tree, 1000000);
	printf("%d: nr_allocated=%d\n", __LINE__, nr_allocated);
	item_kill_tree(&tree);
	printf("%d: nr_allocated=%d\n", __LINE__, nr_allocated);
}
Exemple #7
0
/*
 * Check that tags propagate correctly when extending a tree.
 */
static void extend_checks(void)
{
	RADIX_TREE(tree, GFP_KERNEL);

	item_insert(&tree, 43);
	assert(item_tag_get(&tree, 43, 0) == 0);
	item_tag_set(&tree, 43, 0);
	assert(item_tag_get(&tree, 43, 0) == 1);
	item_insert(&tree, 1000000);
	assert(item_tag_get(&tree, 43, 0) == 1);

	item_insert(&tree, 0);
	item_tag_set(&tree, 0, 0);
	item_delete(&tree, 1000000);
	assert(item_tag_get(&tree, 43, 0) != 0);
	item_delete(&tree, 43);
	assert(item_tag_get(&tree, 43, 0) == 0);	/* crash */
	assert(item_tag_get(&tree, 0, 0) == 1);

	verify_tag_consistency(&tree, 0);

	item_kill_tree(&tree);
}
Exemple #8
0
static void
__simple_checks(struct radix_tree_root *tree, unsigned long index, int tag)
{
	int ret;

	item_check_absent(tree, index);
	assert(item_tag_get(tree, index, tag) == 0);

	item_insert(tree, index);
	assert(item_tag_get(tree, index, tag) == 0);
	item_tag_set(tree, index, tag);
	ret = item_tag_get(tree, index, tag);
	assert(ret != 0);
	ret = item_delete(tree, index);
	assert(ret != 0);
	item_insert(tree, index);
	ret = item_tag_get(tree, index, tag);
	assert(ret == 0);
	ret = item_delete(tree, index);
	assert(ret != 0);
	ret = item_delete(tree, index);
	assert(ret == 0);
}
Exemple #9
0
void dynamic_height_check(void)
{
	int i;
	RADIX_TREE(tree, GFP_KERNEL);
	tree_verify_min_height(&tree, 0);

	item_insert(&tree, 42);
	tree_verify_min_height(&tree, 42);

	item_insert(&tree, 1000000);
	tree_verify_min_height(&tree, 1000000);

	assert(item_delete(&tree, 1000000));
	tree_verify_min_height(&tree, 42);

	assert(item_delete(&tree, 42));
	tree_verify_min_height(&tree, 0);

	for (i = 0; i < 1000; i++) {
		item_insert(&tree, i);
		tree_verify_min_height(&tree, i);
	}

	i--;
	for (;;) {
		assert(item_delete(&tree, i));
		if (i == 0) {
			tree_verify_min_height(&tree, 0);
			break;
		}
		i--;
		tree_verify_min_height(&tree, i);
	}

	item_kill_tree(&tree);
}
Exemple #10
0
/*
** recursively delete all the list
**
*/
long list_delete(LIST *list)
{
  long cnt = 0L;

  if ( list ) {
    pthread_mutex_destroy(list->l_lock);
    cnt = item_delete(list->l_head);
    free(list->l_lock);
    list->l_lock = NULL;
    list->l_head = list->l_tail = NULL;
    list->l_count = 0;
    free(list);
  }
  
  return cnt;
}
Exemple #11
0
static void
asc_process_delete(struct conn *c, struct token *token, int ntoken)
{
    char *key;       /* key to be deleted */
    size_t nkey;     /* # key bytes */
    struct item *it; /* item for this key */

    asc_set_noreply_maybe(c, token, ntoken);

    if (!asc_ntoken_valid(c, ntoken)) {
        log_hexdump(LOG_NOTICE, c->req, c->req_len, "client error on c %d for "
                    "req of type %d with %d invalid tokens", c->sd,
                    c->req_type, ntoken);

        asc_write_client_error(c);
        return;
    }

    key = token[TOKEN_KEY].val;
    nkey = token[TOKEN_KEY].len;

    if (nkey > KEY_MAX_LEN) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and %d "
                  "length key", c->sd, c->req_type, nkey);

        asc_write_client_error(c);
        return;
    }

    /*
     * FIXME: This is not thread-safe, two threads could try to delete the same
     * item twice after succeeding in item_get, leading to erroneous stats
     */
    it = item_get(key, nkey);
    if (it != NULL) {
        stats_slab_incr(it->id, delete_hit);
        item_delete(it);
        asc_write_deleted(c);
    } else {
        stats_thread_incr(delete_miss);
        asc_write_not_found(c);
    }
}
Exemple #12
0
void
cmd_list_delete(struct response *rsp, struct request *req, struct command *cmd)
{
    struct bstring *key = _get_key(req);
    struct element *reply = (struct element *)array_push(rsp->token);

    INCR(process_metrics, list_delete);

    if (item_delete(key)) {
        reply->bstr = str2bstr(RSP_OK);
        INCR(process_metrics, list_delete_deleted);
        log_verb("command '%.*s' '%.*s' succeeded", cmd->bstr.len,
                cmd->bstr.data, key->len, key->data);
    } else {
        reply->bstr = str2bstr(RSP_NOTFOUND);
        INCR(process_metrics, list_delete_notfound);
        log_verb("command '%.*s' '%.*s' completed as no-op, key not found",
                cmd->bstr.len, cmd->bstr.data, key->len, key->data);
    }

}
Exemple #13
0
/*
 * Check that tags propagate correctly when contracting a tree.
 */
static void contract_checks(void)
{
	struct item *item;
	int tmp;
	RADIX_TREE(tree, GFP_KERNEL);

	tmp = 1<<RADIX_TREE_MAP_SHIFT;
	item_insert(&tree, tmp);
	item_insert(&tree, tmp+1);
	item_tag_set(&tree, tmp, 0);
	item_tag_set(&tree, tmp, 1);
	item_tag_set(&tree, tmp+1, 0);
	item_delete(&tree, tmp+1);
	item_tag_clear(&tree, tmp, 1);

	assert(radix_tree_gang_lookup_tag(&tree, (void **)&item, 0, 1, 0) == 1);
	assert(radix_tree_gang_lookup_tag(&tree, (void **)&item, 0, 1, 1) == 0);

	assert(item_tag_get(&tree, tmp, 0) == 1);
	assert(item_tag_get(&tree, tmp, 1) == 0);

	verify_tag_consistency(&tree, 0);
	item_kill_tree(&tree);
}
Exemple #14
0
void world_update_dt(void) {
    t_sprite_iterator iter;
    t_spritePtr sprite;
    t_item_iterator iiter;
    t_itemPtr item;
    
//    if (world.t-debug_time_printed > 10.0) {
//        debug_time_printed+=10.0;
//        printf("t= %.1f   %d sprites nexts: %.1f %.1f %.1f\n",debug_time_printed,world.sprites_n,world.time_next_piligrim,world.time_next_cansado,world.time_next_bici);
//    }
    
    
    
    // en la iteracion de actualizacion acumula collision candidates para despues
    collision_candidates_n=0;
    collision_bici_n=0;
    t_pos collision_x=world.player.vx*game_dt;
    // y calcula el walker mas retrasado y su velocidad
    t_pos min_x=500;
    t_v min_v=c_v_fast;
    world_iterate_sprites(&iter);
    // actualiza posicion y velocidad y estado de la animacion
    // tiene que hacerse al final para el player porque su velocidad se usa en el calculo de los demas
    while ( NULL != (sprite=world_iterate_next(&iter)) ) {
        sprite_update(sprite);

        if (sprite->anim_state_id > 100) {
            printf("warning : anim state invalid\n");
        }
        
        if (abs(sprite->x-collision_x)<200.0) { // si estan cerca pueden colisionar
            collision_candidates[collision_candidates_n]=sprite;
            collision_candidates_n+=1;
        }
        if ((sprite->sprite_class->id==SPRCLS_ID_PEREGRINO || sprite->sprite_class->id==SPRCLS_ID_BORDONERO) && (sprite->anim_state_id<STID_WALKER_STOP || sprite->anim_state_id==STID_WALKER_RECEIVED_HIT)) {// || sprite->anim_state_id==STID_WALKER_RECEIVING_HIT)) {
            if (sprite->x<min_x && sprite->x>0) {
                min_x=sprite->x;
                min_v=sprite->vx;
            }
        }
        if (collision_bici_n<1 && sprite->sprite_class->id==SPRCLS_ID_BICI) {
            collision_bici_n+=1;
            collision_bici=sprite;
        }
        
        // posible destruccion de sprites lejanos cuidado no usar despues sprite
        if (sprite->x-world.cam_x < -100 && sprite->sprite_class->id<SPRCLS_ID_BICI ) {
            world_delete_sprite(iter.i);
        }
        if (sprite->x-world.cam_x > 2000 && sprite->sprite_class->id==SPRCLS_ID_BICI ) {
            world_delete_sprite(iter.i);
            audio_una_bici_menos();
        }
    }
    
    //if (collision_candidates_n>0) printf("collision candidates: %d\n",collision_candidates_n);
    
    item_iterate_init(&iiter);
    while ( NULL != (item=item_iterate_next(&world, &iiter)) ) {
        item_update(item);
        
        if (item->x<-800) {
            item_delete(&world,iiter.i);
        }
    }
    

    if (world.player.x>world.player_checkpoint) {
//        printf("checkpoint !!!\n");
        world.player_checkpoint+=7000.0;
        world.player_deadline=world.t+60.0;
    }
    
    if (!world.waiting_to_start) {
        if (world.player.anim_state_id!=STID_PLAYER_FALLEN) {
            world_lose_life(game_dt*c_life_loss_per_second);
        }
    }
        
    if ( ( world.player_deadline<world.t || world.player_vida<=0.0 ) && ( world.player.anim_state_id<STID_PLAYER_STOP || world.player.anim_state_id==STID_PLAYER_SIDE ) ) {
        if (world.player.anim_state_id!=STID_PLAYER_TIRED) {
            audio_stop_music();
            audio_play_player_clip(AUDIO_SND_GAMEOVER);
            stats_end_game_timedistance();
        }
        world.player.vx=0;
        sprite_set_state(&world.player, STID_PLAYER_TIRED);
    }
    
    if (world.player.anim_state_id<STID_PLAYER_STOP && (world.player_untouchable_time<=world.t) ) {
        if(min_x<90.0) {
            world.player.vx=0.5*min_v;
        } else if (min_x<100.0) {
            world.player.vx=min_v;        
        }
    }
    
    sprite_update(&world.player);
    
    // controles
    t_id player_state=world.player.anim_state_id;

    if (!world.waiting_to_start) {
        if (world.player.vx<c_v_fast && player_state<STID_PLAYER_STOP) world.player.vx+=c_v_a*game_dt;
    } else {
        if (world.t>world_waiting_to_start_time) {
            world.waiting_to_start=False;
            sprite_set_state(&world.player, STID_PLAYER_WALK);
        }
    }

    if ( game_salto_pressed && player_state<STID_PLAYER_STOP ) {
        sprite_set_state(&world.player, STID_PLAYER_PREPARINGJUMP);
        audio_play_player_clip(AUDIO_SND_SALTO);
    }
    if ( game_hit_pressed && player_state<STID_PLAYER_STOP ) {
//        audio_play_player_clip(AUDIO_SND_HIT);
        audio_play_golpe_inicio();
        sprite_set_state(&world.player, STID_PLAYER_PREPARINGHIT);
    }
    if ( game_esquivar_pressed && player_state<STID_PLAYER_STOP ) {
        world.player.vx=0;
        sprite_set_state(&world.player, STID_PLAYER_SIDE);
    }
    if ( game_stop_pressed && player_state<STID_PLAYER_STOP ) {
        world.player.vx=c_v_slow*.7+c_v_fast*.3;
        //world_gain_life(1.0);
        //sprite_set_state(&world.player, STID_PLAYER_STOP);
    }
//    if ( !game_stop_pressed && player_state==STID_PLAYER_STOP ) {
//        world.player.vx=c_v_slow;
//        sprite_set_state(&world.player, STID_PLAYER_WALK);
//    }
    if ( !game_esquivar_pressed && player_state==STID_PLAYER_SIDE ) {
        world.player.vx=c_v_slow;
        sprite_set_state(&world.player, STID_PLAYER_WALK);
    }
    
//    // el estado puede haber cambiado por los controles
//    player_state=world.player.anim_state_id;
//    if ( world.player_vida<.1 && player_state<STID_PLAYER_STOP ) {
//        world.player.vx=c_v_slow*1.5;
//    }
//    
//    if ( world.player_vida<.05 && player_state<STID_PLAYER_STOP ) {
//        world.player.vx=c_v_slow*1.0;
//    }
    
    // si tienes poca vida y aun no estas muerto declarate in panic
    if (world.player_vida<.3 &&  world.player.anim_state_id!=STID_PLAYER_TIRED ) {
        float vida=world.player_vida;
        int ifreq=(vida<0.1)?3:((vida<0.2)?2:1);
        ifreq=1; // anular frecuencia variable del warning
        audio_low_warning_play(ifreq);
        achievments_inpanicnow(true);
    } else {
        achievments_inpanicnow(false);
    }
    
    
    // colisiones
    if ( world.player.y <0.001 && world.player.vy<0.001 ) {
        if ( player_state==STID_PLAYER_JUMP ) {
            world.player.y=0;
            world.player.vy=0;
//            world.player.vx=c_v_fast;
            sprite_set_state(&world.player, STID_PLAYER_WALK);
            audio_play_player_clip(AUDIO_SND_CAIDABIEN);
        } else if ( player_state==STID_PLAYER_FALL ) {
            world.player.y=0;
            world.player.vy=0;
            //world.player.vx=c_v_slow*0.5;
            sprite_set_state(&world.player, STID_PLAYER_FALLEN);
            audio_play_player_clip(AUDIO_SND_CAIDA);
        } else if ( player_state==STID_PLAYER_FALLEN ) {
            world.player.vx-=c_v_fast*0.02;
            if (world.player.vx<0) world.player.vx=0;
        }
    }
    
    int i;
    for (i=0; i<collision_candidates_n; i++) {
        sprite=collision_candidates[i];
        // colisionan sprite y player ???
        world_handle_collision_candidate(&world.player, sprite);
    }
    
    item_iterate_init(&iiter);
    while ( NULL != (item=item_iterate_next(&world, &iiter)) ) {
        if (item->item_class->type==ITEM_CLS_TUMBA) continue;
        if (world_item_collision_check(&world.player, item) /* && player_state==STID_PLAYER_STOP */ ) {
            audio_play_player_clip(AUDIO_SND_COMER);
            if (item->item_class->type==ITEM_CLS_POWERUP_LIFE) {
                world_gain_life(1.0);                
            } else {
                world_gain_life(c_life_gain_per_food);
                achievments_eaten(item);
            }
            item_delete(&world,iiter.i);
            stats_add_comida(item->item_class->type);
        }
    }
    
    // vuelta extra para que las bicis arrasen
    // del collision candidates se ha quedado con una bici y prueba si colisiona con otros
    if (collision_bici_n>0 && collision_bici->x<1500.0) {
        world_iterate_sprites(&iter);
        while ( NULL != (sprite=world_iterate_next(&iter)) ) {
            if (sprite!=collision_bici) {
               
                if (world_nonplayer_collision_check(collision_bici,sprite)) {
                    if ( (sprite->sprite_class->id==SPRCLS_ID_PEREGRINO || sprite->sprite_class->id==SPRCLS_ID_BORDONERO) && sprite->anim_state_id<STID_WALKER_STOP) {
                        audio_play_other_clip(AUDIO_SND_CAIDA);
                        sprite_set_state(sprite, STID_WALKER_RECEIVING_HIT);
                        sprite->vx=0.0;
                    }
                }
            }
        }
    }
    
    //int i;
//	int min_i;
//	t_pos min_x=200;
//	t_v min_v=100;
//    for (i=0;i<MAX_N_WALKER;i++) {
//        if (world.walker_list[i].valid) {
//            world.walker_list[i].x+=(world.walker_list[i].v-world.player_vx)*game_dt;
//			if (!world.walker_list[i].apartado) {
//				if (world.walker_list[i].x<min_x) {
//					min_x=world.walker_list[i].x;
//					min_v=world.walker_list[i].v;
//					min_i=i;
//				}
//			}
//            // regenera rapido para probar
//            if (world.walker_list[i].x-world.cam_x<-25.0) {
//               // printf("regenerate now\n");
//                world.walker_list[i].x=480+world.cam_x+24-100*log(rand()*1.0/RAND_MAX);
//                world.walker_list[i].v=c_v_slow+5.0*(int)(4.0*(rand()*1.0/RAND_MAX));
//				world.walker_list[i].apartado=0;
//            }
//            
//        }
//    }
//
//    if (min_x<50) {
//		world.player_vx=min_v;
//		if (!world.player_slow) {
//			world.player_slow=1;
//			world.player_slow_since=world.t;
//		} else {
//			if (world.t-world.player_slow_since>3.0) {
//				world.walker_list[min_i].apartado=1;
//				world.walker_list[min_i].v=0;
//			}
//		}
//	
//	} else {
//		world.player_vx=c_v_fast;
//		world.player_slow=0;
//	}
//	
//	if (world.player.y<0.0001) {
//		world.player.y=0;
////		if (game_salto_pressed) {
////			world.player_vy=100;
////		}
//        }	
//    
    
    //genera
    
//    if (world.t > world.time_next_piligrim) {
//        int tipo=rand()%2;   // de momento 50 - 50 cambiar probabilidades
//        world_create_walker(1000.0, tipo);
//        world.time_next_piligrim=world.t+random_exp_time(20.0);
//    }    
//    if (world.t > world.time_next_cansado) {
//        world_create_walker(1000.0, 2);
//        world.time_next_cansado=world.t+random_exp_time(20.0);
//    }    
//    if (world.t > world.time_next_bici) {
//        world_create_walker(-400.0, 3);
//        world.time_next_bici=world.t+random_exp_time(20.0);
//    }
    
    
    //probando cosas mas creativas para la camara
    // camara on fuerza que proporcional a la distancia al punto deseado
    // y con rozamiento viscoso para que no oscile

    if (cam_type==0) {    
    
        t_pos cam_now,cam_target;
        cam_now=world.cam_x-world.player.vx*game_dt;
        cam_target=-c_cam_offset;
//
    world.cam_v+=250.0*(cam_target-cam_now)*game_dt-1.5*world.cam_v;

//    if (abs(world.cam_v)>500.0) world.cam_v=copysign(500.0,world.cam_v);
//        world.cam_v=copysign(200,(cam_target-cam_now));
    
        float smooth_alfa=0; // 0 no smooth
        
        t_pos cam_smooth=cam_now+world.cam_v*game_dt;
        world.cam_x=world.cam_x*smooth_alfa+cam_smooth*(1-smooth_alfa);
        
    
 //   if (world.cam_x>cam_target) {world.cam_x=cam_target;world.cam_v=world.player.vx;}
//    if (world.cam_x+200<cam_target) {world.cam_x=cam_target;world.cam_v=world.player.vx;}

//    if (world.cam_x<-300) {world.cam_x=-300; world.cam_v=world.player.vx;}
//    if (world.cam_x>-100) {world.cam_x=-100; world.cam_v=world.player.vx;}
    } else if (cam_type==1) {
        
        // camara simple con distancia maxima y minima
        t_pos max_cam_distance=300;
        t_pos min_cam_distance=200-10000*c_cam_init_free;
        t_pos cam_now=world.cam_x-world.player.vx*game_dt+world.cam_v*game_dt;
        if (cam_now<-max_cam_distance) {world.cam_v=world.player.vx;cam_now=-max_cam_distance;}
        if (cam_now>-min_cam_distance) {world.cam_v=0*world.player.vx;cam_now=-min_cam_distance;}
        world.cam_x=cam_now;
        // cuando la camara alcanza al jugador se acaba el estado inicial de camara
        if (c_cam_init_free && cam_now<-200) c_cam_init_free=0;
    
    } else if (cam_type==2) {
        // de momento la camara sigue al jugador siempre a una distancia
        world.cam_x=-c_cam_offset;
    }
    
    
//    if(game_hit_pressed) {
//        world.cam_x+=10;
//    }
//    if(game_esquivar_pressed) {
//        world.cam_x-=10;
//    }
    
    
    world_update_zones();
    generador_update();
    
    world.t+=game_dt;
    
    achievments_check_update();
}
Exemple #15
0
int main(int argc, char **argv) {
    config_init();

    int c;
    
    while (-1 != (c = getopt(argc, argv, "n:m:k:d:p:h"))) {
        switch(c) {
            case 'n':
                config.num = atoi(optarg);
                break;
            case 'm':
                config.maxbytes = ((size_t)atoi(optarg)) * 1024 * 1024;
                break;
            case 'k':
                config.keysize = atoi(optarg);
                break;
            case 'd':
                config.datasize = atoi(optarg);
                break;
            case 'p':
                config.hashpower = atoi(optarg);
                break;
            case 'h':
                usage();
                return EXIT_SUCCESS;
            default:
                usage();
                return EXIT_FAILURE;
        }
    }

    generate_key_init();
    print_env();
    lru *l = lru_init(config.maxbytes, config.hashpower);

    char *bvalue = malloc(config.datasize);
    memset(bvalue, 'x', config.datasize);

    char *key = malloc(config.keysize);
    memset(key, 0, config.keysize);

    int gnum = config.keysize - num_;

    generate_key_reset();
    bench_start("SET");
    int i;
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        int r = item_set(l, key, config.keysize, bvalue, config.datasize);
        assert(r == 0);
        process_report();
    }
    bench_stop();
    print_stat(l);

    char *buf = malloc(config.datasize);
    size_t sz;
    generate_key_reset();
    bench_start("GET");
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        int r = item_get(l, key, config.keysize, buf, config.datasize, &sz);
        if (!r) {
            assert((int)sz == config.datasize);
            assert(memcmp(bvalue, buf, config.datasize) == 0);
        }
        memset(buf, 0, config.datasize);
        process_report();
    }
    bench_stop();
    print_stat(l);

    generate_key_reset();
    bench_start("DELETE");
    for (i = 0; i < config.num; i++) {
        snprintf(key, config.keysize, fmt_, gnum, generate_key(gnum), i);
        item_delete(l, key, config.keysize);
        process_report();
    }
    bench_stop();
    print_stat(l);
    
    free(buf);
    free(bvalue);
    free(key);
    free(fmt_);
    free(key_);
   
    lru_free(l);
    /*
    printf("print any key to exit...\n");
    getchar();
    */
    return EXIT_SUCCESS;
}
Exemple #16
0
static void
asc_process_update(struct conn *c, struct token *token, int ntoken)
{
    char *key;
    size_t nkey;
    uint32_t flags, vlen;
    int32_t exptime_int;
    time_t exptime;
    uint64_t req_cas_id = 0;
    struct item *it;
    bool handle_cas;
    req_type_t type;
    uint8_t id;

    asc_set_noreply_maybe(c, token, ntoken);

    if (!asc_ntoken_valid(c, ntoken)) {
        log_hexdump(LOG_NOTICE, c->req, c->req_len, "client error on c %d for "
                    "req of type %d with %d invalid tokens", c->sd,
                    c->req_type, ntoken);

        asc_write_client_error(c);
        return;
    }

    type = c->req_type;
    handle_cas = (type == REQ_CAS) ? true : false;
    key = token[TOKEN_KEY].val;
    nkey = token[TOKEN_KEY].len;

    if (nkey > KEY_MAX_LEN) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and %d "
                  "length key", c->sd, c->req_type, nkey);

        asc_write_client_error(c);
        return;
    }

    if (!mc_strtoul(token[TOKEN_FLAGS].val, &flags)) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and "
                  "invalid flags '%.*s'", c->sd, c->req_type,
                  token[TOKEN_FLAGS].len, token[TOKEN_FLAGS].val);

        asc_write_client_error(c);
        return;
    }

    if (!mc_strtol(token[TOKEN_EXPIRY].val, &exptime_int)) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and "
                  "invalid expiry '%.*s'", c->sd, c->req_type,
                  token[TOKEN_EXPIRY].len, token[TOKEN_EXPIRY].val);

        asc_write_client_error(c);
        return;
    }

    if (!mc_strtoul(token[TOKEN_VLEN].val, &vlen)) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and "
                  "invalid vlen '%.*s'", c->sd, c->req_type,
                  token[TOKEN_VLEN].len, token[TOKEN_VLEN].val);

        asc_write_client_error(c);
        return;
    }

    id = item_slabid(nkey, vlen);
    if (id == SLABCLASS_INVALID_ID) {
        log_debug(LOG_NOTICE, "client error on c %d for req of type %d and "
                  "slab id out of range for key size %"PRIu8" and value size "
                  "%"PRIu32, c->sd, c->req_type, nkey, vlen);

        asc_write_client_error(c);
        return;
    }

    exptime = (time_t)exptime_int;

    /* does cas value exist? */
    if (handle_cas) {
        if (!mc_strtoull(token[TOKEN_CAS].val, &req_cas_id)) {
            log_debug(LOG_NOTICE, "client error on c %d for req of type %d and "
                      "invalid cas '%.*s'", c->sd, c->req_type,
                      token[TOKEN_CAS].len, token[TOKEN_CAS].val);

            asc_write_client_error(c);
            return;
        }
    }

    it = item_alloc(id, key, nkey, flags, time_reltime(exptime), vlen);
    if (it == NULL) {
        log_warn("server error on c %d for req of type %d because of oom in "
                 "storing item", c->sd, c->req_type);

        asc_write_server_error(c);

        /* swallow the data line */
        c->write_and_go = CONN_SWALLOW;
        c->sbytes = vlen + CRLF_LEN;

        /*
         * Avoid stale data persisting in cache because we failed alloc.
         * Unacceptable for SET. Anywhere else too?
         *
         * FIXME: either don't delete anything or should be unacceptable for
         * all but add.
         */
        if (type == REQ_SET) {
            it = item_get(key, nkey);
            if (it != NULL) {
                item_delete(it);
            }
        }
        return;
    }

    item_set_cas(it, req_cas_id);

    c->item = it;
    c->ritem = item_data(it);
    c->rlbytes = it->nbyte + CRLF_LEN;
    conn_set_state(c, CONN_NREAD);
}
Exemple #17
0
static void do_thrash(struct radix_tree_root *tree, char *thrash_state, int tag)
{
	int insert_chunk;
	int delete_chunk;
	int tag_chunk;
	int untag_chunk;
	int total_tagged = 0;
	int total_present = 0;

	for (insert_chunk = 1; insert_chunk < THRASH_SIZE; insert_chunk *= N)
	for (delete_chunk = 1; delete_chunk < THRASH_SIZE; delete_chunk *= N)
	for (tag_chunk = 1; tag_chunk < THRASH_SIZE; tag_chunk *= N)
	for (untag_chunk = 1; untag_chunk < THRASH_SIZE; untag_chunk *= N) {
		int i;
		unsigned long index;
		int nr_inserted = 0;
		int nr_deleted = 0;
		int nr_tagged = 0;
		int nr_untagged = 0;
		int actual_total_tagged;
		int actual_total_present;

		for (i = 0; i < insert_chunk; i++) {
			index = rand() % THRASH_SIZE;
			if (thrash_state[index] != NODE_ABSENT)
				continue;
			item_check_absent(tree, index);
			item_insert(tree, index);
			assert(thrash_state[index] != NODE_PRESENT);
			thrash_state[index] = NODE_PRESENT;
			nr_inserted++;
			total_present++;
		}

		for (i = 0; i < delete_chunk; i++) {
			index = rand() % THRASH_SIZE;
			if (thrash_state[index] == NODE_ABSENT)
				continue;
			item_check_present(tree, index);
			if (item_tag_get(tree, index, tag)) {
				assert(thrash_state[index] == NODE_TAGGED);
				total_tagged--;
			} else {
				assert(thrash_state[index] == NODE_PRESENT);
			}
			item_delete(tree, index);
			assert(thrash_state[index] != NODE_ABSENT);
			thrash_state[index] = NODE_ABSENT;
			nr_deleted++;
			total_present--;
		}

		for (i = 0; i < tag_chunk; i++) {
			index = rand() % THRASH_SIZE;
			if (thrash_state[index] != NODE_PRESENT) {
				if (item_lookup(tree, index))
					assert(item_tag_get(tree, index, tag));
				continue;
			}
			item_tag_set(tree, index, tag);
			item_tag_set(tree, index, tag);
			assert(thrash_state[index] != NODE_TAGGED);
			thrash_state[index] = NODE_TAGGED;
			nr_tagged++;
			total_tagged++;
		}

		for (i = 0; i < untag_chunk; i++) {
			index = rand() % THRASH_SIZE;
			if (thrash_state[index] != NODE_TAGGED)
				continue;
			item_check_present(tree, index);
			assert(item_tag_get(tree, index, tag));
			item_tag_clear(tree, index, tag);
			item_tag_clear(tree, index, tag);
			assert(thrash_state[index] != NODE_PRESENT);
			thrash_state[index] = NODE_PRESENT;
			nr_untagged++;
			total_tagged--;
		}

		actual_total_tagged = 0;
		actual_total_present = 0;
		for (index = 0; index < THRASH_SIZE; index++) {
			switch (thrash_state[index]) {
			case NODE_ABSENT:
				item_check_absent(tree, index);
				break;
			case NODE_PRESENT:
				item_check_present(tree, index);
				assert(!item_tag_get(tree, index, tag));
				actual_total_present++;
				break;
			case NODE_TAGGED:
				item_check_present(tree, index);
				assert(item_tag_get(tree, index, tag));
				actual_total_present++;
				actual_total_tagged++;
				break;
			}
		}

		gang_check(tree, thrash_state, tag);

		printf("%d(%d) %d(%d) %d(%d) %d(%d) / "
				"%d(%d) present, %d(%d) tagged\n",
			insert_chunk, nr_inserted,
			delete_chunk, nr_deleted,
			tag_chunk, nr_tagged,
			untag_chunk, nr_untagged,
			total_present, actual_total_present,
			total_tagged, actual_total_tagged);
	}
}