Пример #1
0
void ColumnCommandJL::reloadExtents()
{
	int err;
	BRM::DBRM dbrm;

	err = dbrm.getExtents(OID, extents);
	if (err) {
		ostringstream os;
		os << "pColStep: BRM lookup error. Could not get extents for OID " << OID;
		throw runtime_error(os.str());
	}

	sort(extents.begin(), extents.end(), BRM::ExtentSorter());
}
Пример #2
0
//------------------------------------------------------------------------------
// 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;
}
Пример #3
0
int main(int argc, char **argv)
{
    const int DEBUG_LVL_TO_DUMP_SYSCAT_RPT = 4;
#ifdef _MSC_VER
    //FIXME
#else
    setuid( 0 ); // set effective ID to root; ignore return status
#endif
    setlocale(LC_ALL, "");
    WriteEngine::Config::initConfigCache(); // load Calpont.xml config settings

    InputMgr mgr("299"); //@bug 391
    if (! mgr.input(argc, argv))
        return 1;

    int debugLevel = atoi(mgr.getParm(
        WriteEngine::XMLGenData::RPT_DEBUG).c_str());

    bool bUseLogFile = true;
    bool bSysCatRpt  = false;
    if (debugLevel == DEBUG_LVL_TO_DUMP_SYSCAT_RPT)
    {
        cout << "\nRunning colxml to dump system catalog report:\n\n";
        bUseLogFile = false;
        bSysCatRpt  = true;
    }
    else
    {
        cout << "\nRunning colxml with the following parameters:\n";
    }

    WriteEngine::XMLGenProc curJob(&mgr, bUseLogFile, bSysCatRpt);
    if( debugLevel > 0 && debugLevel <= 3 ) {
        curJob.setDebugLevel( debugLevel );
        cout << "\nDebug level is set to " << debugLevel << endl;
    }

    BRM::DBRM dbrm;
    if (dbrm.getSystemReady() < 1)
    {
        std::string errMsg(
            "System is not ready.  Verify that InfiniDB is up and ready "
            "before running colxml.");
        if (bUseLogFile)
            curJob.logErrorMessage(errMsg);
        else
            cout << errMsg << endl;
        return 1;
    }

    bool rc = false;

    const WriteEngine::XMLGenData::TableList& tables = mgr.getTables();
    try
    {
        if (tables.empty())
            mgr.loadCatalogTables();

        if (tables.empty()) 
        {
            string msg = "Either schema name is invalid or no table "
                         "is in the schema.";
            curJob.logErrorMessage(msg);
        }
        else
        {
            curJob.startXMLFile( );

            for (InputMgr::TableList::const_iterator tbl = tables.begin();
                tbl != tables.end() ; ++tbl)
            {
                curJob.makeTableData( *tbl );
                rc = curJob.makeColumnData(*tbl);
                if (!rc)
                    cout << "No columns for " << tbl->table << endl;
            }
        }
    }
    catch (runtime_error& ex)
    {
        curJob.logErrorMessage(string( "colxml runtime exception: ") +
            ex.what() );
        cout << curJob.errorString() << endl;
        return 1;
    }  
    catch (exception& ex)
    {
        curJob.logErrorMessage(string( "colxml exception: ") + ex.what() );
        cout << curJob.errorString() << endl;
        return 1;
    }
    catch (...)
    {
        curJob.logErrorMessage(string("colxml unknown exception "));
        cout << curJob.errorString() << endl;
        return 1;
    }  

    if (rc) 
    {
        if (debugLevel == DEBUG_LVL_TO_DUMP_SYSCAT_RPT)
        {
            std::string xmlFileName("-");
            curJob.writeXMLFile( xmlFileName );
            cout << "\nDump completed for tables:\n\t";
        }
        else
        {
            std::string xmlFileName = curJob.genJobXMLFileName( );
            cout << "Creating job description file: " << xmlFileName << endl;
            curJob.writeXMLFile( xmlFileName );
            cout << "File completed for tables:\n\t";
        }
        copy(tables.begin(), tables.end(),
            ostream_iterator<execplan::CalpontSystemCatalog::TableName>
            (cout, "\n\t"));
        cout << "\nNormal exit.\n";
    }
    else
    {
        cout << "File not made.\n";
        cout << curJob.errorString();
        return 1;
    }

    return 0;
}
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);
}
Пример #5
0
static int is_erydb_extents_fill(THD *thd, TABLE_LIST *tables, COND *cond)
{
    CHARSET_INFO *cs = system_charset_info;
    TABLE *table = tables->table;
    std::vector<struct BRM::EMEntry> entries;
   	std::vector<struct BRM::EMEntry>::iterator iter;
	std::vector<struct BRM::EMEntry>::iterator end;

    BRM::DBRM *emp = new BRM::DBRM();
    if (!emp || !emp->isDBRMReady())
    {
        return 1;
    }

    execplan::ObjectIDManager oidm;
    BRM::OID_t MaxOID = oidm.size();

    for(BRM::OID_t oid = 3000; oid <= MaxOID; oid++)
    {
        emp->getExtents(oid, entries, false, false, true);
        if (entries.size() == 0)
            continue;

        iter = entries.begin();
        end = entries.end();
        while (iter != end)
        {
            table->field[0]->store(oid);
            if (iter->colWid > 0)
            {
                table->field[1]->store("Column", strlen("Column"), cs);
                if (iter->partition.cprange.lo_val == std::numeric_limits<int64_t>::max() ||
        			iter->partition.cprange.lo_val <= (std::numeric_limits<int64_t>::min() + 2))
        		{
        		    table->field[4]->set_null();
        		}
        		else
        		{
        		    table->field[4]->set_notnull();
                    table->field[4]->store(iter->partition.cprange.lo_val);
                }
                if (iter->partition.cprange.hi_val == std::numeric_limits<int64_t>::max() ||
        			iter->partition.cprange.hi_val <= (std::numeric_limits<int64_t>::min() + 2))
        		{
        		    table->field[5]->set_null();
        		}
        		else
        		{
                    table->field[5]->set_notnull();
                    table->field[5]->store(iter->partition.cprange.hi_val);
                }
                table->field[6]->store(iter->colWid);

            }
            else
            {
                table->field[1]->store("Dictionary", strlen("Dictionary"), cs);
                table->field[4]->set_null();
                table->field[5]->set_null();
                table->field[6]->store(8192);
            }
            table->field[2]->store(iter->range.start);
            table->field[3]->store(iter->range.start + (iter->range.size * 1024) - 1);

            table->field[7]->store(iter->dbRoot);
            table->field[8]->store(iter->partitionNum);
            table->field[9]->store(iter->segmentNum);
            table->field[10]->store(iter->blockOffset);
            table->field[11]->store(iter->range.size * 1024);
            table->field[12]->store(iter->HWM);

            switch (iter->partition.cprange.isValid)
            {
                case 0:
                    table->field[13]->store("Invalid", strlen("Invalid"), cs);
                    break;
                case 1:
                    table->field[13]->store("Updating", strlen("Updating"), cs);
                    break;
                case 2:
                    table->field[13]->store("Valid", strlen("Valid"), cs);
                    break;
                default:
                    table->field[13]->store("Unknown", strlen("Unknown"), cs);
                    break;
            }
            switch (iter->status)
            {
                case BRM::EXTENTAVAILABLE:
                    table->field[14]->store("Available", strlen("Available"), cs);
                    break;
                case BRM::EXTENTUNAVAILABLE:
                    table->field[14]->store("Unavailable", strlen("Unavailable"), cs);
                    break;
                case BRM::EXTENTOUTOFSERVICE:
                    table->field[14]->store("Out of service", strlen("Out of service"), cs);
                    break;
                default:
                    table->field[14]->store("Unknown", strlen("Unknown"), cs);
            }
            // MCOL-454: special case, sometimes blockOffset can be > 0 and HWM can be 0
            if (iter->HWM == 0)
            {
                table->field[15]->store(8192);
            }
            else
            {
                table->field[15]->store((iter->HWM - iter->blockOffset + 1) * 8192);
            }

            if (schema_table_store_record(thd, table))
            {
                delete emp;
                return 1;
            }

            iter++;

        }
    }

    delete emp;
    return 0;
}
Пример #6
0
//------------------------------------------------------------------------------
// Main entry point to this program
//------------------------------------------------------------------------------
int main(int argc, char** argv)
{
	int c;
	bool clearLockOnly = false;
	bool rollbackOnly  = false;
	uint32_t tableOID  = 0;

	while ((c = getopt(argc, argv, "hlr:")) != EOF)
	{
		switch (c)
		{
			case 'l':
				clearLockOnly = true;
				break;
//Only allow '-r' option for development/debugging
#if 1
			case 'r': // hidden option to rollback specified table w/o a lock
				rollbackOnly  = true;
				tableOID      = ::strtoull(optarg, 0, 10);
				break;
#endif
			case 'h':
			case '?':
			default:
				usage();
				return (c == 'h' ? 0 : 1);
				break;
		}
	}

	if ((argc - optind) != 1 )
	{
		usage();
		return 1;
	}

	// Get the table lock ID specified by the user
	uint64_t lockID = ::strtoull(argv[optind], 0, 10);

	// If user specified both clearlock and rollback then we need to do both
	if (clearLockOnly && rollbackOnly)
	{
		clearLockOnly = false;
		rollbackOnly  = false;
	}

	//--------------------------------------------------------------------------
	// Verify that BRM is up and in a read/write state
	//--------------------------------------------------------------------------
	BRM::DBRM brm;
	int brmRc = brm.isReadWrite();
	if (brmRc != BRM::ERR_OK)
	{
		std::string brmErrMsg;
		BRM::errString(brmRc, brmErrMsg);
		std::cout << "BRM error: " << brmErrMsg << std::endl;
		std::cout << "Table lock " << lockID << " is not cleared." << std::endl;
		return 1;
	}

	if (brm.getSystemReady() < 1)
	{
		std::cout << "System is not ready.  Verify that EryDB "
			"is up and ready before running this program" << std::endl;
		return 1;
	}

	//--------------------------------------------------------------------------
	//@Bug 3711 Check whether the table is locked; does the table lock exist.
	//--------------------------------------------------------------------------
	execplan::erydbSystemCatalog::TableName tblName;
	BRM::TableLockInfo tInfo;
	std::string task;
	std::vector<uint32_t> pmList;
	int rc;
	const std::string taskSysCat("getting system catalog information");
	try {
		if (rollbackOnly)
		{
			tInfo.id             = lockID;
			tInfo.tableOID       = tableOID;
			tInfo.ownerPID       = 0;
			tInfo.ownerSessionID = 1;
			tInfo.state          = BRM::LOADING;

			// Construct PM list using all PMs, since we don't have a table
			// lock with the list of applicable DBRoots.
			task = "constructing total PM list";
			rc = constructPMList( pmList );
			if (rc != 0)
			{
				return 1;
			}
		}
		else
		{
			task = "getting table lock";
   			bool lockExists = brm.getTableLockInfo( lockID, &tInfo );
   			if (!lockExists)
			{
				std::cout << "Table lock " << lockID << " does not exist." <<
					std::endl;
				return 1;
			}

			// Construct PM list based on list of affected DBRoots
			task = "mapping DBRoots to PMs";
			rc = constructPMList( tInfo.dbrootList, pmList );
			if (rc != 0)
			{
				return 1;
			}
		}

		uint32_t sessionID = 1;
		task = taskSysCat;
		boost::shared_ptr<execplan::erydbSystemCatalog> systemCatalogPtr =
			execplan::erydbSystemCatalog::makeerydbSystemCatalog(
				sessionID );
		systemCatalogPtr->identity(execplan::erydbSystemCatalog::EC);
		tblName = systemCatalogPtr->tableName( tInfo.tableOID );
	}
	catch (std::exception& ex)
	{
		std::cout << "Error " << task << ".  " << ex.what() << std::endl;
		if (clearLockOnly && (task == taskSysCat))
		{
			tblName.schema= "[unknown name]";
			tblName.table.clear();
			std::cout << "Will still try to clear table lock." << std::endl;
		}
		else
		{
			std::cout << "Table lock " << lockID << " is not cleared." <<
				std::endl;
			return 1;
		}
	}
	catch (...)
	{
		std::cout << "Error " << task << ".  " << std::endl;
		if (clearLockOnly && (task == taskSysCat))
		{
			tblName.schema= "[unknown name]";
			tblName.table.clear();
			std::cout << "Will still try to clear table lock." << std::endl;
		}
		else
		{
			std::cout << "Table lock " << lockID << " is not cleared." <<
				std::endl;
			return 1;
		}
	}

	logInitStatus( tblName.toString(), lockID );
	if (rollbackOnly)
	{
		std::cout << "Rolling back table " << tblName.toString() <<
			std::endl << std::endl;
	}
	else if (clearLockOnly)
	{
		std::cout << "Clearing table lock " << lockID <<
			" for table " << tblName.toString() << std::endl << std::endl;
	}
	else
	{
		std::cout << "Rolling back and clearing table lock for table " <<
			tblName.toString() << "; table lock " << lockID <<
			std::endl << std::endl;
	}

	//--------------------------------------------------------------------------
	// Perform bulk rollback
	//--------------------------------------------------------------------------
	std::string errMsg;
	if (!clearLockOnly)
	{
		std::vector<boost::shared_ptr<messageqcpp::MessageQueueClient> >
			msgQueClts;
		rc = createMsgQueClts(pmList, msgQueClts, errMsg);
		if (rc != 0)
		{
			logFinalStatus( tblName.toString(), lockID, errMsg );
			std::cout << errMsg << std::endl;
			std::cout << "Table lock " << lockID << " for table " <<
				tblName.toString() << " is not cleared." << std::endl;
			return rc;
		}

		rc = execBulkRollbackReq( msgQueClts, pmList,
			&brm, tInfo, tblName.toString(), rollbackOnly, errMsg );
		if (rc != 0)
		{
			logFinalStatus( tblName.toString(), lockID, errMsg );
			std::cout << "Rollback error: " << errMsg << std::endl;
			std::cout << "Table lock " << lockID << " for table " <<
				tblName.toString() << " is not cleared." << std::endl;
			return rc;
		}

		//----------------------------------------------------------------------
		// Change the state of the table lock to cleanup state.
		// We ignore the return stateChange flag.
		//----------------------------------------------------------------------
		if (!rollbackOnly)
		{
			try {
				brm.changeState( tInfo.id, BRM::CLEANUP );
			}
			catch (std::exception& ex)
			{
				std::ostringstream oss;
				oss << "Error changing state.  " << ex.what();
				logFinalStatus( tblName.toString(), lockID, oss.str() );
				std::cout << oss.str() << std::endl;
				std::cout << "Table lock " << lockID << " is not cleared." <<
					std::endl;
				return 1;
			}
			catch (...)
			{
				std::ostringstream oss;
				oss << "Error changing state.  " << std::endl;
				logFinalStatus( tblName.toString(), lockID, oss.str() );
				std::cout << oss.str() << std::endl;
				std::cout << "Table lock " << lockID << " is not cleared." <<
					std::endl;
				return 1;
			}
		}

		//----------------------------------------------------------------------
		// Delete the meta data files
		//----------------------------------------------------------------------
		rc = execFileCleanupReq( msgQueClts, pmList,
			&brm, tInfo, tblName.toString(), errMsg );
		if (rc != 0)
		{
			//@Bug 4517. Release tablelock if remove meta files failed
			const std::string APPLNAME("cleartablelock command");
			const int SUBSYSTEM_ID = 19; // writeengine?
			const int COMP_MSG_NUM = logging::M0089;
			logging::Message::Args msgArgs;
			logging::Message logMsg( COMP_MSG_NUM );
			msgArgs.add( APPLNAME );
			msgArgs.add( tblName.toString() );
			msgArgs.add( lockID );
			msgArgs.add( errMsg );
			logMsg.format( msgArgs );
			logging::LoggingID  lid( SUBSYSTEM_ID );
			logging::MessageLog ml( lid );
			ml.logWarningMessage( logMsg );
			
			std::cout << "File cleanup error: " << errMsg << std::endl;
		}
	} // end of: if (!clearLockOnly)

	//--------------------------------------------------------------------------
	// Finally, release the actual table lock
	//--------------------------------------------------------------------------
	std::cout << std::endl;
	if (rollbackOnly)
	{
		logFinalStatus( tblName.toString(), lockID, std::string() );
		std::cout << "Bulk Rollback Only for table " << tblName.toString() <<
			" completed successfully." << std::endl;
	}
	else
	{
		try {
			brm.releaseTableLock( lockID ); // ignore boolean return value
		}
		catch (std::exception& ex)
		{
			logFinalStatus( tblName.toString(), lockID, ex.what() );
			std::cout << "Error releasing table lock " << lockID <<
				" for table " << tblName.toString() << std::endl;
			std::cout << ex.what() << std::endl;
			return 1;
		}
		catch (...)
		{
			std::string unknownErr("Unknown exception");
			logFinalStatus( tblName.toString(), lockID, unknownErr );
			std::cout << "Error releasing table lock " << lockID <<
				" for table " << tblName.toString() << std::endl;
			std::cout << unknownErr << std::endl;
			return 1;
		}

		logFinalStatus( tblName.toString(), lockID, std::string() );
		std::cout << "Table lock " << lockID << " for table " <<
			tblName.toString() << " is cleared." << std::endl;
	}
	
	return 0;
}
Пример #7
0
int main(int argc, char** argv)
{
#ifdef _MSC_VER
	const char* envp = getenv("SystemRoot");
	string SystemRoot;
	if (envp && *envp)
		SystemRoot = envp;
	else
		SystemRoot = "C:\\WINDOWS";
	string tmpEnv = "TMP=" + SystemRoot + "\\Temp";
	_putenv(tmpEnv.c_str());
#endif

	BRM::DBRM dbrm;

	int c;
	opterr = 0;
	vFlg = false;
	nFlg = false;

	while ((c = getopt(argc, argv, "vnh")) != EOF)
		switch (c)
		{
		case 'v':
			vFlg = true;
			break;
		case 'n':
			nFlg = true;
			break;
		case 'h':
		default:
			usage();
			return (c == 'h' ? 0 : 1);
			break;
		}

	if (nFlg)
		vFlg = true;

	ShmKeys keys;

	cerr << "(Exception msgs are probably OK)" << std::endl;

	RWLock *rwlock[MasterSegmentTable::nTables];
	int RWLockKeys[MasterSegmentTable::nTables];
	int i;

	if (MasterSegmentTable::nTables != 5) {
		cout << "There are more locks than reset_locks knows of.  Time for an update." << endl;
		exit(1);
	}

	RWLockKeys[0] = keys.KEYRANGE_EXTENTMAP_BASE;
	RWLockKeys[1] = keys.KEYRANGE_EMFREELIST_BASE;
	RWLockKeys[2] = keys.KEYRANGE_VBBM_BASE;
	RWLockKeys[3] = keys.KEYRANGE_VSS_BASE;
	RWLockKeys[4] = keys.KEYRANGE_CL_BASE;

	for (i = 0; i < MasterSegmentTable::nTables; i++)
		rwlock[i] = new RWLock(RWLockKeys[i]);

	if (vFlg)
	{
		PRINT("Extent Map", 0);
		PRINT("Extent Map free list", 1);
		PRINT("VBBM", 2);
		PRINT("VSS", 3);
		PRINT("CL", 4);
	}

	if (!nFlg)
	{
		RESET("Extent Map", 0);
		RESET("Extent Map free list", 1);
		RESET("VBBM", 2);
		RESET("VSS", 3);
		RESET("CL", 4);

		if (dbrm.isDBRMReady())
		{
			cout << " - resetting SessionManager semaphore" << endl;
			try {
				execplan::SessionManager sm;
				sm.reset();
			}
			catch (std::exception &e) {
				std::cout << e.what() << std::endl;
			}
		}
	}

	for (i = 0; i < MasterSegmentTable::nTables; i++)
		delete rwlock[i];
		
	std::cout << "OK." << std::endl;
	return 0;
}
Пример #8
0
OIDServer::OIDServer() : fFp(NULL), fFd(-1)
{
	boost::mutex::scoped_lock lk(CtorMutex);

	config::Config* conf;
	string tmp;
	ostringstream os;

	conf = config::Config::makeConfig();
	fFilename = conf->getConfig("OIDManager", "OIDBitmapFile");

	if (fFilename.empty()) {
		os << "OIDServer: <OIDManager><OIDBitmapFile> must exist in the config file";
		log(os.str());
		throw runtime_error(os.str());
	}

	if (IDBPolicy::useHdfs()) {
		if (!IDBPolicy::exists(fFilename.c_str())) { //no bitmap file
			BRM::DBRM em;
			if (!em.isEMEmpty())
			{
				os << "Extent Map not empty and " << fFilename << " not found. Setting system to read-only";
				cerr << os.str() << endl;
				log(os.str());
				em.setReadOnly(true);
				throw runtime_error(os.str());
			}

			fFp = IDBDataFile::open(IDBPolicy::getType(fFilename.c_str(), IDBPolicy::WRITEENG),
									fFilename.c_str(), "w+b", 0, 1);

			if (!fFp) {
				os << "Couldn't create oid bitmap file " << fFilename << ": " <<
						strerror(errno);
				log(os.str());
				throw ios_base::failure(os.str());
			}
#ifndef _MSC_VER
			//FIXME:
			//fchmod(fFd, 0666);   // XXXPAT: override umask at least for testing
			if (fFp)
				chmod(fFilename.c_str(), 0666);   // XXXPAT: override umask at least for testing
#endif
			try {
				initializeBitmap();
			}
			catch(...) {
				delete fFp;
				fFp = NULL;
				throw;
			}
		}
		else {
			fFp = IDBDataFile::open(IDBPolicy::getType(fFilename.c_str(), IDBPolicy::WRITEENG),
									fFilename.c_str(), "r+b", 0, 1);
			if (!fFp) {
				ostringstream os;
				os << "Couldn't open oid bitmap file" << fFilename << ": " <<
						strerror(errno);
				log(os.str());
				throw ios_base::failure(os.str());
			}
		}
	}
	else {
		if (access(fFilename.c_str(), F_OK) != 0) //no bitmap file
		{
			BRM::DBRM em;
			if (!em.isEMEmpty())
			{
				os << "Extent Map not empty and " << fFilename << " not found. Setting system to read-only";
				cerr << os.str() << endl;
				log(os.str());
				em.setReadOnly(true);
				throw runtime_error(os.str());
			}
		}

		fFd = open(fFilename.c_str(), O_CREAT | O_EXCL | O_RDWR | O_BINARY, 0666);
		if (fFd >= 0) {
#ifndef _MSC_VER
			//FIXME:
			fchmod(fFd, 0666);   // XXXPAT: override umask at least for testing
#endif
			try {
				initializeBitmap();
			}
			catch(...) {
				close(fFd);
				throw;
			}
		}
		else if (errno == EEXIST) {
			fFd = open(fFilename.c_str(), O_RDWR | O_BINARY);
			if (fFd < 0) {
				os << "Couldn't open oid bitmap file " << fFilename << ": " <<
						strerror(errno);
				log(os.str());
				throw ios_base::failure(os.str());
			}
		}
		else {
			os << "Couldn't create oid bitmap file " << fFilename << ": " <<
					strerror(errno);
			log(os.str());
			throw ios_base::failure(os.str());
		}
	}

	loadVBOIDs();
}
//------------------------------------------------------------------------------
// Finished working with this auto-increment.  Any remaining steps that are
// necessary to save or commit changes to the auto-increment nextValue, are
// applied here.
//------------------------------------------------------------------------------
int ColumnAutoInc::finish( )
{
    int rc = NO_ERROR;

    // We intentionally use a separate DBRM instance in this function.  We don't
    // use the BRMWrapper singleton.  We do this because the BRM call that is
    // made to issue a lock is a synchronous call that will block till a lock
    // is acquired.  Better to do this in a separate BRM instance, rather than
    // having this call block any other thread using BRM.
    BRM::DBRM dbrm;

    // We grab AI lock in order to access/synchronize DBRM and the system
    // catalog as a single operation, to avoid race condition between apps.
    try
    {
        dbrm.getAILock( fColumnOID );
    }
    catch (std::exception& ex)
    {
        std::ostringstream oss;
        oss << "Error locking auto-increment nextValue lock for table " <<
            fTableName << "; column " << fColumnName << "; " << ex.what();
        fLog->logMsg( oss.str(), ERR_AUTOINC_GET_LOCK, MSGLVL_ERROR );
        BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
        return ERR_AUTOINC_GET_LOCK;
    }

    uint64_t sysCatNextAuto = 0;
    rc = getNextValueFromSysCat( sysCatNextAuto );

    if (rc == NO_ERROR)
    {
        // Update system catalog if my latest AI nextValue is > the current
        // syscat AI nextValue.  max(uint64_t) denotes an AI column that has maxed out.
        uint64_t myNextValue = getNextAutoIncToSave();

        if ( (sysCatNextAuto != AUTOINCR_SATURATED) && // do not update if syscat already at max
                ((myNextValue >  sysCatNextAuto) ||
                 (myNextValue == AUTOINCR_SATURATED)) )
        {
            std::ostringstream oss2;
            oss2 << "Updating next auto increment for table-" << fTableName <<
                 ", column-"        << fColumnName <<
                 "; autoincrement " << myNextValue;
            fLog->logMsg( oss2.str(), MSGLVL_INFO2 );

            rc = BulkLoad::updateNextValue( fColumnOID, myNextValue );

            if (rc != NO_ERROR)
            {
                WErrorCodes ec;
                std::ostringstream oss;
                oss << "Error updating auto-increment nextValue for table " <<
                    fTableName << "; column " << fColumnName << "; rc=" << rc <<
                    "; " << ec.errorString(ERR_AUTOINC_UPDATE);
                fLog->logMsg( oss.str(), ERR_AUTOINC_UPDATE, MSGLVL_ERROR );
                BulkLoad::addErrorMsg2BrmUpdater(fTableName, oss);
                // Don't exit this function yet.  We set return code and fall
                // through to bottom of the function to release the AI lock.
                rc = ERR_AUTOINC_UPDATE;
            }
        }
        else
        {
            std::ostringstream oss2;
            oss2 << "Skip updating next auto increment for table-" << fTableName <<
                 ", column-"        << fColumnName <<
                 "; autoincrement " << myNextValue <<
                 "; syscat AI already at " << sysCatNextAuto;
            fLog->logMsg( oss2.str(), MSGLVL_INFO2 );
        }
    } // end of rc==NO_ERROR from getNextValueFromSysCat()

    try
    {
        dbrm.releaseAILock( fColumnOID );
    }
    catch (std::exception& ex)
    {
        // If we have trouble releasing AI lock, we log it, but we don't
        // consider it fatal to the job; so we don't return bad return code.
        std::ostringstream oss;
        oss << "Error releasing auto-increment nextValue lock for table " <<
            fTableName << "; column " << fColumnName << "; " << ex.what();
        fLog->logMsg( oss.str(), ERR_AUTOINC_REL_LOCK, MSGLVL_WARNING );
        //return ERR_AUTOINC_REL_LOCK;
    }

    return rc;
}
static int is_columnstore_files_fill(THD* thd, TABLE_LIST* tables, COND* cond)
{
    BRM::DBRM* emp = new BRM::DBRM();
    BRM::OID_t cond_oid = 0;
    TABLE* table = tables->table;

    if (!emp || !emp->isDBRMReady())
    {
        return 1;
    }

    if (cond && cond->type() == Item::FUNC_ITEM)
    {
        Item_func* fitem = (Item_func*) cond;

        if ((fitem->functype() == Item_func::EQ_FUNC) && (fitem->argument_count() == 2))
        {
            if (fitem->arguments()[0]->real_item()->type() == Item::FIELD_ITEM &&
                    fitem->arguments()[1]->const_item())
            {
                // WHERE object_id = value
                Item_field* item_field = (Item_field*) fitem->arguments()[0]->real_item();

                if (strcasecmp(item_field->field_name.str, "object_id") == 0)
                {
                    cond_oid = fitem->arguments()[1]->val_int();
                    return generate_result(cond_oid, emp, table, thd);
                }
            }
            else if (fitem->arguments()[1]->real_item()->type() == Item::FIELD_ITEM &&
                     fitem->arguments()[0]->const_item())
            {
                // WHERE value = object_id
                Item_field* item_field = (Item_field*) fitem->arguments()[1]->real_item();

                if (strcasecmp(item_field->field_name.str, "object_id") == 0)
                {
                    cond_oid = fitem->arguments()[0]->val_int();
                    return generate_result(cond_oid, emp, table, thd);
                }
            }
        }
        else if (fitem->functype() == Item_func::IN_FUNC)
        {
            // WHERE object_id in (value1, value2)
            Item_field* item_field = (Item_field*) fitem->arguments()[0]->real_item();

            if (strcasecmp(item_field->field_name.str, "object_id") == 0)
            {
                for (unsigned int i = 1; i < fitem->argument_count(); i++)
                {
                    cond_oid = fitem->arguments()[i]->val_int();
                    int result = generate_result(cond_oid, emp, table, thd);

                    if (result)
                        return 1;
                }
            }
        }
        else if (fitem->functype() == Item_func::UNKNOWN_FUNC &&
                 strcasecmp(fitem->func_name(), "find_in_set") == 0)
        {
            // WHERE FIND_IN_SET(object_id, values)
            String* tmp_var = fitem->arguments()[1]->val_str();
            std::stringstream ss(tmp_var->ptr());

            while (ss >> cond_oid)
            {
                int ret = generate_result(cond_oid, emp, table, thd);

                if (ret)
                    return 1;

                if (ss.peek() == ',')
                    ss.ignore();
            }
        }