00001 /* 00002 // $Id: //open/dev/fennel/exec/ExecStream.cpp#19 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2005-2009 SQLstream, Inc. 00006 // Copyright (C) 2005-2009 LucidEra, Inc. 00007 // Portions Copyright (C) 2004-2009 John V. Sichi 00008 // 00009 // This program is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by the Free 00011 // Software Foundation; either version 2 of the License, or (at your option) 00012 // any later version approved by The Eigenbase Project. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #include "fennel/common/CommonPreamble.h" 00025 #include "fennel/exec/ExecStream.h" 00026 #include "fennel/exec/ExecStreamGraph.h" 00027 #include "fennel/exec/ExecStreamScheduler.h" 00028 #include "fennel/cache/CacheAccessor.h" 00029 #include "fennel/txn/LogicalTxn.h" 00030 00031 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/exec/ExecStream.cpp#19 $"); 00032 00033 ExecStreamParams::ExecStreamParams() 00034 { 00035 } 00036 00037 ExecStreamParams::~ExecStreamParams() 00038 { 00039 } 00040 00041 ExecStream::ExecStream() 00042 { 00043 pGraph = NULL; 00044 id = MAXU; 00045 isOpen = false; 00046 name = ""; 00047 } 00048 00049 bool ExecStream::canEarlyClose() 00050 { 00051 return true; 00052 } 00053 00054 void ExecStream::closeImpl() 00055 { 00056 isOpen = false; 00057 00058 // REVIEW jvs 19-July-2004: It would be nice to be able to do this, making 00059 // sure no cache access is attempted while stream is closed. However, 00060 // it currently causes trouble with TableWriters, which need 00061 // cache access for txn replay. 00062 /* 00063 if (pQuotaAccessor) { 00064 pQuotaAccessor->setMaxLockedPages(0); 00065 } 00066 if (pScratchQuotaAccessor) { 00067 pScratchQuotaAccessor->setMaxLockedPages(0); 00068 } 00069 */ 00070 } 00071 00072 void ExecStream::checkAbort() const 00073 { 00074 if (!pGraph) { 00075 return; 00076 } 00077 ExecStreamScheduler *pScheduler = pGraph->getScheduler(); 00078 if (!pScheduler) { 00079 return; 00080 } 00081 pScheduler->checkAbort(); 00082 } 00083 00084 void ExecStream::prepare(ExecStreamParams const ¶ms) 00085 { 00086 if (pGraph) { 00087 pDynamicParamManager = pGraph->getDynamicParamManager(); 00088 } 00089 pQuotaAccessor = params.pCacheAccessor; 00090 pScratchQuotaAccessor = params.scratchAccessor.pCacheAccessor; 00091 } 00092 00093 void ExecStream::getResourceRequirements( 00094 ExecStreamResourceQuantity &minQuantity, 00095 ExecStreamResourceQuantity &optQuantity, 00096 ExecStreamResourceSettingType &optType) 00097 { 00098 getResourceRequirements(minQuantity, optQuantity); 00099 optType = EXEC_RESOURCE_ACCURATE; 00100 } 00101 00102 void ExecStream::getResourceRequirements( 00103 ExecStreamResourceQuantity &minQuantity, 00104 ExecStreamResourceQuantity &optQuantity) 00105 { 00106 minQuantity.nThreads = 0; 00107 minQuantity.nCachePages = 0; 00108 optQuantity = minQuantity; 00109 } 00110 00111 void ExecStream::setResourceAllocation( 00112 ExecStreamResourceQuantity &quantity) 00113 { 00114 resourceAllocation = quantity; 00115 if (pQuotaAccessor) { 00116 pQuotaAccessor->setMaxLockedPages(quantity.nCachePages); 00117 } 00118 if (pScratchQuotaAccessor) { 00119 pScratchQuotaAccessor->setMaxLockedPages(quantity.nCachePages); 00120 } 00121 } 00122 00123 void ExecStream::open(bool restart) 00124 { 00125 if (restart) { 00126 // REVIEW jvs 3-Jan-2007: We used to be able to assert this, 00127 // but now that we've introduced early close to release 00128 // resources, we can't. 00129 #if 0 00130 assert(isOpen); 00131 #endif 00132 } else { 00133 // NOTE: this assertion is bad because in case of multiple 00134 // inheritance, open can be called twice. So we rely on the 00135 // corresponding assertion in ExecStreamGraph instead, unless 00136 // someone can come up with something better. 00137 #if 0 00138 assert(!isOpen); 00139 #endif 00140 isOpen = true; 00141 needsClose = true; 00142 } 00143 if (pGraph) { 00144 pTxn = pGraph->getTxn(); 00145 TxnId txnId = pGraph->getTxnId(); 00146 if (txnId != NULL_TXN_ID) { 00147 if (pQuotaAccessor) { 00148 pQuotaAccessor->setTxnId(txnId); 00149 } 00150 if (pScratchQuotaAccessor) { 00151 pScratchQuotaAccessor->setTxnId(txnId); 00152 } 00153 } 00154 } 00155 } 00156 00157 void ExecStream::setName(std::string const &nameInit) 00158 { 00159 name = nameInit; 00160 } 00161 00162 std::string const &ExecStream::getName() const 00163 { 00164 return name; 00165 } 00166 00167 bool ExecStream::mayBlock() const 00168 { 00169 return false; 00170 } 00171 00172 ExecStreamBufProvision ExecStream::getOutputBufProvision() const 00173 { 00174 return BUFPROV_NONE; 00175 } 00176 00177 ExecStreamBufProvision ExecStream::getOutputBufConversion() const 00178 { 00179 return BUFPROV_NONE; 00180 } 00181 00182 ExecStreamBufProvision ExecStream::getInputBufProvision() const 00183 { 00184 return BUFPROV_NONE; 00185 } 00186 00187 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/exec/ExecStream.cpp#19 $"); 00188 00189 // End ExecStream.cpp