void print_schema(const char *fname) { int fd = open(fname, O_RDONLY); if (-1 == fd) { fprintf(stderr, "open file [%s] fail errno=%u\n", fname, errno); } else { struct stat st; fstat(fd, &st); char *buffer = new char[st.st_size]; if (NULL == buffer) { fprintf(stderr, "new buffer fail size=%ld\n", st.st_size); } else { int64_t read_ret = read(fd, buffer, st.st_size); if (st.st_size != read_ret) { fprintf(stderr, "read file fail ret=%ld size=%ld errno=%u\n", read_ret, st.st_size, errno); } else { ObSchemaManagerV2 *sm = new(std::nothrow) ObSchemaManagerV2(); if (NULL == sm) { fprintf(stdout, "[%s] new ObSchemaManagerV2 fail\n", __FUNCTION__); } else { int64_t pos = 0; int ret = sm->deserialize(buffer, st.st_size, pos); if (OB_SUCCESS != ret) { fprintf(stderr, "deserialize fail ret=%d\n", ret); } else { print_schema(*sm); } delete sm; } } delete[] buffer; } close(fd); } }
void fetch_schema(MockClient &client, int64_t timestamp) { ObSchemaManagerV2 *schema_mgr = new(std::nothrow) ObSchemaManagerV2(); if (NULL == schema_mgr) { fprintf(stdout, "[%s] new ObSchemaManagerV2 fail\n", __FUNCTION__); } else { int err = client.fetch_schema(timestamp, *schema_mgr, timeout); fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err); if (OB_SUCCESS == err) { print_schema(*schema_mgr); } delete schema_mgr; } }
void print_schema(Pschema schema, int spaces){ Pschema p = schema; while (p != NULL){ print_spaces(spaces, stdout); printf("%s",typetypes[p->type]); if(p->id != NULL){ printf(" '%s'",p->id); } if(p->type == TY_ARRAY){ printf(" [%d]",p->size); } printf("\n"); if(p->child != NULL){ print_schema(p->child,spaces + 1); } p = p->brother; } }
int load_and_dump_schema(const char *filename) { void *buffer; size_t size; int ret = -1; reflection_Schema_table_t S; buffer = read_file(filename, 10000, &size); if (!buffer) { fprintf(stderr, "failed to load binary schema file: '%s'\n", filename); goto done; } if (size < 12) { fprintf(stderr, "file too small to access: '%s'\n", filename); goto done; } S = reflection_Schema_as_root(buffer); if (!S) { S = reflection_Schema_as_root((char*)buffer + 4); if (S) { fprintf(stderr, "(skipping length field of input buffer)\n"); } } if (!S) { fprintf(stderr, "input is not a valid schema"); goto done; } print_schema(S); ret = 0; done: if (buffer) { free(buffer); } return ret; }
int main(int argc, char** argv) { setlocale(LC_ALL, ""); TBSYS_LOGGER.setFileName("ups_admin.log", true); TBSYS_LOG(INFO, "ups_admin start=================================================="); ob_init_memory_pool(); CmdLineParam clp; parse_cmd_line(argc, argv, clp); timeout = clp.timeout?: timeout; MockClient client; init_mock_client(clp.serv_addr, clp.serv_port, clp.login_type, client); PageArena<char> allocer; int rc = 0; if (0 == strcmp("apply", clp.cmd_type)) { apply(clp.ini_fname, allocer, client); } else if (0 == strcmp("get_clog_status", clp.cmd_type)) { get_clog_status(client); } else if (0 == strcmp("get_max_log_seq", clp.cmd_type)) { get_max_log_seq(client); } else if (0 == strcmp("get_clog_cursor", clp.cmd_type)) { get_clog_cursor(client); } else if (0 == strcmp("get_clog_master", clp.cmd_type)) { get_clog_master(client); } else if (0 == strcmp("get_log_sync_delay_stat", clp.cmd_type)) { get_log_sync_delay_stat(client); } else if (0 == strcmp("get", clp.cmd_type)) { get(clp.ini_fname, allocer, client, clp.version_range,clp.expected_result_fname, clp.schema_fname); } else if (0 == strcmp("param_get", clp.cmd_type)) { param_get(clp.ini_fname, client); } else if (0 == strcmp("scan", clp.cmd_type)) { scan(clp.ini_fname, allocer, client, clp.version_range,clp.expected_result_fname, clp.schema_fname); } else if (0 == strcmp("total_scan", clp.cmd_type)) { total_scan(clp.ini_fname, allocer, client, clp.version_range); } else if (0 == strcmp("minor_freeze", clp.cmd_type)) { minor_freeze(client); } else if (0 == strcmp("major_freeze", clp.cmd_type)) { major_freeze(client); } else if (0 == strcmp("fetch_schema", clp.cmd_type)) { fetch_schema(client, clp.timestamp); } else if (0 == strcmp("get_sstable_range_list", clp.cmd_type)) { get_sstable_range_list(client, clp.timestamp, clp.session_id); } else if (0 == strcmp("drop", clp.cmd_type)) { drop(client); } else if (0 == strcmp("dump_memtable", clp.cmd_type)) { dump_memtable(clp.ini_fname, client); } else if (0 == strcmp("dump_schemas", clp.cmd_type)) { dump_schemas(client); } else if (0 == strcmp("force_fetch_schema", clp.cmd_type)) { force_fetch_schema(client); } else if (0 == strcmp("reload_conf", clp.cmd_type)) { reload_conf(clp.ini_fname, client); } else if (0 == strcmp("memory_watch", clp.cmd_type)) { memory_watch(client); } else if (0 == strcmp("memory_limit", clp.cmd_type)) { memory_limit(clp.memory_limit, clp.memtable_limit, client); } else if (0 == strcmp("priv_queue_conf", clp.cmd_type)) { priv_queue_conf(clp.priv_queue_conf, client); } else if (0 == strcmp("clear_active_memtable", clp.cmd_type)) { clear_active_memtable(client); } else if (0 == strcmp("get_last_frozen_version", clp.cmd_type)) { get_last_frozen_version(client); } else if (0 == strcmp("fetch_ups_stat_info", clp.cmd_type)) { fetch_ups_stat_info(client); } else if (0 == strcmp("get_bloomfilter", clp.cmd_type)) { get_bloomfilter(client, clp.timestamp); } else if (0 == strcmp("store_memtable", clp.cmd_type)) { store_memtable(client, clp.timestamp); } else if (0 == strcmp("erase_sstable", clp.cmd_type)) { erase_sstable(client); } else if (0 == strcmp("load_new_store", clp.cmd_type)) { load_new_store(client); } else if (0 == strcmp("reload_all_store", clp.cmd_type)) { reload_all_store(client); } else if (0 == strcmp("reload_store", clp.cmd_type)) { reload_store(client, clp.timestamp); } else if (0 == strcmp("umount_store", clp.cmd_type)) { umount_store(client, clp.ini_fname); } else if (0 == strcmp("force_report_frozen_version", clp.cmd_type)) { force_report_frozen_version(client); } else if (0 == strcmp("switch_commit_log", clp.cmd_type)) { switch_commit_log(client); } else if (0 == strcmp("get_table_time_stamp", clp.cmd_type)) { get_table_time_stamp(client, clp.timestamp); } else if (0 == strcmp("disable_memtable_checksum", clp.cmd_type)) { disable_memtable_checksum(client); } else if (0 == strcmp("enable_memtable_checksum", clp.cmd_type)) { enable_memtable_checksum(client); } else if (0 == strcmp("immediately_drop_memtable", clp.cmd_type)) { immediately_drop_memtable(client); } else if (0 == strcmp("delay_drop_memtable", clp.cmd_type)) { delay_drop_memtable(client); } else if (0 == strcmp("minor_load_bypass", clp.cmd_type)) { rc = minor_load_bypass(client); } else if (0 == strcmp("major_load_bypass", clp.cmd_type)) { rc = major_load_bypass(client); } else if(0 == strcmp("list_sessions", clp.cmd_type)) { client.list_sessions(timeout); } else if(0 == strcmp("kill_session", clp.cmd_type)) { client.kill_session(timeout, clp.session_id); } else if (0 == strcmp("change_log_level", clp.cmd_type)) { change_log_level(client, clp.log_level); } else if (0 == strcmp("get_slave_ups_info", clp.cmd_type)) { get_slave_ups_info(client); } else if (0 == strcmp("print_scanner", clp.cmd_type)) { print_scanner(clp.ini_fname); } else if (0 == strcmp("print_schema", clp.cmd_type)) { print_schema(clp.ini_fname); } else if (0 == strcmp("sql_query", clp.cmd_type)) { execute_sql(client, clp.sql_query); } else if (0 == strcmp("ups_show_sessions", clp.cmd_type)) { ups_show_sessions(client); } else if (0 == strcmp("ups_kill_session", clp.cmd_type)) { ups_kill_session(static_cast<uint32_t>(clp.session_id), client); } else { print_usage(); } if (!clp.quickly_exit) { client.destroy(); TBSYS_LOG(INFO, "ups_admin end=================================================="); return rc; } else { TBSYS_LOG(INFO, "ups_admin killed=================================================="); fflush(stdout); fflush(stderr); _exit(rc); } }
void input_schema(Pschema s, char *attr_name, int spaces, int pretty, FILE *in_file){ // reads a schema and puts it on the top op tstack if(attr_name!=NULL && pretty){ print_spaces(spaces, stdout); fprintf(stdout, "Input record attribute \"%s\"\n",attr_name); } if(pretty){ print_spaces(spaces, stdout); } if(s->type == TY_RECORD || s->type == TY_ARRAY || s->type == TY_ATTR){ int size = get_schema_size(s); int nfields = 0; switch(s->type){ case TY_RECORD:{ if(pretty){ fprintf(stdout,"Input for a record\n"); } Pschema temp = s->child; while(temp){ input_schema(temp->child, temp->id, spaces+1, pretty, in_file); nfields++; temp = temp->brother; } break; } case TY_ARRAY:{ int i; if(pretty){ fprintf(stdout, "Input for an array\n"); } nfields = s->size; for(i=0; i<nfields; i++){ input_schema(s->child, NULL, spaces+1, pretty, in_file); } break; } default: print_schema(s,0); machine_error("TY_ATTR cannot be used in input_schema()."); break; } exec_cat(nfields,size); } else{ switch(s->type){ case TY_INT: { int in = read_int(stdout, in_file, "Insert an integer: ", pretty); push_int(in); break; } case TY_CHAR: { char in = read_char(stdout, in_file, "Insert a char: ", pretty); push_char(in); break; } case TY_REAL: { float in = read_real(stdout, in_file, "Insert a number of type real: ", pretty); push_real(in); break; } case TY_STRING: { char *in = read_string(stdout, in_file, "Insert a string: ", pretty); char *strig_to_store = stringtable_store(in, stringtable); freemem(in, strlen(in) + 1); push_string(strig_to_store); break; } case TY_BOOL: { char in = read_char(stdout, in_file, "Insert a boolean (0 or 1): ", pretty); push_bool(in == '1'); break; } default: {machine_error("Unknown type of schema in input_schema()."); break;} } } }
int main(int argc, char **argv) { char *device; const char *filename; int ch, dryrun; enum main_action action; device = NULL; filename = NULL; dryrun = 0; action = NONE; while ((ch = getopt(argc, argv, "Cd:Df:nS")) != -1) { switch (ch) { case 'C': if (action != NONE) { warnx( "Only one of -C, -D or -S may be specified"); usage(); } action = CONFIG; break; case 'd': device = strdup(optarg); break; case 'D': if (action != NONE) { warnx( "Only one of -C, -D or -S may be specified"); usage(); } action = DELETE; break; case 'f': filename = optarg; break; case 'n': dryrun = 1; break; case 'S': if (action != NONE) { warnx( "Only one of -C, -D or -S may be specified"); usage(); } action = PRINT_SCHEMA; break; case '?': warnx("Unrecognized argument '-%c'\n", optopt); usage(); break; } } if (device != NULL && filename != NULL) { warnx("Only one of the -d and -f flags may be specified"); usage(); } if (device == NULL && filename == NULL) { warnx("Either the -d or -f flag must be specified"); usage(); } switch (action) { case CONFIG: if (filename == NULL) { warnx("-d flag cannot be used with the -C flag"); usage(); } config_action(filename, dryrun); break; case DELETE: if (device == NULL) device = find_device(filename); delete_action(device, dryrun); free(device); break; case PRINT_SCHEMA: if (dryrun) { warnx("-n flag cannot be used with the -S flag"); usage(); } if (device == NULL) device = find_device(filename); print_schema(device); free(device); break; default: usage(); break; } exit(0); }