コード例 #1
0
ファイル: reset_locks.cpp プロジェクト: Gwan-Wang/infinidb
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;
}
コード例 #2
0
ファイル: is_erydb_extents.cpp プロジェクト: hans511002/erydb
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;
}
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();
            }
        }