Пример #1
0
//In case of memcache append/prepend, appending string to a string is allowed currently.
//We have the capability to append Integers and Blobs,but we have restricted it currently,
//to avoid confusions in use cases.
int
as_particle_append_prepend_data(as_bin *b, as_particle_type type, byte *data, uint32_t data_len, bool data_in_memory, bool is_append, bool memcache_compliant)
{
	as_particle_type old_type = as_bin_get_particle_type(b);
	as_particle_type new_type;

	switch(old_type) {
		case AS_PARTICLE_TYPE_STRING:
			particle_append_prepend_data_impl(b, old_type, type, &new_type, data, data_len, data_in_memory, is_append, memcache_compliant);
			break;
		case AS_PARTICLE_TYPE_BLOB:
			if(!memcache_compliant) {
				particle_append_prepend_data_impl(b, old_type, type, &new_type, data, data_len, data_in_memory, is_append, memcache_compliant);
			}
			else {
				return -1;
			}
			break;

		case AS_PARTICLE_TYPE_INTEGER:
			return -1;
			break;
		default:
			return -1;
	}

	if (new_type == AS_PARTICLE_TYPE_INTEGER) {
		as_bin_state_set(b, AS_BIN_STATE_INUSE_INTEGER);
	} else {
		// We do not support append prepend to hidden bins
		as_bin_state_set(b, AS_BIN_STATE_INUSE_OTHER);
	}

	return 0;
}
Пример #2
0
static void
as_bin_init_w_len(as_namespace *ns, as_bin *b, byte *name, size_t len)
{
	as_bin_state_set(b, AS_BIN_STATE_UNUSED);
	b->particle = NULL;

	as_bin_set_id_from_name_buf(ns, b, name, len);
	// Don't touch b->unused - like b->id, it's past the end of its enclosing
	// as_index if single-bin, data-in-memory.
}
Пример #3
0
void
as_bin_init(as_namespace *ns, as_bin *b, const char *name)
{
	as_bin_state_set(b, AS_BIN_STATE_UNUSED);
	b->particle = NULL;

	as_bin_set_id_from_name(ns, b, name);
	// Don't touch b->unused - like b->id, it's past the end of its enclosing
	// as_index if single-bin, data-in-memory.
}
Пример #4
0
void
as_bin_init(as_namespace *ns, as_bin *b, byte *name, size_t namesz, uint version)
{
	as_bin_state_set(b, AS_BIN_STATE_UNUSED);
	as_bin_set_version(b, version, ns->single_bin);

	b->particle = 0;

	as_bin_set_id_from_name_buf(ns, b, name, namesz);
	b->unused = 0;
}
Пример #5
0
void
as_bin_init(as_namespace *ns, as_bin *b, byte *name, size_t namesz, uint version)
{
	as_bin_state_set(b, AS_BIN_STATE_UNUSED);
	as_bin_set_version(b, version, ns->single_bin);

	b->particle = 0;

	as_bin_set_id_from_name_buf(ns, b, name, namesz);
	// Don't touch b->unused - like b->id, it's past the end of its enclosing
	// as_index if single-bin, data-in-memory.
}
Пример #6
0
static inline void
as_bin_init_nameless(as_bin *b)
{
	as_bin_state_set(b, AS_BIN_STATE_UNUSED);
	b->particle = NULL;
}
Пример #7
0
/* as_particle_set
 * Set the contents of a particle, which safely destroys the old particle
 */
as_particle *
as_particle_frombuf(as_bin *b, as_particle_type type, byte *buf, uint32_t sz, uint8_t *stack_particle, bool data_in_memory)
{

#ifdef EXTRA_CHECKS
	// check the incoming type
	if (type < AS_PARTICLE_TYPE_NULL || type >= AS_PARTICLE_TYPE_MAX) {
		cf_info(AS_PARTICLE, "particle set: bad particle type %d, error", (int)type);
		return(NULL);
	}
#endif
	as_particle *retval = 0;

	if (data_in_memory) {
		// we have to deal with these cases
		// current type is integer, new type is integer
		// current type is not integer, new type is integer
		// current type is integer, new type is not integer
		// current type is not integer, new type is not integer
		if (as_bin_is_integer(b)) {
			if (type == AS_PARTICLE_TYPE_INTEGER) {
				// current type is integer, new type is integer
				// just copy the new integer over the existing one.
				return (g_particle_setter_table[type](&b->iparticle, type, buf, sz, data_in_memory));
			}
			else {
				// current type is integer, new type is not integer
				// make this the same case as current type is not integer, new type is not integer
				// cleanup the integer and allocate a pointer.
				b->particle = 0;
			}
		}
		else if (as_bin_inuse(b)) {
			// if it's a completely new type, destruct the old one and create a new one
			uint8_t bin_particle_type = as_bin_get_particle_type(b);
			if (type != bin_particle_type) {
				g_particle_destructor_table[bin_particle_type](b->particle);
				b->particle = 0;
			}
		}
		else {
			b->particle = 0;
		}
	}

	switch (type) {
		case AS_PARTICLE_TYPE_INTEGER:
			// current type is not integer, new type is integer
			as_bin_state_set(b, AS_BIN_STATE_INUSE_INTEGER);
			// use the iparticle embedded in the bin
			retval = g_particle_setter_table[type](&b->iparticle, type, buf, sz, data_in_memory);
			break;
		case AS_PARTICLE_TYPE_NULL:
			// special case, used to free old particle w/o setting new one
			break;
		default:
			// current type is not integer, new type is not integer
			if (! data_in_memory) {
				b->particle = (as_particle *)stack_particle;
			}

			if (as_particle_type_hidden(type)) {
				as_bin_state_set(b, AS_BIN_STATE_INUSE_HIDDEN);
			} else {
				as_bin_state_set(b, AS_BIN_STATE_INUSE_OTHER);
			}
			b->particle = g_particle_setter_table[type](b->particle, type, buf, sz, data_in_memory);
			retval = b->particle;
			break;
	}

	return(retval);
}