Example #1
0
/* Return a pointer to an option in CFG, or NULL if it doesn't exist.
   if SECTIONP is non-null, return a pointer to the option's section.
   OPTION may be NULL. */
static cfg_option_t *
find_option(svn_config_t *cfg, const char *section, const char *option,
            cfg_section_t **sectionp)
{
  void *sec_ptr = get_hash_value(cfg->sections, cfg->tmp_key, section,
                                 cfg->section_names_case_sensitive);
  if (sectionp != NULL)
    *sectionp = sec_ptr;

  if (sec_ptr != NULL && option != NULL)
    {
      cfg_section_t *sec = sec_ptr;
      cfg_option_t *opt = get_hash_value(sec->options, cfg->tmp_key, option,
                                         cfg->option_names_case_sensitive);
      /* NOTE: ConfigParser's sections are case sensitive. */
      if (opt == NULL
          && apr_strnatcasecmp(section, SVN_CONFIG__DEFAULT_SECTION) != 0)
        /* Options which aren't found in the requested section are
           also sought after in the default section. */
        opt = find_option(cfg, SVN_CONFIG__DEFAULT_SECTION, option, &sec);
      return opt;
    }

  return NULL;
}
Example #2
0
const char * get_key_value(void *cfgdata,const char *section, const char *key_name, const char *def)
{
  conf_section_t *psect = NULL;
  int i;
#ifdef WITH_HASH
  unsigned short vhash;
#endif
  cfgdata_t *cd = (cfgdata_t *)cfgdata;

#ifdef WITH_HASH
  /* search for the section name... */
  /* first search in the hash table... */
  vhash = get_hash_value(section) % CONF_HASH_SECTION_SIZE;
  if (cd->m_Hash[vhash] != NULL && strcasecmp(section, cd->m_Hash[vhash]->section_name) == 0)
  {
    psect = cd->m_Hash[vhash]; /* found this section in the hash table */
  }
#endif

  if (psect == NULL)
  {
    /* Not found in the hash table, do a normal search... */
    for (i = 0; i < cd->section_count; i++)
    {
      if (strcasecmp(cd->psection[i].section_name, section) == 0)
      {
        psect = &cd->psection[i];
        break;
      }
    }
  }

  if (psect != NULL)
  {
#ifdef WITH_HASH
    /* section found, search for the key in this section... */
    vhash = get_hash_value(key_name) % CONF_HASH_KEY_SIZE;
    if (psect->hash[vhash] != NULL && strcasecmp(key_name, psect->hash[vhash]->key_name) == 0)
    {
      return psect->hash[vhash]->key_value;
    }
#endif
    /* not found in the hash table, do a normal linear search... */
    for (i = 0; i < psect->key_count; i++)
    {
      if (strcasecmp(psect->keys[i].key_name, key_name) == 0)
      {
        return psect->keys[i].key_value;
      }
    }
  }

  return def; /* key is not found; use default value */
}
Example #3
0
/* add node to cluster */
int add_node(cluster_t *cluster, char *addr, int port)
{
    debug_argv(" add_node:%s %d \n",addr, port);
    int i = 0;
    if(cluster->nodes_num >= MAX_NODE_NUM)
        return -1;
    server_node_t *node = (server_node_t *)malloc(sizeof(server_node_t));
    memcpy(node->addr, addr, strlen(addr));
    node->addr[strlen(addr)] = '\0';
    node->port = port;
    node->fd = -1;
    if(cluster->nodes_num == 0)
    {
        node->hash = MAX_NODE_NUM;
        debug("add_node start:%d     hash:%d\n",i,node->hash);
        for(i = 0;i<MAX_NODE_NUM;i++)
            cluster->nodes[i] = node;
    }
    else
    {
        int start;
        node->hash = get_hash_value(cluster, cluster->nodes_num, &start);
        debug("add_node start:%d     hash:%d\n",start,node->hash);
        for (i = start; i<node->hash;i++)
            cluster->nodes[i] = node;
    }
    cluster->nodes_num ++;
    return 0;
}
Example #4
0
/* Replace an entry from the hash table. The entry is returned, or NULL if it wasn't found */
void *ght_replace(ght_hash_table_t *p_ht,
		  void *p_entry_data,
		  unsigned int i_key_size, const void *p_key_data)
{
  ght_hash_entry_t *p_e;
  ght_hash_key_t key;
  ght_uint32_t l_key;
  void *p_old;

  DEBUG_ASSERT(p_ht);

  hk_fill(&key, i_key_size, p_key_data);

  l_key = get_hash_value(p_ht, &key) & p_ht->i_size_mask;

  /* Check that the first element in the list really is the first. */
  DEBUG_ASSERT( p_ht->pp_entries[l_key]?p_ht->pp_entries[l_key]->p_prev == NULL:1 );

  /* LOCK: p_ht->pp_entries[l_key] */
  p_e = search_in_bucket(p_ht, l_key, &key, (unsigned char)p_ht->i_heuristics);
  /* UNLOCK: p_ht->pp_entries[l_key] */

  if ( !p_e )
    return NULL;

  p_old = p_e->p_data;
  p_e->p_data = p_entry_data;

  return p_old;
}
void insert()
{
	int ele,val,i=0,pos,j;
	scanf("%d",&ele);
	val=get_hash_value(ele,size);
	while(1)
	{
		if(i>=size)
		{
			printf("Hashtable is full \n");
			return;
		}
		pos=(val+i*i)%size;
		printf("%d ",pos);
		if(hashtable[pos]==-32000)
		{
			hashtable[pos]=ele;
			//printf("%d \n",pos);
			break;
		}
		else
		{
			i++;
		}
	}
}
void search()
{
	int ele,val,pos,i=0;
	scanf("%d",&ele);
	val=get_hash_value(ele,size);
	while(i<size)
	{
		pos=(val+i*i)%size;
		printf("%d ",pos);
		if(hashtable[pos]==ele)
		{
			printf("FOUND \n");
			return;
		}
		else if(hashtable[pos]==-32000)
		{
			printf("NOT FOUND \n");
			return;
		}
		else
		{
			i++;
		}
	}
}
Example #7
0
 int list_hash(caValue* value)
 {
     int hash = 0;
     int count = list_length(value);
     for (int i=0; i < count; i++) {
         hash ^= get_hash_value(list_get(value, i));
     }
     return hash;
 }
Example #8
0
/*
 * For a given key, compute the hash value and return the id of the lock
 * protecting the corresponding partition.
 */
static LWLockId
SyncHTPartLockId(SyncHT *syncHT, void *key)
{
	Assert(NULL != syncHT);
	Assert(NULL != syncHT->ht);
	Assert(NULL != key);

	uint32 hashValue = get_hash_value(syncHT->ht, key);
	return (syncHT->baseLWLockId + (hashValue % syncHT->numPartitions));
}
Example #9
0
TEST(HASH_TEST, HandleNoneZeroInput)  {
    //hash32╬╗
    char str_a[5];
    char str_b[5];
    memset(str_a,0,sizeof(str_a));
    memset(str_b,0,sizeof(str_b));

	struct low_data_struct data_a;
	struct low_data_struct data_b;
    
    //▓Р╩н╣■¤Б
    uint32 a = 14141;
    sprintf(str_a,"%u",a);
	data_a.data = str_a;
	data_a.type = HI_TYPE_SHORT;
    uint64 a_hash = get_hash_value(&data_a);

    uint32 b = 12414;
    sprintf(str_b,"%u",b);
	data_b.data = str_b;
	data_b.type = HI_TYPE_SHORT;
    uint64 b_hash = get_hash_value(&data_b);  
    
    ASSERT_NE(a_hash,b_hash);

	//▓Р╩н┐Нох
	data_a.len = 0;
	data_b.len = 0;

	data_a.type = HI_TYPE_STRING;
	a_hash = get_hash_value(&data_a);
	data_b.type = HI_TYPE_STRING;
	b_hash = get_hash_value(&data_b);

	ASSERT_EQ(a_hash,b_hash);
}
Example #10
0
/* Remove an entry from the hash table. The removed entry, or NULL, is
   returned (and NOT free'd). */
void *ght_remove(ght_hash_table_t *p_ht,
		 unsigned int i_key_size, const void *p_key_data)
{
  ght_hash_entry_t *p_out;
  ght_hash_key_t key;
  ght_uint32_t l_key;
  void *p_ret=NULL;

  DEBUG_ASSERT(p_ht);

  hk_fill(&key, i_key_size, p_key_data);
  l_key = get_hash_value(p_ht, &key) & p_ht->i_size_mask;

  /* Check that the first element really is the first */
  DEBUG_ASSERT( (p_ht->pp_entries[l_key]?p_ht->pp_entries[l_key]->p_prev == NULL:1) );

  /* LOCK: p_ht->pp_entries[l_key] */
  p_out = search_in_bucket(p_ht, l_key, &key, 0);

  /* Link p_out out of the list. */
  if (p_out)
    {
      remove_from_chain(p_ht, l_key, p_out);

      /* This should ONLY be done for normal items (for now all items) */
      p_ht->i_items--;

      p_ht->p_nr[l_key]--;
      /* UNLOCK: p_ht->pp_entries[l_key] */
#if !defined(NDEBUG)
      p_out->p_next = NULL;
      p_out->p_prev = NULL;
#endif /* NDEBUG */

      p_ret = p_out->p_data;
      he_finalize(p_ht, p_out);
    }
  /* else: UNLOCK: p_ht->pp_entries[l_key] */

  return p_ret;
}
Example #11
0
/* Get an entry from the hash table. The entry is returned, or NULL if it wasn't found */
void *ght_get(ght_hash_table_t *p_ht,
	      unsigned int i_key_size, const void *p_key_data)
{
  ght_hash_entry_t *p_e;
  ght_hash_key_t key;
  ght_uint32_t l_key;

  assert(p_ht);

  hk_fill(&key, i_key_size, p_key_data);

  l_key = get_hash_value(p_ht, &key) & p_ht->i_size_mask;

  /* Check that the first element in the list really is the first. */
  assert( p_ht->pp_entries[l_key]?p_ht->pp_entries[l_key]->p_prev == NULL:1 );

  /* LOCK: p_ht->pp_entries[l_key] */
  p_e = search_in_bucket(p_ht, l_key, &key, p_ht->i_heuristics);
  /* UNLOCK: p_ht->pp_entries[l_key] */

  return (p_e?p_e->p_data:NULL);
}
Example #12
0
/* Insert an entry into the hash table */
int ght_insert(ght_hash_table_t *p_ht,
	       void *p_entry_data,
	       unsigned int i_key_size, const void *p_key_data)
{
  ght_hash_entry_t *p_entry;
  ght_uint32_t l_key;
  ght_hash_key_t key;

  DEBUG_ASSERT(p_ht);

  hk_fill(&key, i_key_size, p_key_data);
  l_key = get_hash_value(p_ht, &key) & p_ht->i_size_mask;
  if (search_in_bucket(p_ht, l_key, &key, 0))
    {
      /* Don't insert if the key is already present. */
      return -1;
    }
  p_entry = he_create(p_ht, p_entry_data, i_key_size, p_key_data);
  if (!(p_entry))
    {
      return -2;
    }

  /* Rehash if the number of items inserted is too high. */
  if (p_ht->i_automatic_rehash && p_ht->i_items > 2*p_ht->i_size)
    {
      ght_rehash(p_ht, 2*p_ht->i_size);
      /* Recalculate l_key after ght_rehash has updated i_size_mask */
      l_key = get_hash_value(p_ht, &key) & p_ht->i_size_mask;
    }

  /* Place the entry first in the list. */
  p_entry->p_next = p_ht->pp_entries[l_key];
  p_entry->p_prev = NULL;
  if (p_ht->pp_entries[l_key])
    {
      p_ht->pp_entries[l_key]->p_prev = p_entry;
    }
  p_ht->pp_entries[l_key] = p_entry;

  /* If this is a limited bucket hash table, potentially remove the last item */
  if (p_ht->bucket_limit != 0 &&
      p_ht->p_nr[l_key] >= p_ht->bucket_limit)
    {
      ght_hash_entry_t *p;

      /* Loop through entries until the last
       *
       * FIXME: Better with a pointer to the last entry
       */
      for (p = p_ht->pp_entries[l_key];
	   p->p_next != NULL;
	   p = p->p_next);

      DEBUG_ASSERT(p && p->p_next == NULL);

      remove_from_chain(p_ht, l_key, p); /* To allow it to be reinserted in fn_bucket_free */
      p_ht->fn_bucket_free(p->p_data, p->key.p_key);

      he_finalize(p_ht, p);
    }
  else
    {
      p_ht->p_nr[l_key]++;

      DEBUG_ASSERT( p_ht->pp_entries[l_key]?p_ht->pp_entries[l_key]->p_prev == NULL:1 );

      p_ht->i_items++;
    }

  if (p_ht->p_oldest == NULL)
    {
      p_ht->p_oldest = p_entry;
    }
  p_entry->p_older = p_ht->p_newest;

  if (p_ht->p_newest != NULL)
    {
      p_ht->p_newest->p_newer = p_entry;
    }

  p_ht->p_newest = p_entry;

  return 0;
}
Example #13
0
    ret = db_load_segment("hello",sid,segment_file_name,mem_pool);
    ASSERT_EQ(MILE_RETURN_SUCCESS,ret);

    index_equal_ret = db_index_equal_query("hello",get_time_hint(mem_pool),data,mem_pool);

    list_for_each_entry(node,index_equal_ret,rowids_list) {
        if(node->sid == 0)
            ASSERT_EQ(node->rowids->rowid_num,10);
        else if(node->sid == 1)
            ASSERT_EQ(node->rowids->rowid_num,1);
        else
            FAIL();
    }

    index_value_ret = db_index_value_query("hello",sid,"HI_TYPE_STRING",docid,mem_pool);
    ASSERT_EQ(*(uint64*)index_value_ret->data,get_hash_value(data));

    index_value_ret = db_index_value_query("hello",sid,"HI_TYPE_TINY",docid,mem_pool);
    ASSERT_EQ(*(int8*)(index_value_ret->data),1);

    db_release();
}


TEST(DUMP_TEST, HandleNoneZeroInput) {
    MEM_POOL* mem_pool = mem_pool_init(M_1M);

    //初始化DB
    init_profile(1000,mem_pool);

    test_single_dump(mem_pool);
Example #14
0
svn_boolean_t
svn_config_has_section(svn_config_t *cfg, const char *section)
{
  return NULL != get_hash_value(cfg->sections, cfg->tmp_key, section,
                                cfg->section_names_case_sensitive);
}
Example #15
0
/*
 * BufTableHashCode
 *		Compute the hash code associated with a BufferTag
 *
 * This must be passed to the lookup/insert/delete routines along with the
 * tag.  We do it like this because the callers need to know the hash code
 * in order to determine which buffer partition to lock, and we don't want
 * to do the hash computation twice (hash_any is a bit slow).
 */
uint32
BufTableHashCode(BufferTag *tagPtr)
{
	return get_hash_value(SharedBufHash, (void *) tagPtr);
}
Example #16
0
//也是分两种情况
//1.空值 直接返回桶里的所有doclist
//2.非空 则对data取hash值,找到自己的桶,如果该桶没有值,则说明不存在,如果存在,且相等,则返回该桶下的所有doclist,否则继续往后找
//一旦有桶为空,则说明这个值一定不存在,也不需要再往后找了
struct rowid_list* hash_index_query(struct hash_index_manager* hash_index,struct low_data_struct* data,MEM_POOL* mem_pool)
{
	struct hash_bucket* bucket;
	struct rowid_list* ret;
	uint64_t hash_value;
	uint64_t hash_value_in_hash_info;
	uint32_t loc;
	uint32_t offset;
	uint32_t i;

	//如果为空值的话,则把第hashmod的桶返回给上层
	if(data->len == 0)
	{
		bucket = hash_index->mem_mmaped+hash_index->hashmod;
		
		hash_value_in_hash_info = Mile_AtomicGetPtr(&bucket->hash_value);
		/*只要为空,则肯定不存在*/
		if(hash_value_in_hash_info == 0)
		{
			return NULL;
		}

		offset = Mile_AtomicGetPtr(&bucket->offset);
		ret = get_rowid_list(hash_index,NEXT_DOC_ROW_STRUCT(hash_index->doclist, offset),mem_pool);
		return ret;
	}
	
	
	//根据value做一次hash
	PROFILER_BEGIN("get hash value");
	hash_value = get_hash_value(data);
	PROFILER_END();

	//取模
	loc = hash_value%hash_index->hashmod;

	//如果定位到的hash有值,则需要往下寻找
	i=loc;
	do
	{
		bucket = hash_index->mem_mmaped+i;

		hash_value_in_hash_info = Mile_AtomicGetPtr(&bucket->hash_value);
		/*如果循环的过程中,只要有一个为空,则肯定不存在*/
		if(hash_value_in_hash_info == 0)
		{
			return NULL;
		}
		
		//找出hash值相等地方
		if(hash_value_in_hash_info == hash_value)
		{
		   offset = Mile_AtomicGetPtr(&bucket->offset);
		   ret = get_rowid_list(hash_index,NEXT_DOC_ROW_STRUCT(hash_index->doclist, offset),mem_pool);
		   return ret;
		}
		
		i = (i+1)%hash_index->hashmod;
	}
	while(i!=loc);

	log_debug("查询不到这个值");
	return NULL;
}
Example #17
0
//两种情况
//1.空值情况
//则直接定位到第hashmod个桶
//2.非空值情况
//则根据插入的值做hash,通过hash值对hashmod取模,从而定位到存储到哪个桶上,如果这个桶的hash value相等则直接插入,如果
//不等,则说明冲突了,则需要往后继续找到自己的桶
int32_t hash_index_insert(struct hash_index_manager* hash_index,struct low_data_struct* data,uint32_t docid)
{
	struct hash_bucket* bucket;
	uint64_t hash_value;
	uint32_t loc;
	uint32_t i;
	uint32_t offset;

	//根据value做一次hash
	PROFILER_BEGIN("get hash value");
	hash_value = get_hash_value(data);
	PROFILER_END();
	
	//判断是否为空值
	if(data->len == 0)
	{
		bucket = hash_index->mem_mmaped+hash_index->hashmod;

		//哈希这个位置没有这个值存在,调用doclist接口插入
		if(bucket->hash_value == 0)
		{
			if((offset = doclist_insert(hash_index->doclist,docid,0, hash_index->hashmod)) == 0)
				return ERROR_INSERT_REPEAT;
			
			//注意hash_value一定要在offset之后写,因为并发查询的时候会先去读value,判断value是否为0
			Mile_AtomicSetPtr(&bucket->offset, offset);
			Mile_AtomicSetPtr(&bucket->hash_value, hash_value);
		}
		else
		{
			offset = doclist_insert(hash_index->doclist,docid,bucket->offset, hash_index->hashmod);
			Mile_AtomicSetPtr(&bucket->offset, offset);
		}
		return MILE_RETURN_SUCCESS;
	}
	
	
	//取模
	loc = hash_value%hash_index->hashmod;
	i = loc;

	do
	{
		bucket = hash_index->mem_mmaped+i;

		//哈希这个位置没有这个值存在,调用doclist接口插入
		if(bucket->hash_value == 0)
		{
			if((offset = doclist_insert(hash_index->doclist,docid,0, i)) == 0 )
				return ERROR_INSERT_REPEAT;
			//注意hash_value一定要在offset之后写,因为并发查询的时候会先去读value,判断value是否为0
			Mile_AtomicSetPtr(&bucket->offset, offset);
			Mile_AtomicSetPtr(&bucket->hash_value, hash_value);
			return MILE_RETURN_SUCCESS;
		}

		//哈希这个位置有值存在,并且相等
		if(bucket->hash_value == hash_value)
		{
			if((offset = doclist_insert(hash_index->doclist,docid,bucket->offset, i)) == 0)
				return ERROR_INSERT_REPEAT;
			Mile_AtomicSetPtr(&bucket->offset, offset);
			return MILE_RETURN_SUCCESS;
		}
		
		i = (i+1)%hash_index->hashmod;
	}
	while(i!=loc);

	log_error("hash 恶性冲突");
	return ERROR_HASH_CONFLICT;
}
Example #18
0
/* 该函数把<setcion_name,key_name,key_value>写到内存中配置数据
   数据结构中,如果section_name,key_name不存在,则会创建一个节、一个键并设置值*/
int  set_key_value(void *cfgdata,const char *section, const char *key_name, const char *set)
{
  conf_section_t *psect = NULL;
  conf_key_t *pkey = NULL;
  int i;
#ifdef WITH_HASH
  unsigned short vhash;
#endif
  cfgdata_t *cd = (cfgdata_t *)cfgdata;

#ifdef WITH_HASH
  /* search if this section already exists... */
  /* first search in the hash table... */
  vhash = get_hash_value(section) % CONF_HASH_SECTION_SIZE;
  if (cd->m_Hash[vhash] != NULL && strcasecmp(section, cd->m_Hash[vhash]->section_name) == 0)
  {
    psect = cd->m_Hash[vhash]; /* found this section in the hash table */
  }
#endif

  if (psect == NULL)
  {
    /* not found in the hash table, do a normal search... */
    for (i = 0; i < cd->section_count; i++)
    {
      if (strcasecmp(cd->psection[i].section_name, section) == 0)
      {
        psect = &cd->psection[i];
        break;
      }
    }
  }

  /* if this is a new section, try to allocate memory for it */
  if (psect == NULL)
  {
    cd->section_count++;

    /* if we don't have enough room for this new section, try to allocate more memory */
    if (cd->section_count > cd->current_size)
    {
      cd->current_size += CONF_SIZE_INCREMENT;
      if (cd->psection)
      {
        cd->psection = (conf_section_t *)realloc(cd->psection, sizeof(conf_section_t) * cd->current_size);
      }
      else
      {
        cd->psection = (conf_section_t *)malloc(sizeof(conf_section_t) * cd->current_size);
      }

      if (!cd->psection)
      {
        return -1;
      }
    }

    psect = &cd->psection[cd->section_count - 1];
    psect->section_name = strdup(section);
    psect->keys = NULL;
    psect->key_count = 0;
    psect->current_size = 0;
#ifdef WITH_HASH
    memset(psect->hash, 0, sizeof(psect->hash)); /* zero out the hash table */
    /* store this new section in the hash table... */
    vhash = get_hash_value(psect->section_name) % CONF_HASH_SECTION_SIZE;
    cd->m_Hash[vhash] = psect;
#endif
  }

#ifdef WITH_HASH
  /* search if the key is already in the section... */
  vhash = get_hash_value(key_name) % CONF_HASH_KEY_SIZE;
  if (psect->hash[vhash] != NULL && strcasecmp(key_name, psect->hash[vhash]->key_name) == 0)
  {
    pkey = psect->hash[vhash]; /* we have found the key in the hash table */
  }
#endif

  if (pkey == NULL)
  {
    /* key is not found in the hash table, do a normal search... */
    for (i = 0; i < psect->key_count; i++)
    {
      if (strcasecmp(key_name, psect->keys[i].key_name) == 0)
      {
        /* we have found the value */
        pkey = &psect->keys[i];
        break;
      }
    }
  }

  if (pkey != NULL)
  {
    /* this key already exists in the section... */
    free(pkey->key_value);
    pkey->key_value = strdup(set);

    if (pkey->key_value == NULL)
    {
      return -1;
    }
  }
  else
  {
    /*  this is a new key... */
    psect->key_count++;

    /* if we don't have enough room for this new key, try to allocate more memory */
    if (psect->key_count > psect->current_size)
    {
      psect->current_size += CONF_SIZE_INCREMENT;
      if (psect->keys)
      {
        psect->keys = (conf_key_t *)realloc(psect->keys, sizeof(conf_key_t) * psect->current_size);
      }
      else
      {
        psect->keys = (conf_key_t *)malloc(sizeof(conf_key_t) * psect->current_size);
      }

      if (psect->keys == NULL)
      {
        return -1;
      }
    }

    psect->keys[psect->key_count - 1].key_name = strdup(key_name);
    psect->keys[psect->key_count - 1].key_value = strdup(set);

    if (psect->keys[psect->key_count - 1].key_value == NULL || psect->keys[psect->key_count - 1].key_name == NULL)
    {
      return -1;
    }

    trim(psect->keys[psect->key_count - 1].key_value);
    trim(psect->keys[psect->key_count - 1].key_name);

#ifdef WITH_HASH
    /* store this new key in the hash table */
    vhash = get_hash_value(psect->keys[psect->key_count - 1].key_name) % CONF_HASH_KEY_SIZE;
    psect->hash[vhash] = &psect->keys[psect->key_count - 1];
#endif
  }

  return 0;
}
Example #19
0
//只有filter列才能更新
int32_t index_field_update(struct index_field_manager* index_field,
						 struct low_data_struct* new_data,
						 struct low_data_struct** old_data,
						 uint32_t docid,
						 MEM_POOL* mem_pool)
{
	int32_t ret;
	
	//拒绝更新的条件
	if(index_field == NULL)
	{
		log_warn("此列未初始化%s",index_field->field_name);
		return ERROR_FIELD_NOT_WORK;
	}

	if(index_field->flag != NULL && Mile_AtomicGetPtr(index_field->flag) & INDEX_FIELD_COMPRESS)
		return ERROR_INDEX_FIELD_COMPRESSED;

	switch(index_field->index_type)
	{

		case HI_KEY_ALG_FILTER:
		{
			//如果是字符串,需要对数据进行预处理
			if(new_data->type == HI_TYPE_STRING)
			{
				struct low_data_struct hash_data;

				PROFILER_BEGIN("get_hash_value");
				uint64_t hash_value = get_hash_value(new_data);
				PROFILER_END();
				
				hash_data.data = &hash_value;
				hash_data.len = get_unit_size(HI_TYPE_LONGLONG);

				PROFILER_BEGIN("filter index update");
				if((ret = filter_index_update(index_field->filter_index,&hash_data,old_data,docid,mem_pool) < 0) )
				{
					PROFILER_END();
					return ret;
				}
				PROFILER_END();
			}
			else
			{
				PROFILER_BEGIN("filter index update");
				if((ret = filter_index_update(index_field->filter_index,new_data,old_data,docid,mem_pool) < 0) )
				{
					PROFILER_END();
					return ret;
				}
				PROFILER_END();
			}

			return MILE_RETURN_SUCCESS;
		}	
		default:
			log_warn("只有filter列才能update");
			return ERROR_ONLY_FILTER_SUPPORT;
	}
}
Example #20
0
int32_t index_field_insert(struct index_field_manager* index_field,struct low_data_struct* data,uint32_t docid)
{
	int32_t ret;

	//拒绝插入的条件
	if(index_field == NULL) 
	{
		log_warn("此列未初始化%s",index_field->field_name);
		return ERROR_FIELD_NOT_WORK;
	}
	
	if(index_field->flag != NULL && (Mile_AtomicGetPtr(index_field->flag) & INDEX_FIELD_COMPRESS))
    	return ERROR_INDEX_FIELD_COMPRESSED;

	switch(index_field->index_type)
	{
		case HI_KEY_ALG_FULLTEXT:
			{
				/*全文列插入hash*/
				PROFILER_BEGIN("dyhash index insert");
				if((ret = dyhash_index_insert(index_field->dyhash_index,data,docid)) < 0)
				{
					PROFILER_END();
					return ret;
				}
				PROFILER_END();

				return MILE_RETURN_SUCCESS;

			}
		case HI_KEY_ALG_HASH:
			{
				/*哈希列插入hash*/
				PROFILER_BEGIN("hash index insert");
				if((ret = hash_index_insert(index_field->hash_index,data,docid)) < 0)
				{
					PROFILER_END();
					return ret;
				}
				PROFILER_END();

				return MILE_RETURN_SUCCESS;
			}
		case HI_KEY_ALG_BTREE:
			{
				return MILE_RETURN_SUCCESS;
			}
		case HI_KEY_ALG_FILTER:
			{
				//如果是字符串,需要对数据进行预处理
				if(data->type == HI_TYPE_STRING)
				{
					struct low_data_struct hash_data;
					
					PROFILER_BEGIN("get hash value");
					uint64_t hash_value = get_hash_value(data);
					PROFILER_END();
					
					hash_data.data = &hash_value;
					hash_data.len = get_unit_size(HI_TYPE_LONGLONG);
					hash_data.type = HI_TYPE_LONGLONG;
					hash_data.field_name = data->field_name;

					if(*index_field->max_len < get_unit_size(HI_TYPE_LONGLONG))
					{
						*index_field->max_len = get_unit_size(HI_TYPE_LONGLONG);
						msync(index_field->max_len,sizeof(uint32_t),MS_SYNC);
					}

					PROFILER_BEGIN("filter index insert");
					if((ret = filter_index_insert(index_field->filter_index,&hash_data,docid) < 0) )
					{
						PROFILER_END();
						return ret;
					}
					PROFILER_END();
					
				}
				else
				{
					if(data->len > get_unit_size(HI_TYPE_LONGLONG))
					{
						log_error("数据长度超过8个字节,len:%u",data->len);
						return ERROR_INSERT_FAILDED;
			
					}
					if(*index_field->max_len < data->len)
					{
						*index_field->max_len = data->len;
						msync(index_field->max_len,sizeof(uint32_t),MS_SYNC);
					}
					
					PROFILER_BEGIN("filter index insert");
					if((ret = filter_index_insert(index_field->filter_index,data,docid) < 0) )
					{
						PROFILER_END();
						return ret;
					}
					PROFILER_END();
				}

				return MILE_RETURN_SUCCESS;
			}
		default:
			log_error("该列的索引类型不正确,%d",index_field->index_type);
			return ERROR_NOT_SUPPORT_INDEX;
	}
}