//------------------------------------------------------------------------------ // Main entry point to this program //------------------------------------------------------------------------------ int main(int argc, char** argv) { int c; while ((c = getopt(argc, argv, "h")) != EOF) { switch (c) { case 'h': case '?': default: usage(); return (c == 'h' ? 0 : 1); break; } } int nargs = argc - optind; if ((nargs > 2) || (nargs == 1)) { usage(); return 1; } BRM::DBRM dbrm; std::vector<BRM::TableLockInfo> tableLocks; try { tableLocks = dbrm.getAllTableLocks(); } catch (std::exception& ex) { std::cerr << "Error getting list of table locks: " << ex.what() << std::endl; return 2; } int rc = 0; if (nargs == 2) // List table lock information for a given table { std::string schema(argv[optind++]); std::string table( argv[optind++]); // Get table oid CalpontSystemCatalog *systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(1); systemCatalogPtr->identity(CalpontSystemCatalog::EC); CalpontSystemCatalog::TableName tableName; tableName.schema = schema; tableName.table = table; CalpontSystemCatalog::ROPair roPair; try { roPair = systemCatalogPtr->tableRID( tableName ); } catch (logging::IDBExcept& e) { std::cerr << e.what() << std::endl; return 3; } catch (std::runtime_error& e) { std::cerr << "Error searching for table in system catalog. " << e.what() << std::endl; return 4; } catch (...) { std::cerr << "Unknown error searching for table in system catalog." <<std::endl; return 5; } // Keep in mind the same table could have more than 1 lock // (on different PMs), so we don't exit loop after "first" match. std::vector<BRM::TableLockInfo> matchingTableLocks; for (unsigned int i=0; i<tableLocks.size(); i++) { if (roPair.objnum == (CalpontSystemCatalog::OID) tableLocks[i].tableOID) { matchingTableLocks.push_back( tableLocks[i] ); } } if (matchingTableLocks.size() > 0) { std::string tableName(schema); tableName += '.'; tableName += table; rc = printTableLocks( systemCatalogPtr, tableName, matchingTableLocks ); } else { std::cout << " Table " << schema << "." << table << " is not locked by any process. " << std::endl; } } else // List table lock information for all table locks { //All table lock info required if (tableLocks.size() == 0) { std::cout << " No tables are locked in the database." << std::endl; } else { CalpontSystemCatalog *systemCatalogPtr = CalpontSystemCatalog::makeCalpontSystemCatalog(); systemCatalogPtr->identity(CalpontSystemCatalog::EC); std::string tableName; rc = printTableLocks( systemCatalogPtr, tableName, tableLocks ); } } return rc; }
int main(int argc, char **argv) { string command; Oam oam; BRM::DBRM dbrm; char c; // Invokes member function `int operator ()(void);' while ((c = getopt(argc, argv, "c:h")) != -1) { switch (c) { case 'c': command = optarg; break; case 'h': usage(argv[0]); exit(-1); break; default: usage(argv[0]); exit(1); break; } } if ( command == "suspend" ) { try { std::vector<BRM::TableLockInfo> tableLocks = dbrm.getAllTableLocks(); if (!tableLocks.empty()) { oam.DisplayLockedTables(tableLocks, &dbrm); } else { dbrm.setSystemSuspended(true); sleep(5); string cmd = startup::StartUp::installDir() + "/bin/save_brm > /var/log/mariadb/columnstore/save_brm.log1 2>&1"; int rtnCode = system(cmd.c_str()); if (rtnCode == 0) { cout << endl << "Suspend Calpont Database Writes Request successfully completed" << endl; } else { cout << endl << "Suspend Calpont Database Writes Failed: save_brm Failed" << endl; dbrm.setSystemSuspended(false); } } } catch (exception& e) { cout << endl << "**** Suspend Calpont Database Writes Failed: " << e.what() << endl; } catch(...) { cout << endl << "**** Suspend Calpont Database Writes Failed" << endl; } } else { if ( command == "resume" ) { try{ dbrm.setSystemSuspended(false); cout << endl << "Resume Calpont Database Writes Request successfully completed" << endl; } catch (exception& e) { cout << endl << "**** Resume Calpont Database Writes Failed: " << e.what() << endl; } catch(...) { cout << endl << "**** Resume Calpont Database Writes Failed" << endl; } } else { cout << "Invalid Command Entered, please try again" << endl; exit(-1); } } exit(0); }