/*
 * Function to open chunk record
 * Parameters:
 * 		lrd  : Parent ldt record
 * 		keyd : Key digest for the record to be opened
 * 		slot(out): Filled with slot in case of success
 *
 * Return value :
 * 		 0  in case of success returns positive slot value
 * 		-1   in case record is already open
 * 		-2   in case free slot cannot be found
 * 		-3   in case record cannot be opened
 *
 * Description:
 * 		1. Get the empty chunk slot.
 * 		2. Read the record into it
 *
 * Callers:
 *		ldt_aerospike_crec_open
 */
int
crec_open(ldt_record *lrecord, cf_digest *keyd, ldt_slot **lslotp)
{
	cf_detail_digest(AS_LDT, keyd, "[ENTER] crec_open(): Digest: ");

	// 1. Search in opened record
	*lslotp = slot_lookup_by_digest(lrecord, keyd);
	if (*lslotp) {
		cf_debug(AS_LDT, "ldt_aerospike_crec_open : Found already open");
		return 0;
	}

	// 2. Find free slot and setup chunk
	*lslotp     = slot_lookup_free(lrecord, "crec_open");
	if (!*lslotp) {
		return -2;
	}
	slot_init(*lslotp, lrecord);
	slot_setup_digest(*lslotp, keyd);

	// 3. Open Record
	int rv = udf_record_open((udf_record *)as_rec_source((*lslotp)->c_urec_p));
	if (rv) {
		// free the slot for reuse
		slot_destroy(*lslotp, lrecord);
		*lslotp = NULL;
		return -3;
	}
	return 0;
}
void
chunk_destroy(ldt_record *lrecord, ldt_slot_chunk *lchunk)
{
	for (int j = 0; j < LDT_SLOT_CHUNK_SIZE; j++) {
		if (lchunk->slots[j].inuse) {
			ldt_slot *lslotp      = &lchunk->slots[j];
			slot_destroy(lslotp, lrecord);
		}
	}
	cf_free(lchunk->slots);
	lchunk->slots         = NULL;
}
示例#3
0
void
mem_slot_test() {
  as_mem_slot_t *s = slot_new(4);
  slot_alloc(s, 4);
  int a = slot_alloc(s, 5);
  slot_alloc(s, 3);
  slot_free(s, a, 5);
  slot_alloc(s, 6);

  slot_print(s);
  slot_destroy(s);
}
示例#4
0
LOCAL ndas_error_t ndcmd_stop(void) 
{
    int i,size, slot;
    ndas_error_t ret;
    ndas_device_info info;
    struct ndas_registered *data;
    
    size = ndas_registered_size();
    if ( !NDAS_SUCCESS(size) ) {
        dbgl_blk(1,"fail to get ndas_registered_size");    
        goto out;
    }
    dbgl_blk(1,"ndas_registered_size=%d", size);
    data = sal_malloc(sizeof(struct ndas_registered)* size);
    if ( !data ) {
        goto out;
    }

    for ( i = NDAS_FIRST_SLOT_NR; i < NDAS_MAX_SLOT_NR; i++) 
    {
        struct ndas_slot* sd = NDAS_GET_SLOT_DEV(i); 

        if ( !sd ) {
            continue;
        }
        slot = sd->slot;
        slot_destroy(slot);
        ndas_disable_slot(slot);
    }
    ret = ndas_registered_list(data, size);
    if ( !NDAS_SUCCESS(ret) ) {
        goto out_free;
    }
    
    if ( ret != size ) {
        goto out_free;
    }

    for ( i = 0; i < size; i ++ ) 
    {
        dbgl_blk(1,"name[%d]=%s", i , data[i].name);
        ret = ndas_get_ndas_dev_info(data[i].name, &info);
        if ( !NDAS_SUCCESS(ret) )
            continue;
        nproc_remove_ndev(data[i].name);
        ndas_unregister_device(data[i].name);
    }
out_free:
    sal_free(data);
out:
    return ndas_stop();
}
as_rec *
crec_create(ldt_record *lrecord)
{
	// Generate Key Digest
	udf_record *h_urecord = (udf_record *) as_rec_source(lrecord->h_urec);
	cf_digest keyd        = h_urecord->r_ref->r->key;
	as_namespace *ns      = h_urecord->tr->rsv.ns;
	int retry_cnt         = 0;
	ldt_slot *lslotp      = slot_lookup_free(lrecord, "crec_create");

	if (!lslotp) {
		cf_crash(AS_LDT, "Allocation error !!!");
	}
	slot_init(lslotp, lrecord);

	while (retry_cnt++ < LDT_SUBRECORD_RANDOMIZER_MAX_RETRIES) {

		as_ldt_digest_randomizer(&keyd);
		as_ldt_subdigest_setversion(&keyd, lrecord->version);
		slot_setup_digest(lslotp, &keyd);

		int rv = as_aerospike_rec_create(lrecord->as, lslotp->c_urec_p);

		// rv == 0 if successful
		// rv == 1 if record is already found retry
		// other wise failure
		if (rv == 0) {
			cf_detail_digest(AS_LDT, &keyd, "Crec Create:Ptr(%p) Digest: version %ld", lslotp->c_urec_p, lrecord->version);
			as_val_reserve(lslotp->c_urec_p);
			return lslotp->c_urec_p;
		}

		if (rv != 1) {
			cf_warning(AS_LDT, "crec_create: LDT Sub-Record Create Error [rv=%d]... Fail", rv);
			break;
		}
		cf_atomic64_incr(&ns->lstats.ldt_randomizer_retry);
	}

	slot_destroy(lslotp, lrecord);
	cf_warning_digest(AS_LDT, &keyd, "ldt_aerospike_crec_create : Create failed after %d retries", retry_cnt);
	return NULL;
}
int
ldt_aerospike_crec_close(const as_aerospike * as, const as_rec *crec_p)
{
	cf_detail(AS_LDT, "[ENTER] as(%p) subrec(%p)", as, crec_p );
	if (!as || !crec_p) {
		cf_warning(AS_LDT, "ldt_aerospike_crec_close: Invalid Parameters [as=%p, subrecord=%p]... Fail", as, crec_p);
		return 2;
	}

	// Close of the record is only allowed if the user has not updated
	// it. Other wise it is a group commit
	udf_record *c_urecord = (udf_record *)as_rec_source(crec_p);
	if (!c_urecord) {
		cf_warning(AS_LDT, "ldt_aerospike_crec_close: Internal Error [Malformed Sub Record]... Fail");
		return -1;
	}
	ldt_record  *lrecord  = (ldt_record *)c_urecord->lrecord;
	if (!lrecord) {
		cf_warning(AS_LDT, "ldt_aerospike_crec_close: Internal Error [Invalid Head Record Reference in Sub Record]... Fail");
		return -1;
	}

	ldt_slot *lslotp   = slot_lookup_by_urec(lrecord, crec_p);
	if (!lslotp) {
		cf_warning(AS_LDT, "ldt_aerospike_crec_close: Invalid Operation [Sub Record close called for the record which is not open]... Fail");
		return -1;
	}
	cf_detail(AS_LDT, "ldt_aerospike_crec_close");
	if (c_urecord->flag & UDF_RECORD_FLAG_HAS_UPDATES) {
		cf_debug(AS_LDT, "Cannot close record with update ... it needs group commit");
		return -2;
	}
	udf_record_close(c_urecord);
	udf_record_cache_free(c_urecord);
	slot_destroy(lslotp, lrecord);
	c_urecord->flag &= ~UDF_RECORD_FLAG_ISVALID;
	return 0;
}
示例#7
0
LOCAL
ndas_error_t ndcmd_unregister(char *name) 
{
    int i;
    ndas_error_t err;
    ndas_device_info info;
    err = ndas_get_ndas_dev_info(name, &info); 

    if ( !NDAS_SUCCESS(err)) {
        return err;
    }
    err = ndas_unregister_device(name);
    if ( !NDAS_SUCCESS(err)) {
        return err;
    }
    
    for ( i = 0; i < info.nr_unit; i++) {
        slot_destroy(info.slot[i]);
    }
    nproc_remove_ndev(name);

    return err;
}
示例#8
0
文件: queue.c 项目: jinrenlab/tanlz
/******************************************************************************
 **函数名称: queue_destroy
 **功    能: 销毁加锁队列
 **输入参数:
 **     queue: 队列
 **输出参数: NONE
 **返    回: VOID
 **实现描述:
 **注意事项:
 **作    者: # Qifeng.zou # 2014.10.12 #
 ******************************************************************************/
void queue_destroy(queue_t *queue)
{
    ring_destroy(queue->ring);
    slot_destroy(queue->slot);
    free(queue);
}