Ejemplo n.º 1
0
int32_t process_client_message(struct mile_message_header* msg_head,
		struct data_buffer* rbuf, struct data_buffer* sbuf) {
	int32_t result_code = MILE_RETURN_SUCCESS;
	MEM_POOL_PTR mem_pool;
	void* packet;
	struct slave_sync_res *binlog_res;

	switch (msg_head->message_type) {
	case MT_CD_EXE_GET_LOAD_THRESHOLD: {
		log_debug("get get_load_threshold command");
		double load = g_load_threshold;
		gen_dc_get_load_threshold_packet(load, msg_head, sbuf);
	}
		break;
	case MT_CD_EXE_SET_LOAD_THRESHOLD: {
		log_debug("get set_load_threshold command");
		double old_load = g_load_threshold;
		mem_pool = mem_pool_init(KB_SIZE);
		struct set_load_threshold_packet *p = parse_set_load_threshold_packet(
				mem_pool, rbuf);

		g_load_threshold = p->value;
		log_info(
				"change os overloading threshold from %g to %g", old_load, g_load_threshold);
		gen_dc_set_load_threshold_packet(old_load, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
	}
		break;
	default:
		result_code = -1;
		break;
	}

	return result_code;
}
Ejemplo n.º 2
0
void test_multi_hashvalue(uint32_t limit)
{
   MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
   int32_t ret;
   struct hash_index_config config;
   config.row_limit = limit;
   strcpy(config.work_space,"/tmp/hash_compress_test");
   system("rm -rf /tmp/hash_compress_test");
   mkdirs(config.work_space);
   init_profile(1000,mem_pool);
   
   struct hash_index_manager* hash_index = hash_index_init(&config,mem_pool);


   uint32_t i;
   struct low_data_struct* data = (struct low_data_struct*)mem_pool_malloc(mem_pool,sizeof(struct low_data_struct));
   get_low_data(data,mem_pool);
   
   for(i=0; i<config.row_limit;i++)
   {   sprintf((char*)data->data,"%d",i);
	   ret = hash_index_insert(hash_index,data,i);
	   ASSERT_EQ(0,ret);
   }

   verify_muti_hashvalue(hash_index,mem_pool);
   hash_index_release(hash_index);
}
Ejemplo n.º 3
0
int DocEngine::SpecialSql(struct mile_message_header* msg_head, struct data_buffer* rbuf, struct data_buffer* sbuf){
	MEM_POOL_PTR mem_pool;
	void* packet;
	void* result;
	int32_t result_code = MILE_RETURN_SUCCESS;
	uint16_t msg_type = msg_head->message_type;


	switch (msg_type) {
	case MT_MD_EXE_GET_KVS:
		mem_pool = mem_pool_init(MB_SIZE);
		packet = parse_get_kvs_packet(mem_pool, rbuf);
		result = GetKvs((struct get_kvs_packet*) packet, mem_pool);

		if(NULL == result){
			result_code = ERROR_QUERY_BY_ROWID;
		}else{
			gen_query_result_packet((ResultSet*) result, msg_head,
					sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	default:
		log_error("unsupported command, packet type %d", msg_type);
		result_code = ERROR_UNSUPPORTED_SQL_TYPE;
		break;
	}

	return result_code;
}
Ejemplo n.º 4
0
int32_t process_test_message(struct mile_message_header* msg_head,
		struct data_buffer* rbuf, struct data_buffer* sbuf) {
	int32_t result_code = MILE_RETURN_SUCCESS;
	MEM_POOL_PTR mem_pool;

	switch (msg_head->message_type) {
	case MT_TEST_REQ_ECHO: // echo message for testing.
	{
		mem_pool = mem_pool_init(MB_SIZE);
		const char *str = read_cstring(rbuf, mem_pool);
		log_debug("get echo message [%s]", str);

		write_int32(0, sbuf);
		write_int8(msg_head->version_major, sbuf);
		write_int8(msg_head->version_minor, sbuf);
		write_int16(MT_TEST_RES_ECHO, sbuf);
		write_int32(msg_head->message_id, sbuf);

		write_int32(strlen(str), sbuf);
		write_bytes((uint8_t *) str, strlen(str), sbuf);

		fill_int32(sbuf->data_len, sbuf, 0);
		result_code = MILE_RETURN_SUCCESS;
		mem_pool_destroy(mem_pool);
	}
		break;
	default:
		result_code = -1;
		break;
	}

	return result_code;
}
Ejemplo n.º 5
0
int32_t process_master_message(struct mile_message_header* msg_head,
		struct data_buffer* rbuf, struct data_buffer* sbuf, void **bl_reader,
		MEM_POOL_PTR session_mem) {
	int32_t result_code = MILE_RETURN_SUCCESS;
	MEM_POOL_PTR mem_pool;
	void* packet;
	struct slave_sync_res *binlog_res;

	switch (msg_head->message_type) {
	case MT_SM_GET_BINLOG:
		mem_pool = mem_pool_init(MB_SIZE);
		// STATIC_ASSERT( MB_SIZE > sizeof(struct slave_sync_res) + MAX_BINLOG_DATA_PER_PACKET, MAX_BINLOG_PACKAGE_SHOULD_LESS_THAN_MEM_POOL_SIZE);
		packet = parse_slave_sync_req(mem_pool, rbuf);
		binlog_res = execute_slave_sync(mem_pool,
				(struct slave_sync_req *) packet, bl_reader, session_mem);
		assert(NULL != binlog_res);
		gen_slave_sync_res_packet(binlog_res, msg_head, sbuf);
		result_code = 0;
		mem_pool_destroy(mem_pool);
		break;
	default:
		result_code = -1;
		break;
	}

	return result_code;
}
TEST(DYHASH_CHECKPOINT2, dyhashindex){
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);

	struct dyhash_index_config config;
	
	char dir_path[] = "/tmp/dyhash_index3";

	config.is_full = 0;
	config.row_limit = 2;
	config.is_full = 1;
	strcpy(config.work_space, dir_path);
	

    init_profile(1000,mem_pool);
	
	struct dyhash_index_manager* dyhash_index = dyhash_index_init(&config,mem_pool);

	struct low_data_struct data;
	data.data = mem_pool_malloc(mem_pool, strlen("hello world"));
	memset(data.data, 0, strlen("hello world"));
	strcpy((char*)data.data, "hello world");
	data.len = strlen("hello world");
	data.type = HI_TYPE_STRING;


	uint32_t count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(1, count);

	
	struct rowid_list* query_ret = dyhash_index_query(dyhash_index, &data, mem_pool);
	print_rowid_list(query_ret);
}
Ejemplo n.º 7
0
int main(int argc, char* argv[])
{
	char* cmd = NULL;
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
	int socket_fd;

	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGINT, sign_handler);
	signal(SIGTERM, sign_handler);

	if((socket_fd = parse_cmd_line(argc, argv, mem_pool)) <= 0)
	{
		mem_pool_destroy(mem_pool);
		return 0;
	}
	
	while (global_start) {
		if ((cmd = readline("MILE>")) == NULL) {
			break;
		}
		parse_cmd(cmd,socket_fd,mem_pool);
		mem_pool_reset(mem_pool);
		if(cmd != NULL)
		{
			free(cmd);
			cmd = NULL;
		}
	}

	mem_pool_destroy(mem_pool);
	return 0;
}	
Ejemplo n.º 8
0
/*
 * Clears the cache.
 */
static void fscache_clear(struct fscache *cache)
{
	mem_pool_discard(cache->mem_pool, 0);
	cache->mem_pool = NULL;
	mem_pool_init(&cache->mem_pool, 0);
	hashmap_free(&cache->map, 0);
	hashmap_init(&cache->map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
	cache->lstat_requests = cache->opendir_requests = 0;
	cache->fscache_misses = cache->fscache_requests = 0;
}
struct dyhash_index_manager* init(struct dyhash_index_config* config,char * dir_path){
	char cmd[1024];
	memset(cmd, 0, sizeof(cmd));
	sprintf(cmd, "rm -rf %s", dir_path);
	system(cmd);
	
	mkdirs(dir_path);

	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
    init_profile(1000,mem_pool);
	return dyhash_index_init(config,mem_pool);
}
Ejemplo n.º 10
0
/*
 * Enables the cache. Note that the cache is read-only, changes to
 * the working directory are NOT reflected in the cache while enabled.
 */
int fscache_enable(size_t initial_size)
{
	int fscache;
	struct fscache *cache;
	int result = 0;

	/* allow the cache to be disabled entirely */
	fscache = git_env_bool("GIT_TEST_FSCACHE", -1);
	if (fscache != -1)
		core_fscache = fscache;
	if (!core_fscache)
		return 0;

	/*
	 * refcount the global fscache initialization so that the
	 * opendir and lstat function pointers are redirected if
	 * any threads are using the fscache.
	 */
	EnterCriticalSection(&fscache_cs);
	if (!initialized) {
		if (!dwTlsIndex) {
			dwTlsIndex = TlsAlloc();
			if (dwTlsIndex == TLS_OUT_OF_INDEXES)
				return 0;
		}

		/* redirect opendir and lstat to the fscache implementations */
		opendir = fscache_opendir;
		lstat = fscache_lstat;
	}
	initialized++;
	LeaveCriticalSection(&fscache_cs);

	/* refcount the thread specific initialization */
	cache = fscache_getcache();
	if (cache) {
		cache->enabled++;
	} else {
		cache = (struct fscache *)xcalloc(1, sizeof(*cache));
		cache->enabled = 1;
		/*
		 * avoid having to rehash by leaving room for the parent dirs.
		 * '4' was determined empirically by testing several repos
		 */
		hashmap_init(&cache->map, (hashmap_cmp_fn)fsentry_cmp, NULL, initial_size * 4);
		mem_pool_init(&cache->mem_pool, 0);
		if (!TlsSetValue(dwTlsIndex, cache))
			BUG("TlsSetValue error");
	}

	trace_printf_key(&trace_fscache, "fscache: enable\n");
	return result;
}
Ejemplo n.º 11
0
void test_tow_hashvalue(uint32_t limit)
{
   MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
   struct hash_index_config config;
   config.row_limit = limit;
   strcpy(config.work_space,"/tmp/hash_compress_test");
   system("rm -rf /tmp/hash_compress_test");
   mkdirs(config.work_space);
   init_profile(1000,mem_pool);
   
   struct hash_index_manager* hash_index = hash_index_init(&config,mem_pool);


   uint32_t i;
   struct low_data_struct* data = (struct low_data_struct*)mem_pool_malloc(mem_pool,sizeof(struct low_data_struct));
   get_low_data(data,mem_pool);
   
   for(i=0; i<config.row_limit/2;i++)
   {   
   	   strcpy((char*)data->data,"1");
	   hash_index_insert(hash_index,data,i);
   }

   for(i=config.row_limit/2; i<config.row_limit;i++)
   {   
   	   strcpy((char*)data->data,"2");
	   hash_index_insert(hash_index,data,i);
   }

   	struct hash_compress_manager* hash_compress = hash_compress_load(hash_index,10,mem_pool);
	
   	struct rowid_list* rlist_a;
	struct rowid_list* rlist_b;

    get_low_data(data,mem_pool);

	strcpy((char*)data->data,"1");
	rlist_a = hash_index_query(hash_index,data,mem_pool);
	rlist_b = hash_compress_query(hash_compress,data,mem_pool);

	ASSERT_EQ(rowid_list_equals(rlist_a,rlist_b),1);

	strcpy((char*)data->data,"2");
	rlist_a = hash_index_query(hash_index,data,mem_pool);
	rlist_b = hash_compress_query(hash_compress,data,mem_pool);

	ASSERT_EQ(rowid_list_equals(rlist_a,rlist_b),1);

    hash_index_release(hash_index);
    hash_compress_release(hash_compress);
}
Ejemplo n.º 12
0
TEST(DYHASH_RECOVER2, dyhashindex){
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
	struct dyhash_index_config config;
	
	char dir_path[] = "/tmp/dyhash_index4";

	config.is_full = 1;
	config.row_limit = 8;
	strcpy(config.work_space, dir_path);
	
	struct low_data_struct data;
	data.data = malloc(strlen("hello1world") + 1);
	memset(data.data, 0, strlen("hello1world") + 1);
	data.len = strlen("hello1world");
	data.type = HI_TYPE_STRING;
	
	struct dyhash_index_manager* dyhash_index = dyhash_index_init(&config, mem_pool);
	int32_t ret;

	dyhash_index_recover(dyhash_index, 3);

	strcpy((char*)data.data, "hello1world");
	uint32_t count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(3, count);

	strcpy((char*)data.data, "hello2world");
	count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(0, count);

	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,3);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello2world");
    ret = dyhash_index_insert(dyhash_index,&data,4);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello2world");
    ret = dyhash_index_insert(dyhash_index,&data,5);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello1world");
	count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(4, count);

	strcpy((char*)data.data, "hello2world");
	count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(2, count);
	
}
Ejemplo n.º 13
0
TEST(DYHASH_RECOVER1, dyhashindex){
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);

	struct dyhash_index_config config;
	
	char dir_path[] = "/tmp/dyhash_index4";

	config.is_full = 0;
	config.row_limit = 8;
	strcpy(config.work_space, dir_path);
	
	
	struct dyhash_index_manager* dyhash_index = init(&config,dir_path);
	
	struct low_data_struct data;
	data.data = mem_pool_malloc(mem_pool, strlen("hello1world"));
	memset(data.data, 0, strlen("hello1world"));
	data.len = strlen("hello world");
	data.type = HI_TYPE_STRING;

	int32_t ret = 0;
	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,0);
	ASSERT_EQ(0, ret);
	
	
	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,1);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,2);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,3);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello2world");
    ret = dyhash_index_insert(dyhash_index,&data,4);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello2world");
    ret = dyhash_index_insert(dyhash_index,&data,5);
	ASSERT_EQ(0, ret);

	dyhash_index_release(dyhash_index);
}
Ejemplo n.º 14
0
/**
  * @brief  Initialize the target hardware and the console
  * @param  None
  * @retval None
  */
void MOD_PreInit(void)
{

  memset(MOD_table, 0, sizeof(GROUP_InitTypeDef));

  /* Init Console to save events log*/
  CONSOLE_Init();

  CONSOLE_LOG((uint8_t *)"[SYSTEM] Module Manager running....");

  /* Init Board specific hardware */
  BSP_Init();
  
  /*Init heap memory (located in SRAM)*/ 
  mem_pool_init();
}
Ejemplo n.º 15
0
TEST(STORE_STAT_TEST, HandleNoneZeroInput) 
{

   MEM_POOL* mem_pool = mem_pool_init(M_1M);  
   store_stats_init(1000*10,mem_pool);

   uint64 i;
   for(i=0;i<10000;i++)
   	record_time("index_equal",1000*100);


   ASSERT_EQ(100.000000,get_avg_time_inms("index_equal"));
   ASSERT_EQ(10000,get_count("index_equal"));
   ASSERT_EQ(10000,get_total_count("index_equal"));
   sleep(2);
   ASSERT_EQ(5000,get_throughput("index_equal"));
}
Ejemplo n.º 16
0
/**
 * Long path for mem_pools_alloc
 *
 * @return true - if there is a free chunk in mem_pools,
 *         false - otherwise (not enough memory).
 */
static bool __attr_noinline___
mem_pools_alloc_longpath (void)
{
  /**
   * If there are no free chunks, allocate new pool.
   */
  if (mem_free_chunks_number == 0)
  {
    mem_pool_state_t *pool_state = (mem_pool_state_t*) mem_heap_alloc_block (MEM_POOL_SIZE, MEM_HEAP_ALLOC_LONG_TERM);

    JERRY_ASSERT (pool_state != NULL);

    mem_pool_init (pool_state, MEM_POOL_SIZE);

    MEM_CP_SET_POINTER (pool_state->next_pool_cp, mem_pools);

    mem_pools = pool_state;

    mem_free_chunks_number += MEM_POOL_CHUNKS_NUMBER;

    MEM_POOLS_STAT_ALLOC_POOL ();
  }
  else
  {
    /**
     * There is definitely at least one pool of specified type with at least one free chunk.
     *
     * Search for the pool.
     */
    mem_pool_state_t *pool_state = mem_pools, *prev_pool_state_p = NULL;

    while (pool_state->first_free_chunk == MEM_POOL_CHUNKS_NUMBER)
    {
      prev_pool_state_p = pool_state;
      pool_state = MEM_CP_GET_NON_NULL_POINTER (mem_pool_state_t, pool_state->next_pool_cp);
    }

    JERRY_ASSERT (prev_pool_state_p != NULL && pool_state != mem_pools);

    prev_pool_state_p->next_pool_cp = pool_state->next_pool_cp;
    MEM_CP_SET_NON_NULL_POINTER (pool_state->next_pool_cp, mem_pools);
    mem_pools = pool_state;
  }

  return true;
} /* mem_pools_alloc_longpath */
Ejemplo n.º 17
0
void* MainStep::Execute(TableManager* table, void* input, int32_t &result_code,
		int64_t timeout, MEM_POOL_PTR mem_pool) {
	MileIterator* iter = (MileIterator*) input;
	MileIterator* step_iter = substeps->CreateIterator();
	uint32_t i = 0;
	uint32_t cut_threshold=table->getCutThreshold();

	ExecuteSubstep* substep;
	MEM_POOL_PTR inner_mem_pool = mem_pool_init(MB_SIZE);

	for (iter->First(); !iter->IsDone(); iter->Next()) {
		for (step_iter->First(); !step_iter->IsDone(); step_iter->Next()) {
			substep = (ExecuteSubstep*) step_iter->CurrentItem();
			result_code = substep->Execute(table,
					(MileHandler*) iter->CurrentItem(), result, inner_mem_pool);
			if (result_code != 0) {
				break;
			}
		}
		mem_pool_reset(inner_mem_pool);
		if (result_code < 0) {
			break;
		}

		if((++i) % 100 == 0){
			if(get_time_msec() > timeout){
				result_code = ERROR_TIMEOUT;
				break;
			}
		}
		if( cut_threshold > 0 && i >= cut_threshold )
		{
			break;
		}
	}

	mem_pool_destroy(inner_mem_pool);

	if (result_code == WARN_EXCEED_QUERY_LIMIT || result_code >= 0) {
		result_code = MILE_RETURN_SUCCESS;
	}
	return result;
}
Ejemplo n.º 18
0
TEST(DATA_BUFFER_TEST, READ_AND_WRITE){

	MEM_POOL_PTR pMemPool = mem_pool_init(MB_SIZE);
	struct data_buffer* buffer = init_data_buffer();
	buffer->data_len = 256;
	buffer->data = (uint8*) mem_pool_malloc(pMemPool, 256);

	uint8 tmp8;
	uint16 tmp16;
	uint32 tmp32;
	uint64 tmp64;

	char* str = (char*) mem_pool_malloc(pMemPool, 100);
	char* result = (char*) mem_pool_malloc(pMemPool, 100);
	strcpy(str, "hello world!");

	
	write_int8(122, buffer);
	write_int16(1111, buffer);
	write_int32(324, buffer);
	write_int64(2321, buffer);
	write_bytes((uint8*)str, strlen(str)+1, buffer);

	

	tmp8 = read_int8(buffer);
	ASSERT_EQ(tmp8, 122);
	tmp16 = read_int16(buffer);
	ASSERT_EQ(tmp16, 1111);
	tmp32 = read_int32(buffer);
	ASSERT_EQ(tmp32, 324);
	tmp64 = read_int64(buffer);
	ASSERT_EQ(tmp64, 2321);

	read_bytes(buffer, (uint8*)result, strlen(str)+1);
	ASSERT_EQ(0, strcmp(str, result));

	destroy_data_buffer(buffer);
	mem_pool_destroy(pMemPool);
}
Ejemplo n.º 19
0
TEST(DYHASH_CHECKPOINT1, dyhashindex){
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);

	struct dyhash_index_config config;
	
	char dir_path[] = "/tmp/dyhash_index3";

	config.is_full = 0;
	config.row_limit = 2;
	strcpy(config.work_space, dir_path);
	
	
	struct dyhash_index_manager* dyhash_index = init(&config,dir_path);

	int32_t ret = 0;
	uint32_t docid = 0;
	
	struct low_data_struct data;
	data.data = mem_pool_malloc(mem_pool, strlen("hello world"));
	memset(data.data, 0, strlen("hello world"));
	strcpy((char*)data.data, "hello world");
	data.len = strlen("hello world");
	data.type = HI_TYPE_STRING;

	uint32_t i;
	for(i=0; i<10; i++)
	{
		ret = dyhash_index_insert(dyhash_index,&data,docid);
		ASSERT_EQ(0, ret);

	}
	
	dyhash_index_checkpoint(dyhash_index);


	struct rowid_list* query_ret = dyhash_index_query(dyhash_index, &data, mem_pool);
	print_rowid_list(query_ret);
}
Ejemplo n.º 20
0
	virtual void SetUp()
	{
		ClearDir();
		::mkdir(dir_.c_str(), 0755);
		mem_ = mem_pool_init( 1 << 20); // MB

		// init config
		ConfigFile &conf = *ConfigFile::GlobalInstance();
		conf.SetValue(CONF_LDB_SESSION, CONF_LDB_TABLES, "t");

		// use user specified time
		conf.SetValue(CONF_LDB_SESSION, "t.row_key", "k");
		conf.SetValue(CONF_LDB_SESSION, "t.time_key", "t");
		conf.SetValue(CONF_LDB_SESSION, "t.time_key_scale", "0");
		conf.SetValue(CONF_LDB_SESSION, "t.time_key_len", "4");

		conf.SetValue(CONF_LDB_SESSION, "t.cumulative_step", "10,100,200");
		conf.SetValue(CONF_LDB_SESSION, "t.aggregate_desc", "count(*),max(value),min(value),sum(value)");

		conf.SetValue(CONF_LDB_SESSION, "max_open_files", "512");

		engine_ = NEW(mem_, LdbEngine)(dir_.c_str(), conf);
		ASSERT_EQ(0, engine_->Init());
	}
Ejemplo n.º 21
0
TEST(BITMARK_TEST, HandleNoneZeroInput)  {
    int32 ret;
    int32 value;
    MEM_POOL* mem_pool = mem_pool_init(M_1M);  
    struct bitmark_config config; 
	strcpy(config.bitmark_name,"null");
	strcpy(config.work_space,"/tmp/bitmark_test");
	config.row_limit = 10;

	system("rm -rf /tmp/bitmark_test");
	init_profile(1000,mem_pool);
	mkdirs(config.work_space);

    struct bitmark_manager* bitmark = bitmark_init(&config, mem_pool);

    //全部置零
    bitmark_reset(bitmark);

    //置位
    //表示6行已插入该行值
    ret = bitmark_set(bitmark,6);
    ASSERT_EQ(ret,0);
    
    //查询
    value = bitmark_query(bitmark,6);
    ASSERT_EQ(value,0); 
	
    value = bitmark_query(bitmark,8);
    ASSERT_EQ(value,1);

    //删除6行的值
    ret = bitmark_clear(bitmark,6);
    ASSERT_EQ(ret,0);

    mem_pool_destroy(mem_pool);
}
Ejemplo n.º 22
0
int DocEngine::Command(struct mile_message_header* msg_head,
		struct data_buffer* rbuf, struct data_buffer* sbuf) {
	MEM_POOL_PTR mem_pool;
	void* parsed_packet;
	void* result;
	int32_t result_code = 0;
	uint16_t msg_type = msg_head->message_type;

	switch (msg_type) {
	case MT_MD_EXE_GET_KVS:
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_get_kvs_packet(mem_pool, rbuf);
		result = GetKvs((struct get_kvs_packet*) parsed_packet, mem_pool);

		if(NULL == result){
			result_code = ERROR_QUERY_BY_ROWID;
		}else{
			gen_query_result_packet((ResultSet*) result, msg_head,
					sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	case MT_CD_EXE_COMPRESS:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_compress_packet(mem_pool, rbuf);

		log_debug(
				"接收到compress命令:%s", ((struct compress_packet*)parsed_packet)->table_name);

		db_read_lock();
		result_code = db_compress(
				((struct compress_packet*) parsed_packet)->table_name,
				mem_pool);
		db_read_unlock();

		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;
	case MT_CD_EXE_INDEX:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_ensure_index_packet(mem_pool, rbuf);

		log_debug(
				"接收到ensure_index命令 %s %s %u %u", ((struct ensure_index_packet*)parsed_packet)->table_name, ((struct ensure_index_packet*)parsed_packet)->field_name, ((struct ensure_index_packet*)parsed_packet)->index_type, ((struct ensure_index_packet*)parsed_packet)->data_type);

		db_read_lock();
		result_code = db_ensure_index(
				((struct ensure_index_packet*) parsed_packet)->table_name,
				((struct ensure_index_packet*) parsed_packet)->field_name,
				((struct ensure_index_packet*) parsed_packet)->index_type,
				((struct ensure_index_packet*) parsed_packet)->data_type,
				mem_pool);

		db_read_unlock();
		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;

	case MT_CD_EXE_UNINDEX:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_del_index_packet(mem_pool, rbuf);

		log_debug(
				"接收到del_index命令 %s %s %u", ((struct del_index_packet*)parsed_packet)->table_name, ((struct del_index_packet*)parsed_packet)->field_name, ((struct del_index_packet*)parsed_packet)->index_type);

		db_read_lock();
		result_code = db_del_index(
				((struct del_index_packet*) parsed_packet)->table_name,
				((struct del_index_packet*) parsed_packet)->field_name,
				((struct del_index_packet*) parsed_packet)->index_type,
				mem_pool);
		db_read_unlock();

		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;

	case MT_CD_EXE_LOAD:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_load_segment_packet(mem_pool, rbuf);

		log_debug(
				"接收到load_segment命令 %s %u %s", ((struct load_segment_packet*)parsed_packet)->table_name, ((struct load_segment_packet*)parsed_packet)->sid, ((struct load_segment_packet*)parsed_packet)->segment_dir);

		db_read_lock();
		result_code = db_load_segment(
				((struct load_segment_packet*) parsed_packet)->table_name,
				((struct load_segment_packet*) parsed_packet)->sid,
				((struct load_segment_packet*) parsed_packet)->segment_dir,
				mem_pool);
		db_read_unlock();

		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;

	case MT_CD_EXE_REPLACE:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_replace_segment_packet(mem_pool, rbuf);

		log_debug(
				"接收到replace segments命令 %s %s", ((struct replace_segment_packet*)parsed_packet)->table_name, ((struct replace_segment_packet*)parsed_packet)->segment_dir);

		db_read_lock();
		result_code = db_replace_all_segments(
				((struct replace_segment_packet*) parsed_packet)->table_name,
				((struct replace_segment_packet*) parsed_packet)->segment_dir,
				mem_pool);
		db_read_unlock();

		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;

	case MT_CD_EXE_UNLOAD:
		mem_pool = mem_pool_init(KB_SIZE);

		parsed_packet = parse_unload_segment_packet(mem_pool, rbuf);

		log_debug(
				"接收到unload_segment命令 %s %u", ((struct unload_segment_packet*)parsed_packet)->table_name, ((struct unload_segment_packet*)parsed_packet)->sid);

		db_read_lock();
		result_code = db_unload_segment(
				((struct unload_segment_packet*) parsed_packet)->table_name,
				((struct unload_segment_packet*) parsed_packet)->sid, mem_pool);
		db_read_unlock();

		gen_dc_response_packet(result_code, msg_head, sbuf);
		mem_pool_destroy(mem_pool);
		break;

	case MT_CD_EXE_CP:
		log_debug( "get checkpoint command");
		db_checkpoint();
		gen_dc_response_packet(0, msg_head, sbuf);
		break;
	case MT_CD_STAT:
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_doc_stat_packet(mem_pool, rbuf);

		log_debug(
				"接收到stat命令 %s %u", ((struct doc_stat_packet*)parsed_packet)->table_name, ((struct doc_stat_packet*)parsed_packet)->type);

		if (((struct doc_stat_packet*) parsed_packet)->type == 1) {
			uint16_t max_segment_num = 0;
			struct segment_meta_data* result = NULL;

			db_read_lock();
			result = db_query_segment_stat(
					((struct doc_stat_packet*) parsed_packet)->table_name,
					&max_segment_num, mem_pool);
			db_read_unlock();

			gen_dc_segment_stat_packet(result, max_segment_num, msg_head, sbuf);
		}

		if (((struct doc_stat_packet*) parsed_packet)->type == 2) {
			uint16_t index_field_count = 0;
			struct index_field_meta* result = NULL;

			db_read_lock();
			result = db_query_index_stat(
					((struct doc_stat_packet*) parsed_packet)->table_name,
					&index_field_count, mem_pool);
			db_read_unlock();

			gen_dc_index_stat_packet(result, index_field_count, msg_head, sbuf);
		}

		mem_pool_destroy(mem_pool);
		break;
	default:
		log_error("unsupported command, packet type %d", msg_type);
		result_code = ERROR_UNSUPPORTED_SQL_TYPE;
		break;
	}

	return result_code;
}
Ejemplo n.º 23
0
TEST(BTREETEST, HandleNoneZeroInput)  {
	MEM_POOL_PTR pMemPool = mem_pool_init(M_1M); 
	BTREE_PTR pBtree = btree_init(pMemPool, "zbtree_index", "/tmp/", 3*MAX, HI_TYPE_LONGLONG);
//	BTREE_PTR pBtree = btree_init(pMemPool, "zbtree_index", "/tmp/", 3*MAX, HI_TYPE_LONG);
	BTREE_PTR pBtree2 = btree_init(pMemPool, "zbtree_index2", "/tmp/", 3*MAX, HI_TYPE_DOUBLE);

	init_profile(1000, pMemPool);
	/*
	struct timeval start, end, end2;               
	double interval; 
	gettimeofday(&start, NULL);

	srand((unsigned int)time(NULL)); 
	int res,i;
	uint64 num;
	//插入10万数据
	for ( i = 0; i < MAX; i += 1 )
	{
		num = rand()%MAX;
		res = btree_insert(pMemPool, pBtree, num, i);
		ASSERT_EQ(res, 0);
	}
	gettimeofday(&end, NULL);
	interval = 1000000*(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
	printf("insert %d data, cost %.2f ms\n", MAX, interval /1000);

	//范围查询10万次
	BTREE_ENTRY_PTR pBtreeEntry;
	uint32 num2;
//	struct rowid_list *pRowidList;
	for ( i = 0; i < MAX; i += 1 )
	{
		num = rand()%MAX+100;
		pBtreeEntry = btree_search(pBtree, num, CT_LE);
//		num2 = rand()%MAX+100;
//		struct rowid_list * pRowidList = btree_range_query(pBtree, num, 0, num2, 0, pMemPool);
//		if(pRowidList!=NULL)
//		{
//			printf("%d:", i);
//			print_rowid_list(pRowidList);
//		}
		//		ASSERT_EQ((pBtreeEntry != NULL), 1);
	}
	gettimeofday(&end2, NULL);
	interval = 1000000*(end2.tv_sec - end.tv_sec) + (end2.tv_usec - end.tv_usec);
	printf("search %d data, cost %.2f ms\n", MAX, interval /1000);
	*/
	
	//插入3 7 7 9 11 2 4 5 6 8
	int res = btree_insert(pMemPool, pBtree, 3, 1);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 7, 2);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 7, 10);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 9, 3);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 11, 4);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 2, 5);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 4, 6);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 5, 7);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 6, 8);
	ASSERT_EQ(res, 0);
	res = btree_insert(pMemPool, pBtree, 8, 9);
	ASSERT_EQ(res, 0);

	//等值查找3 9 8
//	long long value = 3;
	BTREE_ENTRY_PTR pBtreeEntry = btree_search(pBtree, 3, CT_EQ);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 3);
	pBtreeEntry = btree_search(pBtree, 9, CT_EQ);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 9);
	pBtreeEntry = btree_search(pBtree, 1, CT_EQ);
	ASSERT_EQ((pBtreeEntry == NULL), 1);

	//查找<7 <6 
	pBtreeEntry = btree_search(pBtree, 7, CT_LT);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 6);
	pBtreeEntry = btree_search(pBtree, 6, CT_LT);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 5);

	//查找>7 >6 
	pBtreeEntry = btree_search(pBtree, 7, CT_GT);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 8);
	pBtreeEntry = btree_search(pBtree, 6, CT_GT);
	ASSERT_EQ((pBtreeEntry != NULL), 1);
	ASSERT_EQ(pBtreeEntry->key, 7);

	//测试btree next
	//BTREE_ENTRY_PTR pEntry = btree_search(pBtree, 2, 0);
	BTREE_ENTRY_PTR pEntry = btree_get_start_entry(pBtree);
	struct doc_row_unit *pUnit;
	while(pEntry != NULL)
	{
		std::cout << "key = " << pEntry->key << " docID: ";
		//输出doclist
		pUnit = doclist_next(pBtree->pDoclist, pEntry->doclist);
		while(pUnit != NULL)
		{
			std::cout << pUnit->doc_id << " ";
			pUnit = doclist_next(pBtree->pDoclist, pUnit->next);
		}
		pEntry = btree_next(pBtree, pEntry);
		std::cout << std::endl;
	}
	std::cout << std::endl;

	struct rowid_list * pRowidList = btree_range_query(pBtree, 0, 0, 10, 0, pMemPool);
	print_rowid_list(pRowidList);

	BTREE_KEY key;
	double value;
	//insert 3.1 11.11 111.111 1111.1 11111.1 11.11
	value =3.1;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 1);
	ASSERT_EQ(res, 0);

	value =11.11;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 2);
	ASSERT_EQ(res, 0);

	value =111.111;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 3);
	ASSERT_EQ(res, 0);

	value =1111.1;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 4);
	ASSERT_EQ(res, 0);

	value =11111.1;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 5);
	ASSERT_EQ(res, 0);

	value =11.11;
	memcpy(&key, &value, 8);
	res = btree_insert(pMemPool, pBtree2, key, 6);
	ASSERT_EQ(res, 0);

	value =1111;
	memcpy(&key, &value, 8);
	pRowidList = btree_range_query(pBtree2, 0, 0, key, 0, pMemPool);
	print_rowid_list(pRowidList);

	pEntry = btree_get_start_entry(pBtree2);
	while(pEntry != NULL)
	{
		std::cout << "key = " << *(double*)&pEntry->key << " docID: ";
		//输出doclist
		pUnit = doclist_next(pBtree2->pDoclist, pEntry->doclist);
		while(pUnit != NULL)
		{
			std::cout << pUnit->doc_id << " ";
			pUnit = doclist_next(pBtree2->pDoclist, pUnit->next);
		}
		pEntry = btree_next(pBtree2, pEntry);
		std::cout << std::endl;
	}
	std::cout << std::endl;
	//测试dump
	//btree_dump(pBtree);
	btree_destroy(pBtree);
	btree_destroy(pBtree2);
}
Ejemplo n.º 24
0
DocEngine::DocEngine(const char *storage_dir, const ConfigFile &conf) :
		storage_dir_(storage_dir), conf_(&conf), db_conf_(NULL) {
	mem_ = mem_pool_init(1 << 20);
}
Ejemplo n.º 25
0
int32_t process_mergeserver_message(struct mile_message_header* msg_head,
		struct data_buffer* rbuf, struct data_buffer* sbuf,
		int16_t exceed_cpu_used, uint64_t deadline_time) {
	int32_t result_code = MILE_RETURN_SUCCESS;
	MEM_POOL_PTR mem_pool;
	void* parsed_packet;
	ExecutePlan* plan = NULL;
	void* result;

	switch (msg_head->message_type) {
	case MT_MD_EXE_INSERT:
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_insert_packet(mem_pool, rbuf);
		plan = SqlAnalyzer::Analyze(StorageEngine::storage,
				(struct insert_packet*) parsed_packet, mem_pool);
		if (plan == NULL) {
			result_code = -1;
		} else {
			result = plan->Execute(result_code, deadline_time);
			plan->~ExecutePlan();
		}
		if (result_code == MILE_RETURN_SUCCESS) {
			gen_insert_result_packet(*(uint64_t*) result, msg_head, sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	case MT_MD_EXE_DELETE:
		if (exceed_cpu_used) {
			log_warn("cpu使用率超出,拒绝UPDATE QUERY DELETE服务");
			break;
		}
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_delete_packet(mem_pool, rbuf);
		plan = SqlAnalyzer::Analyze(StorageEngine::storage,
				(struct delete_packet*) parsed_packet, mem_pool);
		if (plan == NULL) {
			result_code = -1;
		} else {
			result = plan->Execute(result_code, deadline_time);
			plan->~ExecutePlan();
		}

		if (result_code == MILE_RETURN_SUCCESS) {
			gen_delete_result_packet(*(uint32_t*) result, msg_head, sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	case MT_MD_EXE_EXPORT: {
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_export_packet(mem_pool, rbuf);
		plan = SqlAnalyzer::Analyze(StorageEngine::storage,
				(struct export_packet *) parsed_packet, mem_pool);
		if (plan == NULL) {
			result_code = -1;
		} else {
			result = plan->Execute(result_code, deadline_time);
			plan->~ExecutePlan();
		}

		if (result_code == MILE_RETURN_SUCCESS) {
			gen_export_result_packet(*(uint64_t*) result, msg_head, sbuf);
		}

		mem_pool_destroy(mem_pool);
	}
		break;
	case MT_MD_EXE_UPDATE:
		if (exceed_cpu_used) {
			log_warn("cpu使用率超出,拒绝UPDATE QUERY DELETE服务");
			break;
		}
		mem_pool = mem_pool_init(MB_SIZE);
		parsed_packet = parse_update_packet(mem_pool, rbuf);
		plan = SqlAnalyzer::Analyze(StorageEngine::storage,
				(struct update_packet*) parsed_packet, mem_pool);
		if (plan == NULL) {
			result_code = -1;
		} else {
			result = plan->Execute(result_code, deadline_time);
			plan->~ExecutePlan();
		}

		if (result_code == MILE_RETURN_SUCCESS) {
			gen_update_result_packet(*(uint32_t*) result, msg_head, sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	case MT_MD_EXE_QUERY:
		if (exceed_cpu_used) {
			log_warn("cpu使用率超出,拒绝UPDATE QUERY DELETE服务");
			break;
		}
		mem_pool = mem_pool_init(MB_SIZE);

		result_code = loadavg_check(); // check overloading
		if (ERROR_OS_OVERLOADING == result_code) {
			log_warn(
					"OS overloading, discard packet msg id %"PRIu32, msg_head->message_id);
		} else if (0 == result_code) {
			parsed_packet = parse_query_packet(mem_pool, rbuf);
			plan = SqlAnalyzer::Analyze(StorageEngine::storage,
					(struct query_packet*) parsed_packet, mem_pool);
			if (plan == NULL) {
				result_code = -1;
			} else {
				result = plan->Execute(result_code, deadline_time);
				plan->~ExecutePlan();
			}
		}

		if (result_code == MILE_RETURN_SUCCESS) {
			gen_query_result_packet((ResultSet*) result, msg_head, sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	case MT_MD_GET_STATE:
		mem_pool = mem_pool_init(KB_SIZE);
		parsed_packet = parse_get_state_packet(mem_pool, rbuf);
		result = StateManager::QueryStates(StorageEngine::storage,
				(struct get_state_packet*) parsed_packet, mem_pool);
		if (result == NULL) {
			result_code = ERROR_GET_DOCSERVER_STATE;
		} else {
			gen_state_result_packet((struct stat_info_array*) result, msg_head,
					sbuf);
		}
		mem_pool_destroy(mem_pool);
		break;
	default:
		result_code = StorageEngine::storage->SpecialSql(msg_head, rbuf, sbuf);
		break;
	}

	if (result_code < 0) {
		gen_error_packet(result_code, msg_head, sbuf);
	}
	return result_code;
}
Ejemplo n.º 26
0
TEST(HASHINDEX_TEST, HandleNoneZeroInput)  {
    MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
    struct hash_index_config config;

    system("rm -rf /tmp/hashindex_test");
    char dir_path[] = "/tmp/hashindex_test";
    mkdirs(dir_path);
    config.row_limit = BUCKET_NUM;
    strcpy(config.work_space,dir_path);

    init_profile(1000,mem_pool);
    int32_t ret;

    //插入一个值
    struct low_data_struct insert_data;
    get_low_data(&insert_data,mem_pool);

    struct hash_index_manager* hash_index = hash_index_init(&config,mem_pool);
    ret = hash_index_insert(hash_index,&insert_data,0);
    ASSERT_EQ(ret,0);

    //查询
    struct rowid_list* rowids;

    uint32_t i;
    struct rowid_list_node* p;

    rowids = hash_index_query(hash_index,&insert_data,mem_pool);

    for(i = 0, p = rowids->head; i < rowids->rowid_num; i++)
    {
        if(i != 0 && i%ROWID_ARRAY_SIZE == 0)
        {
            p = p->next;
        }
        ASSERT_EQ(p->rowid_array[i%ROWID_ARRAY_SIZE],0);
        break;
    }

    //再插入一个值
    hash_index_insert(hash_index,&insert_data,1);

    rowids = hash_index_query(hash_index,&insert_data,mem_pool);


    for(i = 0, p = rowids->head; i < rowids->rowid_num; i++)
    {
        if(i != 0 && i%ROWID_ARRAY_SIZE == 0)
        {
            p = p->next;

            if(i==0)
                ASSERT_EQ(p->rowid_array[i%ROWID_ARRAY_SIZE],1);

            if(i==1)
            {
                ASSERT_EQ(p->rowid_array[i%ROWID_ARRAY_SIZE],0);
                break;
            }
        }
    }

    //插入BUCKET_NUM个
    for(i=2; i<BUCKET_NUM+1; i++)
    {
        sprintf((char*)insert_data.data,"ali%u",i);
        ret = hash_index_insert(hash_index,&insert_data,i);
        ASSERT_EQ(ret,0);
    }

    //再插一个报冲突了
    sprintf((char*)insert_data.data,"ali%u",i);
    ret = hash_index_insert(hash_index,&insert_data,i);
    ASSERT_EQ(ret,ERROR_HASH_CONFLICT);

    //插入一个空值,OK
    insert_data.len = 0;
    ret = hash_index_insert(hash_index,&insert_data,i);
    ASSERT_EQ(ret,0);

    rowids = hash_index_query(hash_index,&insert_data,mem_pool);

    ASSERT_EQ(rowids->rowid_num,1);
    ASSERT_EQ(rowids->head->rowid_array[0],5);

    hash_index_release(hash_index);
    mem_pool_destroy(mem_pool);
}
Ejemplo n.º 27
0
TEST(RECOVER_TEST_2, HandleNoneZeroInput)  {
    MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);
    struct hash_index_config config;

    system("rm -rf /tmp/hashindex_test");
    char dir_path[] = "/tmp/hashindex_test";
    mkdirs(dir_path);
    config.row_limit = ROW_LIMIT;
    strcpy(config.work_space,dir_path);

    init_profile(1000,mem_pool);
    int32_t ret;

    struct hash_index_manager* hash_index = hash_index_init(&config,mem_pool);

    //插入18条数据,只恢复16条
    uint32_t i;
    struct low_data_struct* data = (struct low_data_struct*)mem_pool_malloc(mem_pool, sizeof(struct low_data_struct));
    memset(data, 0, sizeof(struct low_data_struct));

    for(i=0; i<18; i++)
    {
        if(i != 0 && i%2 == 1)
            continue;

        data->len = 5;
        data->data = mem_pool_malloc(mem_pool,5);
        data->type = HI_TYPE_STRING;
        data->field_name = (char*)mem_pool_malloc(mem_pool,20);
        memset(data->field_name,0,20);
        strcpy(data->field_name,"HI_TYPE_STRING");
        memset(data->data,0,5);
        ret = hash_index_insert(hash_index,data,i);
        ASSERT_EQ(0, ret);
        ret = hash_index_insert(hash_index,data,i+1);
        ASSERT_EQ(0, ret);
    }

    struct doc_row_unit* doc = NULL;

    ASSERT_EQ(0, hash_index_recover(hash_index, 16));

    for(i=0; i<ROW_LIMIT; i++)
    {
        doc = GET_DOC_ROW_STRUCT(hash_index->doclist, i);
    }

    //验证
    for(i=0; i<16; i++)
    {
        doc = GET_DOC_ROW_STRUCT(hash_index->doclist, i);
        ASSERT_EQ(i, doc->doc_id);
    }

    for(i=16; i<ROW_LIMIT; i++)
    {
        doc = GET_DOC_ROW_STRUCT(hash_index->doclist, i);
        ASSERT_EQ(0, doc->doc_id);
        ASSERT_EQ(0,doc->next);
    }

    struct hash_bucket* hbucket = NULL;
    uint32_t bucket_no = 0;

    for(i=0; i<ROW_LIMIT+1; i++)
    {
        hbucket = hash_index->mem_mmaped + i;
        doc = NEXT_DOC_ROW_STRUCT(hash_index->doclist, hbucket->offset);

        if(hbucket->hash_value == 0)
        {
            continue;
        }

        while(!(doc->next & 0x80000000))
        {
            ASSERT_GT(16, doc->doc_id);
            doc = NEXT_DOC_ROW_STRUCT(hash_index->doclist, doc->next);
        }

        bucket_no = doc->next & 0x7fffffff;
        ASSERT_EQ(i,bucket_no);
    }

    hash_index_release(hash_index);
    mem_pool_destroy(mem_pool);
}
Ejemplo n.º 28
0
int main()
{
    mem_pool_init();
    int i;
    void *a;
    void *b;
    /*
    for(i=0;i<1000;i++)
    {
        a=mem_alloc(5);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)a);
        i++;        
        b=mem_alloc(5);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)b);
        mem_free(a);
        mem_free(b);
    }

    for(i=0;i<1000;i++)
    {
        a=mem_alloc(18);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)a);
        i++;        
        b=mem_alloc(18);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)b);
        mem_free(a);
        mem_free(b);
    }
    */
    /*
    for(i=0;i<1000;i++)
    {
        a=mem_alloc(10);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)a);
        i++;        
        b=mem_alloc(10);
        printf("+++++++++++++++the %d addr is %x\n",i,(unsigned int)b);
        mem_free(a);
        mem_free(b);
    }
    */
    /*
    printf("the mem alloc is %x\n",(int)a);
    //mem_free(a);
    a=mem_alloc(9);
    //printf("the mem alloc 9 ++++++++++++++++++is %x\n",(int)a);
    mem_free(a);
    a=mem_alloc(18);
    printf("the mem alloc is %x\n",(int)a);
    a=mem_alloc(100);
    free(a);
    */
    clock_t t1,t2,ta,tb;
    t1=clock();
    int t;
    for(t=0;t<0x0ffffffa;t++)
    {
        a=mem_alloc(5);
        mem_free(a);
    }
    t2=clock();
    ta=t2-t1;
    t1=clock();
    for(t=0;t<0x0ffffffa;t++)
    {
        a=malloc(5);
        free(a);
    }
    t2=clock();
    tb=t2-t1;
    printf("the time %ld\t%ld\n",ta,tb);
	system("pause");
}
Ejemplo n.º 29
0
int create_sync_list()
{

#if MEM_POOL_ENABLE
        mem_pool_init();
        printf("######eable mem  pool######\n");
#endif

    local_sync = 0;
    server_sync = 1;
    finished_initial = 0;
    LOCAL_FILE.path = NULL;
    int i;
    int num=asus_cfg.dir_number;
    g_pSyncList = (sync_list **)malloc(sizeof(sync_list *)*num);
    memset(g_pSyncList,0,sizeof(sync_list *)*num);
#if TOKENFILE
    sighandler_finished = 0;
#endif
    for(i=0;i<asus_cfg.dir_number;i++)
    {
        g_pSyncList[i] = (sync_list *)malloc(sizeof(sync_list));
        memset(g_pSyncList[i],0,sizeof(sync_list));

        g_pSyncList[i]->receve_socket = 0;
        g_pSyncList[i]->have_local_socket = 0;
        g_pSyncList[i]->first_sync = 1;
        g_pSyncList[i]->no_local_root = 0;
        g_pSyncList[i]->init_completed = 0;
#if TOKENFILE
        g_pSyncList[i]->sync_disk_exist = 0;
#endif

//        sprintf(g_pSyncList[i]->temp_path,"%s/.smartsync/dropbox",asus_cfg.prule[i]->base_path);
//        my_mkdir_r(g_pSyncList[i]->temp_path);    //have mountpath

//        snprintf(g_pSyncList[i]->conflict_file,255,"%s/conflict_%s",
//                 g_pSyncList[i]->temp_path,asus_cfg.prule[i]->rooturl+1);

        g_pSyncList[i]->ServerRootNode = NULL;
        g_pSyncList[i]->OldServerRootNode = NULL;
        g_pSyncList[i]->VeryOldServerRootNode = NULL;
        g_pSyncList[i]->SocketActionList = queue_create();
        g_pSyncList[i]->unfinished_list = create_action_item_head();
        g_pSyncList[i]->up_space_not_enough_list = create_action_item_head();
        g_pSyncList[i]->server_action_list = create_action_item_head();
        g_pSyncList[i]->copy_file_list = create_action_item_head();
        g_pSyncList[i]->access_failed_list = create_action_item_head();
        if(asus_cfg.prule[i]->rule == 1)
        {
            g_pSyncList[i]->download_only_socket_head = create_action_item_head();
        }
        else
        {
            g_pSyncList[i]->download_only_socket_head = NULL;
        }

#if TOKENFILE
        tokenfile_info_tmp = tokenfile_info_start->next;
        while(tokenfile_info_tmp != NULL)
        {
            //printf("asus_cfg.prule[%d]->rooturl=%s,asus_cfg.user=%s\n",i,asus_cfg.prule[i]->rooturl,asus_cfg.user);
            //printf("tokenfile_info_tmp->folder=%s,tokenfile_info_tmp->url=%s\n",tokenfile_info_tmp->folder,tokenfile_info_tmp->url);
            if(!strcmp(tokenfile_info_tmp->folder,asus_cfg.prule[i]->rooturl) && !strcmp(tokenfile_info_tmp->url,asus_cfg.user))
            {
                g_pSyncList[i]->sync_disk_exist = 1;
                /*
                 fix below bug:
                    rm sync dir,change the sync dir,can not create sync dir
                */
                if(access(asus_cfg.prule[i]->path,F_OK))
                {
                    my_mkdir_r(asus_cfg.prule[i]->path);
                }
                break;
            }
            tokenfile_info_tmp = tokenfile_info_tmp->next;
        }
#endif
    }
}
Ejemplo n.º 30
0
TEST(DYHASH_INDEX_TEST2, dyhashindex)  {
	MEM_POOL* mem_pool = mem_pool_init(MB_SIZE);

	struct dyhash_index_config config;
	
	char dir_path[] = "/tmp/dyhash_index2";

	config.is_full = 0;
	config.row_limit = 2;
	strcpy(config.work_space, dir_path);
	
	
	struct dyhash_index_manager* dyhash_index = init(&config,dir_path);

	int32_t ret = 0;
	uint32_t docid = 0;
	
	struct low_data_struct data;
	data.data = mem_pool_malloc(mem_pool, strlen("hello world"));
	memset(data.data, 0, strlen("hello world"));
	strcpy((char*)data.data, "hello world");
	data.len = strlen("hello world");
	data.type = HI_TYPE_STRING;
	
	strcpy((char*)data.data, "hello1world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);
	
	
	strcpy((char*)data.data, "hello2world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello3world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello4world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);
	
	
	strcpy((char*)data.data, "hello5world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	
	strcpy((char*)data.data, "hello6world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	
	strcpy((char*)data.data, "hello7world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello8world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);

	strcpy((char*)data.data, "hello9world");
    ret = dyhash_index_insert(dyhash_index,&data,docid);
	ASSERT_EQ(0, ret);
	
	uint32_t count = dyhash_index_count_query(dyhash_index, &data, mem_pool);
	ASSERT_EQ(1,count);
}