void DatabaseOrdinary::renameTable( const Context & context, const String & table_name, IDatabase & to_database, const String & to_table_name) { DatabaseOrdinary * to_database_concrete = typeid_cast<DatabaseOrdinary *>(&to_database); if (!to_database_concrete) throw Exception("Moving tables between databases of different engines is not supported", ErrorCodes::NOT_IMPLEMENTED); StoragePtr table = tryGetTable(table_name); if (!table) throw Exception("Table " + name + "." + table_name + " doesn't exist.", ErrorCodes::TABLE_ALREADY_EXISTS); /// Уведомляем таблицу о том, что она переименовывается. Если таблица не поддерживает переименование - кинется исключение. try { table->rename(context.getPath() + "/data/" + escapeForFileName(to_database_concrete->name) + "/", to_database_concrete->name, to_table_name); } catch (const Poco::Exception & e) { /// Более хорошая диагностика. throw Exception{e}; } ASTPtr ast = getCreateQueryImpl(path, table_name); ASTCreateQuery & ast_create_query = typeid_cast<ASTCreateQuery &>(*ast); ast_create_query.table = to_table_name; /// NOTE Неатомарно. to_database_concrete->createTable(to_table_name, table, ast, table->getName()); removeTable(table_name); }
/*Удаление игрока*/ void removePlayerFromTable(void *buf) { int id = *((int *)buf); int i, index; int max_players = MAX_TABLES_COUNT * MAX_PLAYERS_PER_TABLE; char remove_name[256]; /* 1) Searching player's name by id */ for (index = 0; index < max_players; index++) { if (IdName[index].id == id) { /* If name found */ strncpy(remove_name, IdName[index].name, MAX_NAME_LENGTH); break; } } /* 2) Searching requested player by name */ for (index = 0; index < MAX_TABLES_COUNT; index++) { for (i = 0; i < MAX_PLAYERS_PER_TABLE; i++) { if ((strcmp(room.tables[index].players[i], remove_name)) == 0) { /* If name found */ bzero(room.tables[index].players[i], MAX_NAME_LENGTH); /* 3) Decrement structure "information of table" */ inofList[index].countPlayer -= 1; if (inofList[index].countPlayer == 0) { removeTable(room.tables[index].id); } return; } } } }
void DatabaseOrdinary::renameTable( const Context & context, const String & table_name, IDatabase & to_database, const String & to_table_name) { DatabaseOrdinary * to_database_concrete = typeid_cast<DatabaseOrdinary *>(&to_database); if (!to_database_concrete) throw Exception("Moving tables between databases of different engines is not supported", ErrorCodes::NOT_IMPLEMENTED); StoragePtr table = tryGetTable(context, table_name); if (!table) throw Exception("Table " + name + "." + table_name + " doesn't exist.", ErrorCodes::UNKNOWN_TABLE); /// Notify the table that it is renamed. If the table does not support renaming, exception is thrown. try { table->rename(context.getPath() + "/data/" + escapeForFileName(to_database_concrete->name) + "/", to_database_concrete->name, to_table_name); } catch (const Exception &) { throw; } catch (const Poco::Exception & e) { /// Better diagnostics. throw Exception{e}; } ASTPtr ast = getQueryFromMetadata(detail::getTableMetadataPath(metadata_path, table_name)); if (!ast) throw Exception("There is no metadata file for table " + table_name, ErrorCodes::FILE_DOESNT_EXIST); ASTCreateQuery & ast_create_query = typeid_cast<ASTCreateQuery &>(*ast); ast_create_query.table = to_table_name; /// NOTE Non-atomic. to_database_concrete->createTable(context, to_table_name, table, ast); removeTable(context, table_name); }
void CLounge::processLogouts(long /*now*/) { bool sendUpdate = false; // // Process logging out players // list<PlayerPtr>::iterator i = loggingOut_.begin(); while (i != loggingOut_.end()) { sendUpdate = true; string username = (*i).player_->name(); SOCKET sd = (*i).player_->getSocket(); printf("Logging out player %s socket %d.\n", username.c_str(), sd); // Forget ip address UnregisterIPAddress((*i).player_->getIpAddress()); // Erase the player from the main list. tolower(username); if (players_.erase(username) == 0) { // player was not in main list - erase from // logging in list LoginPlayers::iterator it = find_if(loggingIn_.begin(), loggingIn_.end(), same_socket(sd)); if (it != loggingIn_.end()) loggingIn_.erase(it); } // Terminate the connection CPoller::Inst()->removePlayerSocket(sd); Sys_CloseSocket(sd); // Notify Load Balancer and/or lounges notifyOthers(RemovePlayer, username.c_str()); // Remove it from logging out list i = loggingOut_.erase(i); } // // Process logging out tables // list<TablePtr>::iterator ti = loggingOutTables_.begin(); while (ti != loggingOutTables_.end()) { sendUpdate = true; CTable* table = (*ti).table_; printf("*** Removing table %d socket %d.\n", table->getNumber(), table->getSocket()); removeTable(table); // NOTE: after removeTable 'table' points to destroyed data // Remove it from logging out list ti = loggingOutTables_.erase(ti); } if (sendUpdate) { // Send login stats update if something was removed CpduLoungeStats pduStats; pduStats.sendStats(players_.size(), tables_.size()); } }
BlockIO InterpreterDropQuery::execute() { String path = context.getPath(); String current_database = context.getCurrentDatabase(); ASTDropQuery & drop = typeid_cast<ASTDropQuery &>(*query_ptr); bool drop_database = drop.table.empty() && !drop.database.empty(); if (drop_database && drop.detach) { context.detachDatabase(drop.database); return {}; } String database_name = drop.database.empty() ? current_database : drop.database; String database_name_escaped = escapeForFileName(database_name); String data_path = path + "data/" + database_name_escaped + "/"; String metadata_path = path + "metadata/" + database_name_escaped + "/"; auto database = context.tryGetDatabase(database_name); if (!database && !drop.if_exists) throw Exception("Database " + database_name + " doesn't exist", ErrorCodes::UNKNOWN_DATABASE); std::vector<std::pair< StoragePtr, std::unique_ptr<DDLGuard>>> tables_to_drop; if (!drop_database) { StoragePtr table; if (drop.if_exists) table = context.tryGetTable(database_name, drop.table); else table = context.getTable(database_name, drop.table); if (table) tables_to_drop.emplace_back(table, context.getDDLGuard(database_name, drop.table, "Table " + database_name + "." + drop.table + " is dropping or detaching right now")); else return {}; } else { if (!database) { if (!drop.if_exists) throw Exception("Database " + database_name + " doesn't exist", ErrorCodes::UNKNOWN_DATABASE); return {}; } for (auto iterator = database->getIterator(); iterator->isValid(); iterator->next()) tables_to_drop.emplace_back(iterator->table(), context.getDDLGuard(database_name, iterator->name(), "Table " + database_name + "." + iterator->name() + " is dropping or detaching right now")); } for (auto & table : tables_to_drop) { table.first->shutdown(); /// If table was already dropped by anyone, an exception will be thrown auto table_lock = table.first->lockForAlter(); String current_table_name = table.first->getTableName(); if (drop.detach) { /// Drop table from memory, don't touch data and metadata database->detachTable(current_table_name); } else { if (!table.first->checkTableCanBeDropped()) throw Exception("Table " + database_name + "." + current_table_name + " couldn't be dropped due to failed pre-drop check", ErrorCodes::TABLE_WAS_NOT_DROPPED); /// Delete table metdata and table itself from memory database->removeTable(current_table_name); /// Delete table data table.first->drop(); table.first->is_dropped = true; String current_data_path = data_path + escapeForFileName(current_table_name); if (Poco::File(current_data_path).exists()) Poco::File(current_data_path).remove(true); } } if (drop_database) { /// Delete the database. The tables in it have already been deleted. auto lock = context.getLock(); /// Someone could have time to delete the database before us. context.assertDatabaseExists(database_name); /// Someone could have time to create a table in the database to be deleted while we deleted the tables without the context lock. if (!context.getDatabase(database_name)->empty()) throw Exception("New table appeared in database being dropped. Try dropping it again.", ErrorCodes::DATABASE_NOT_EMPTY); /// Delete database information from the RAM auto database = context.detachDatabase(database_name); /// Delete the database. database->drop(); Poco::File(data_path).remove(false); Poco::File(metadata_path).remove(false); } return {}; }
CLuaObject::~CLuaObject() { removeTable(); }
bool BufferManager::deleteAll(const Table *pTable ){ return removeTable(pTable) && createTable(pTable); }
/** * @brief Remove multiple tables -- if found -- from Streamer. * * @param tables */ void Streamer::removeTables( vector<Id> tables ) { for( vector<Id>::const_iterator it = tables.begin(); it != tables.end(); it++) removeTable( *it ); }