[Tarantool-patches] [PATCH v2 3/3] box: let only box handle constraint dup errors

Cyrill Gorcunov gorcunov at gmail.com
Thu Dec 5 22:13:57 MSK 2019


On Thu, Dec 05, 2019 at 09:59:33PM +0300, Roman Khabibov wrote:
> 
> Vlad, please, don’t see the previous.
> 
> Cyrill, I added both for sure.

Thanks!

> +/**
> + * Just return string with constraint type to print it in error
> + * message.
> + */
> +static inline const char *
> +cosntraint_type_str(struct constraint_def *def) {
> +	assert(def->type == CONSTRAINT_TYPE_PK || def->type ==
> +	       CONSTRAINT_TYPE_UNIQUE || def->type == CONSTRAINT_TYPE_FK ||
> +	       def->type == CONSTRAINT_TYPE_CK);
> +	switch (def->type) {
> +	case CONSTRAINT_TYPE_PK:
> +		return "PRIMARY KEY";
> +	case CONSTRAINT_TYPE_UNIQUE:
> +		return "UNIQUE";
> +	case CONSTRAINT_TYPE_FK:
> +		return "FOREIGN KEY";
> +	case CONSTRAINT_TYPE_CK:
> +		return "CHECK";
> +	default:
> +		break;
> +	}
> +	return NULL;
> +}

This is a way better than it was. To be honest I'm not strong
in the whole context of the series, but when I need to provide
some symbolic name I do something like

/**
 * popen_state_str - get process state string representation
 * @state:	process state
 */
const char *
popen_state_str(unsigned int state)
{
	/*
	 * A process may be in a number of states,
	 * running/sleeping/disk sleep/stopped and etc
	 * but we are interested only if it is alive
	 * or dead (via plain exit or kill signal).
	 *
	 * Thus while it present in a system and not
	 * yet reaped we call it "alive".
	 *
	 * Note this is API for lua, so change with
	 * caution if needed.
	 */
	static const char * state_str[POPEN_STATE_MAX] = {
		[POPEN_STATE_NONE]	= "none",
		[POPEN_STATE_RUNNING]	= "alive",
		[POPEN_STATE_EXITED]	= "exited",
		[POPEN_STATE_SIGNALED]	= "signaled",
	};

	return state < POPEN_STATE_MAX ? state_str[state] : "unknown";
}

but note that I know the number of entries so it might not fit
your needs thus I'm fine with your current code. Thanks!


More information about the Tarantool-patches mailing list