bool create_db(char *db_name) { ib_bool_t res = ib_database_create(db_name); if (res == IB_FALSE) { return false; } return true; }
static void do_start(void* arg) { PortState* state = (PortState*)arg; erl_drv_mutex_lock(G_ENGINE_STATE_LOCK); if (G_ENGINE_STATE == ENGINE_STOPPED) { // Engine was stopped; set the flag, unlock and run the start G_ENGINE_STATE = ENGINE_STARTING; erl_drv_mutex_unlock(G_ENGINE_STATE_LOCK); // Run the startup without holding any lock -- this can take a while // if we are recovering from previous errors ib_err_t error = ib_startup("barracuda"); if (error == DB_SUCCESS) { // Make sure the innokeystore database exists // TODO: Avoid hard-coding the db name here... if (ib_database_create("innokeystore") != IB_TRUE) { error = DB_ERROR; } } // Relock and sort out results erl_drv_mutex_lock(G_ENGINE_STATE_LOCK); if (error == DB_SUCCESS) { G_ENGINE_STATE = ENGINE_STARTED; send_ok(state); } else { G_ENGINE_STATE = ENGINE_STOPPED; send_error_str(state, ib_strerror(error)); } } else if (G_ENGINE_STATE == ENGINE_STARTED) { // another thread has already completed startup send_ok(state); } else { // Engine was not in stopped state when do_start was called. // Probably due to multiple threads trying to start at the // same time. assert(G_ENGINE_STATE == ENGINE_STARTING); send_error_atom(state, "starting"); } erl_drv_mutex_unlock(G_ENGINE_STATE_LOCK); }
/********************************************************************* Create an InnoDB database (sub-directory). */ static ib_err_t create_database( /*============*/ const char* name) { ib_bool_t err; err = ib_database_create(name); assert(err == IB_TRUE); return(DB_SUCCESS); }
/** * Create the database schema. * @return true if the database schema was created without any problems * false otherwise. */ static bool create_schema(void) { ib_tbl_sch_t schema= NULL; ib_idx_sch_t dbindex= NULL; if (ib_database_create("memcached") != IB_TRUE) { fprintf(stderr, "Failed to create database\n"); return false; } ib_trx_t transaction= ib_trx_begin(IB_TRX_SERIALIZABLE); ib_id_t table_id; checked(ib_table_schema_create(tablename, &schema, IB_TBL_COMPACT, 0)); checked(ib_table_schema_add_col(schema, "key", IB_BLOB, IB_COL_NOT_NULL, 0, 32767)); checked(ib_table_schema_add_col(schema, "data", IB_BLOB, IB_COL_NONE, 0, 1024*1024)); checked(ib_table_schema_add_col(schema, "flags", IB_INT, IB_COL_UNSIGNED, 0, 4)); checked(ib_table_schema_add_col(schema, "cas", IB_INT, IB_COL_UNSIGNED, 0, 8)); checked(ib_table_schema_add_col(schema, "exp", IB_INT, IB_COL_UNSIGNED, 0, 4)); checked(ib_table_schema_add_index(schema, "PRIMARY_KEY", &dbindex)); checked(ib_index_schema_add_col(dbindex, "key", 0)); checked(ib_index_schema_set_clustered(dbindex)); checked(ib_schema_lock_exclusive(transaction)); checked(ib_table_create(transaction, schema, &table_id)); checked(ib_trx_commit(transaction)); ib_table_schema_delete(schema); return true; error_exit: /* @todo release resources! */ { ib_err_t error= ib_trx_rollback(transaction); if (error != DB_SUCCESS) fprintf(stderr, "Failed to roll back the transaction:\n\t%s\n", ib_strerror(error)); } return false; }
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); }