コード例 #1
0
/*
 * 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;
}
コード例 #2
0
ファイル: udf_record.c プロジェクト: farvour/aerospike-server
/*********************************************************************
 * INTERFACE FUNCTIONS                                               *
 *																	 *
 * See the as_aerospike for the API definition						 *
 ********************************************************************/
static as_val *
udf_record_get(const as_rec * rec, const char * name)
{
	if (udf_record_param_check(rec, name, __FILE__, __LINE__)) {
		return NULL;
	}
	udf_record  *   urecord = (udf_record *) as_rec_source(rec);
	as_val *        value   = NULL;

	cf_debug(AS_UDF, "[ENTER] rec(%p) name(%s)", rec, name );

	// Get from cache
	value = udf_record_cache_get(urecord, name);

	// If value not NULL, then return it.
	if ( value != NULL ) {
		return value;
	}

	// Check in the cache before trying to look up in record
	// Note: Record may not have been created yet ... Do not
	// change the order unless you fully understand what you
	// are doing
	if ( !(urecord->flag & UDF_RECORD_FLAG_STORAGE_OPEN) ) {
		if (udf_record_open(urecord)) { // lazy read the record from storage
			return NULL;
		}
	}

	// Check if storage is available
	if ( !urecord->rd->ns ) {
		cf_detail(AS_UDF, "udf_record_get: storage unavailable");
		return NULL;
	}

	value = udf_record_storage_get(urecord, name);

	// We have a value, so we will cache it.
	// DO NOT remove this. We need to cache copy to makes sure ref count 
	// gets decremented post handing this as_val over to the lua world
	if ( urecord && value ) {
		udf_record_cache_set(urecord, name, value, false);
	}

	cf_detail(AS_UDF, "udf_record_get: end (%s) [%p,%p]", name, urecord, value);
	return value;
}
コード例 #3
0
/*
 * Internal Function: 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
ldt_crec_open(ldt_record *lrecord, cf_digest *keyd, int *slotp)
{
	cf_debug_digest(AS_LDT, keyd, "[ENTER] ldt_crec_open(): Digest: ");

	// 1. Search in opened record
	int slot = ldt_crec_find_digest(lrecord, keyd);
	if (slot != -1) {
		cf_info(AS_LDT, "ldt_aerospike_rec_open : Found already open");
		return 0;
	}

	// 2. Find free slot and setup chunk
	slot     = ldt_crec_find_freeslot(lrecord);
	if (slot == -1) {
		cf_warning(AS_LDT, "Cannot open more than (%d) records in a single UDF",
				s_max_open_subrecs);
		return -2;
	}
	cf_detail(AS_LDT, "ldt_crec_open popped slot %d", slot);
	lrecord->chunk[slot].slot = slot;
	ldt_chunk *lchunk         = &lrecord->chunk[slot];
	ldt_chunk_init(lchunk, lrecord);
	ldt_chunk_setup(lchunk, lrecord->h_urec, keyd);
	//ldt_chunk_print(lrecord, slot);

	// Open Record
	int rv = udf_record_open((udf_record *)as_rec_source(lchunk->c_urec_p));
	if (rv) {
		// Open the slot for reuse
		ldt_chunk_destroy(&lrecord->chunk[slot]);
		return -3;
	}
	*slotp = slot;
	return 0;
}