//--------------------------------------------------------------------------- // @function: // IMemoryPool::NewImpl // // @doc: // Implementation of New that can be used by "operator new" functions //// //--------------------------------------------------------------------------- void* IMemoryPool::NewImpl ( SIZE_T cSize, const CHAR *szFilename, ULONG ulLine, IMemoryPool::EAllocationType eat ) { GPOS_ASSERT(ULONG_MAX >= cSize); GPOS_ASSERT_IMP ( (NULL != CMemoryPoolManager::Pmpm()) && (this == CMemoryPoolManager::Pmpm()->PmpGlobal()), CMemoryPoolManager::Pmpm()->FAllowGlobalNew() && "Use of new operator without target memory pool is prohibited, use New(...) instead" ); ULONG ulAlloc = CMemoryPool::UlAllocSize((ULONG) cSize); void *pv = PvAllocate(ulAlloc, szFilename, ulLine); GPOS_OOM_CHECK(pv); return dynamic_cast<CMemoryPool*>(this)->PvFinalizeAlloc(pv, (ULONG) cSize, eat); }
//--------------------------------------------------------------------------- // @function: // CMiniDumperDXLTest::EresUnittest_Basic // // @doc: // Test minidumps in case of an exception // //--------------------------------------------------------------------------- GPOS_RESULT CMiniDumperDXLTest::EresUnittest_Basic() { CAutoMemoryPool amp(CAutoMemoryPool::ElcNone); IMemoryPool *mp = amp.Pmp(); CWStringDynamic minidumpstr(mp); COstreamString oss(&minidumpstr); CMiniDumperDXL mdrs(mp); mdrs.Init(&oss); CHAR file_name[GPOS_FILE_NAME_BUF_SIZE]; GPOS_TRY { CSerializableStackTrace serStackTrace; // read the dxl document CHAR *szQueryDXL = CDXLUtils::Read(mp, szQueryFile); // parse the DXL query tree from the given DXL document CQueryToDXLResult *ptroutput = CDXLUtils::ParseQueryToQueryDXLTree(mp, szQueryDXL, NULL); GPOS_CHECK_ABORT; CSerializableQuery serQuery(mp, ptroutput->CreateDXLNode(), ptroutput->GetOutputColumnsDXLArray(), ptroutput->GetCTEProducerDXLArray()); // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); // we need to use an auto pointer for the cache here to ensure // deleting memory of cached objects when we throw CAutoP<CMDAccessor::MDCache> apcache; apcache = CCacheFactory::CreateCache<gpopt::IMDCacheObject*, gpopt::CMDKey*> ( true, // fUnique 0 /* unlimited cache quota */, CMDKey::UlHashMDKey, CMDKey::FEqualMDKey ); CMDAccessor::MDCache *pcache = apcache.Value(); CMDAccessor mda(mp, pcache, CTestUtils::m_sysidDefault, pmdp); CSerializableMDAccessor serMDA(&mda); CAutoTraceFlag atfPrintQuery(EopttracePrintQuery, true); CAutoTraceFlag atfPrintPlan(EopttracePrintPlan, true); CAutoTraceFlag atfTest(EtraceTest, true); COptimizerConfig *optimizer_config = GPOS_NEW(mp) COptimizerConfig ( CEnumeratorConfig::GetEnumeratorCfg(mp, 0 /*plan_id*/), CStatisticsConfig::PstatsconfDefault(mp), CCTEConfig::PcteconfDefault(mp), ICostModel::PcmDefault(mp), CHint::PhintDefault(mp), CWindowOids::GetWindowOids(mp) ); // setup opt ctx CAutoOptCtxt aoc ( mp, &mda, NULL, /* pceeval */ CTestUtils::GetCostModel(mp) ); // translate DXL Tree -> Expr Tree CTranslatorDXLToExpr *pdxltr = GPOS_NEW(mp) CTranslatorDXLToExpr(mp, &mda); CExpression *pexprTranslated = pdxltr->PexprTranslateQuery ( ptroutput->CreateDXLNode(), ptroutput->GetOutputColumnsDXLArray(), ptroutput->GetCTEProducerDXLArray() ); gpdxl::ULongPtrArray *pdrgul = pdxltr->PdrgpulOutputColRefs(); gpmd::CMDNameArray *pdrgpmdname = pdxltr->Pdrgpmdname(); ULONG ulSegments = GPOPT_TEST_SEGMENTS; CQueryContext *pqc = CQueryContext::PqcGenerate(mp, pexprTranslated, pdrgul, pdrgpmdname, true /*fDeriveStats*/); // optimize logical expression tree into physical expression tree. CEngine eng(mp); CSerializableOptimizerConfig serOptConfig(mp, optimizer_config); eng.Init(pqc, NULL /*search_stage_array*/); eng.Optimize(); CExpression *pexprPlan = eng.PexprExtractPlan(); (void) pexprPlan->PrppCompute(mp, pqc->Prpp()); // translate plan into DXL IntPtrArray *pdrgpiSegments = GPOS_NEW(mp) IntPtrArray(mp); GPOS_ASSERT(0 < ulSegments); for (ULONG ul = 0; ul < ulSegments; ul++) { pdrgpiSegments->Append(GPOS_NEW(mp) INT(ul)); } CTranslatorExprToDXL ptrexprtodxl(mp, &mda, pdrgpiSegments); CDXLNode *pdxlnPlan = ptrexprtodxl.PdxlnTranslate(pexprPlan, pqc->PdrgPcr(), pqc->Pdrgpmdname()); GPOS_ASSERT(NULL != pdxlnPlan); CSerializablePlan serPlan(mp, pdxlnPlan, optimizer_config->GetEnumeratorCfg()->GetPlanId(), optimizer_config->GetEnumeratorCfg()->GetPlanSpaceSize()); GPOS_CHECK_ABORT; // simulate an exception GPOS_OOM_CHECK(NULL); } GPOS_CATCH_EX(ex) { // unless we're simulating faults, the exception must be OOM GPOS_ASSERT_IMP ( !GPOS_FTRACE(EtraceSimulateAbort) && !GPOS_FTRACE(EtraceSimulateIOError) && !IWorker::m_enforce_time_slices, CException::ExmaSystem == ex.Major() && CException::ExmiOOM == ex.Minor() ); mdrs.Finalize(); GPOS_RESET_EX; CWStringDynamic str(mp); COstreamString oss(&str); oss << std::endl << "Minidump" << std::endl; oss << minidumpstr.GetBuffer(); oss << std::endl; // dump the same to a temp file ULONG ulSessionId = 1; ULONG ulCommandId = 1; CMinidumperUtils::GenerateMinidumpFileName(file_name, GPOS_FILE_NAME_BUF_SIZE, ulSessionId, ulCommandId, NULL /*szMinidumpFileName*/); std::wofstream osMinidump(file_name); osMinidump << minidumpstr.GetBuffer(); oss << "Minidump file: " << file_name << std::endl; GPOS_TRACE(str.GetBuffer()); } GPOS_CATCH_END; // TODO: - Feb 11, 2013; enable after fixing problems with serializing // XML special characters (OPT-2996) // // try to load minidump file // CDXLMinidump *pdxlmd = CMinidumperUtils::PdxlmdLoad(mp, file_name); // GPOS_ASSERT(NULL != pdxlmd); // delete pdxlmd; // delete temp file ioutils::Unlink(file_name); return GPOS_OK; }