Exemple #1
0
int
main(int argc, char* argv[])
{
	ib_tbl_sch_t	ib_tbl_sch = NULL;
	ib_id_t		table_id;
	int		valid_page_sizes[] = {0, 1, 2, 4, 8, 16};
	int		invalid_page_sizes[] = {3, 5, 6, 14, 17, 32, 128, 301};
	size_t		i;

	(void)argc;
	(void)argv;

	OK(ib_init());

	test_configure();

	OK(ib_startup("barracuda"));

	OK(ib_cfg_set("file_per_table", IB_TRUE));

	OK(ib_database_create(DBNAME));

	for (i = 0;
	     i < sizeof(valid_page_sizes) / sizeof(valid_page_sizes[0]);
	     i++) {

		ib_trx_t	ib_trx;

		OK(ib_table_schema_create(TABLENAME, &ib_tbl_sch,
					  IB_TBL_COMPRESSED,
					  valid_page_sizes[i]));

		OK(ib_table_schema_add_col(ib_tbl_sch, "c1", IB_INT,
					   IB_COL_UNSIGNED, 0 /* ignored */,
					   sizeof(int)));

		ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ);

		OK(ib_schema_lock_exclusive(ib_trx));

		OK(ib_table_create(ib_trx, ib_tbl_sch, &table_id));

		OK(ib_trx_commit(ib_trx));

		ib_table_schema_delete(ib_tbl_sch);

		ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ);

		OK(ib_schema_lock_exclusive(ib_trx));

		OK(ib_table_drop(ib_trx, TABLENAME));

		OK(ib_trx_commit(ib_trx));
	}

	for (i = 0;
	     i < sizeof(invalid_page_sizes) / sizeof(invalid_page_sizes[0]);
	     i++) {

		ib_err_t	ib_err;

		ib_err = ib_table_schema_create(TABLENAME, &ib_tbl_sch,
						IB_TBL_COMPRESSED,
						invalid_page_sizes[i]);

		if (ib_err == DB_SUCCESS) {
			fprintf(stderr, "Creating a compressed table with "
				"page size %d succeeded but should have "
				"failed", invalid_page_sizes[i]);
			exit(EXIT_FAILURE);
		}

	}

	/* ignore errors as there may be tables left over from other tests */
	OK(ib_database_drop(DBNAME));

	OK(ib_shutdown(IB_SHUTDOWN_NORMAL));

	return(EXIT_SUCCESS);
}
Exemple #2
0
static void do_set_cfg(void* arg)
{
    PortState* state = (PortState*)arg;

    erl_drv_mutex_lock(G_ENGINE_STATE_LOCK);
    if (G_ENGINE_STATE == ENGINE_STOPPED)
    {
        char* key   = UNPACK_STRING(state->work_buffer, 0);
        const char* value = UNPACK_STRING(state->work_buffer, strlen(key)+1);

        if (strcmp(key, "error_log") == 0)
        {
            if (set_log_file(value) == 0)
            {
                send_ok(state);
            }
            else
            {
                send_error_atom(state, "einval");
            }
        }
        else
        {
            // Check the expected type of the provided key so as to 1. validate it's a good key
            // and 2. know what setter to use.
            ib_cfg_type_t key_type;
            ib_err_t error = ib_cfg_var_get_type(key, &key_type);
            if (error == DB_SUCCESS)
            {
                if (key_type == IB_CFG_TEXT)
                {
                    // HACK: Semantics of setting a text configuration value for innodb changed
                    // to be pointer assignment (from copy) for vsn 1.0.6.6750. So, we strdup the
                    // value to ensure everything works as expected.
                    // TODO: Setup some sort of list of strdup'd values to ensure they all get
                    // cleaned up properly. In typical usage, this isn't going to be a problem
                    // as you only initialize once per run, but it bothers me just the same.
                    error = ib_cfg_set(key, strdup(value));
                }
                else
                {
                    ErlDrvUInt value_i;
                    UNPACK_INT(state->work_buffer, strlen(key)+1, &value_i);
                    error = ib_cfg_set(key, value_i);
                }

            }

            if (error == DB_SUCCESS)
            {
                send_ok(state);
            }
            else
            {
                send_error_str(state, ib_strerror(error));
            }
        }
    }
    else
    {
        send_error_atom(state, "starting");
    }

    erl_drv_mutex_unlock(G_ENGINE_STATE_LOCK);
}