CmdInterpreter.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/farrago/CmdInterpreter.h#40 $
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) 1999-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 #ifndef Fennel_CmdInterpreter_Included
00025 #define Fennel_CmdInterpreter_Included
00026 
00027 #include "fennel/farrago/JniUtil.h"
00028 #include "fennel/farrago/Fem.h"
00029 #include "fennel/synch/StatsTimer.h"
00030 #include "fennel/common/FileStatsTarget.h"
00031 #include "fennel/ftrs/BTreeExecStream.h"
00032 
00033 #include <boost/utility.hpp>
00034 
00035 FENNEL_BEGIN_NAMESPACE
00036 
00037 class TraceTarget;
00038 class JavaTraceTarget;
00039 class JavaErrorTarget;
00040 class BTreeDescriptor;
00041 
00047 class FENNEL_FARRAGO_EXPORT CmdInterpreter
00048     : public boost::noncopyable, virtual public FemVisitor
00049 {
00050 public:
00054     struct DbHandle
00055     {
00056         SharedDatabase pDb;
00057         boost::shared_ptr<TraceTarget> pTraceTarget;
00058         StatsTimer statsTimer;
00059         SharedExecStreamGovernor pResourceGovernor;
00060 
00061         // TODO:  parameterize these
00062         explicit DbHandle()
00063             : statsTimer(500)
00064         {
00065         }
00066 
00067         virtual ~DbHandle();            // make class polymorphic
00068     };
00069 
00073     struct TxnHandle
00074     {
00075         SharedDatabase pDb;
00076         SharedLogicalTxn pTxn;
00077         SharedFtrsTableWriterFactory pFtrsTableWriterFactory;
00078         bool readOnly;
00079         SharedExecStreamGovernor pResourceGovernor;
00084         SharedSegment pSnapshotSegment;
00091         SharedSegment pReadCommittedSnapshotSegment;
00092 
00093         explicit TxnHandle()
00094             : readOnly(false)
00095             {
00096             }
00097 
00098         virtual ~TxnHandle();           // make class polymorphic
00099     };
00100 
00101     struct StreamGraphHandle
00102         : public BTreeOwnerRootMap
00103     {
00104         SharedExecStreamFactory pExecStreamFactory;
00105         SharedExecStreamGraph pExecStreamGraph;
00106         SharedExecStreamScheduler pScheduler;
00107         TxnHandle *pTxnHandle;
00111         SharedSegment pSegment;
00116         SharedSegment pReadCommittedSegment;
00117         // a global ref to the FarragoRuntimeContext
00118         jobject javaRuntimeContext;
00119 
00120         explicit StreamGraphHandle()
00121             : pTxnHandle(0), javaRuntimeContext(0)
00122             {
00123             }
00124 
00125         ~StreamGraphHandle();
00126 
00127         // implement BTreeOwnerRootMap
00128         virtual PageId getRoot(PageOwnerId pageOwnerId);
00129     };
00130 
00134     struct ExecutionHandle
00135     {
00139         volatile bool aborted;
00140     };
00141 
00146     ExecutionHandle *pExecHandle;
00147 
00148 protected:
00154     int64_t resultHandle;
00155 
00156     static DbHandle *getDbHandle(SharedProxyDbHandle);
00157     static TxnHandle *getTxnHandle(SharedProxyTxnHandle);
00158     static StreamGraphHandle *getStreamGraphHandle(
00159         SharedProxyStreamGraphHandle);
00160     static SavepointId getSavepointId(SharedProxySvptHandle);
00161     static TxnId getCsn(SharedProxyCsnHandle);
00162 
00163     virtual DbHandle *newDbHandle();    
00164     virtual TxnHandle *newTxnHandle();  
00165     void deleteDbHandle(DbHandle *);
00166 
00167     void setDbHandle(SharedProxyDbHandle,DbHandle *);
00168     void setTxnHandle(SharedProxyTxnHandle,TxnHandle *);
00169     void setStreamGraphHandle(SharedProxyStreamGraphHandle,StreamGraphHandle *);
00170     void setExecStreamHandle(SharedProxyStreamHandle,ExecStream *);
00171     void setSvptHandle(
00172         SharedProxySvptHandle,SavepointId);
00173     void setCsnHandle(SharedProxyCsnHandle, TxnId);
00174 
00175     void getBTreeForIndexCmd(ProxyIndexCmd &,PageId,BTreeDescriptor &);
00176     void dropOrTruncateIndex(
00177         ProxyCmdDropIndex &cmd, bool drop);
00178 
00179     virtual JavaTraceTarget *newTraceTarget();  
00180 
00189     void beginTxn(ProxyBeginTxnCmd &cmd, bool readOnly, TxnId csn);
00190 
00191     // Per-command overrides for FemVisitor; add new commands here
00192     virtual void visit(ProxyCmdCreateExecutionStreamGraph &);
00193     virtual void visit(ProxyCmdPrepareExecutionStreamGraph &);
00194     virtual void visit(ProxyCmdCreateStreamHandle &);
00195     virtual void visit(ProxyCmdCreateIndex &);
00196     virtual void visit(ProxyCmdTruncateIndex &);
00197     virtual void visit(ProxyCmdDropIndex &);
00198     virtual void visit(ProxyCmdVerifyIndex &);
00199     virtual void visit(ProxyCmdOpenDatabase &);
00200     virtual void visit(ProxyCmdCloseDatabase &);
00201     virtual void visit(ProxyCmdCheckpoint &);
00202     virtual void visit(ProxyCmdSetParam &);
00203     virtual void visit(ProxyCmdBeginTxn &);
00204     virtual void visit(ProxyCmdBeginTxnWithCsn &);
00205     virtual void visit(ProxyCmdSavepoint &);
00206     virtual void visit(ProxyCmdCommit &);
00207     virtual void visit(ProxyCmdRollback &);
00208     virtual void visit(ProxyCmdGetTxnCsn &);
00209     virtual void visit(ProxyCmdGetLastCommittedTxnId &);
00210     virtual void visit(ProxyCmdAlterSystemDeallocate &);
00211     virtual void visit(ProxyCmdVersionIndexRoot &);
00212     virtual void visit(ProxyCmdInitiateBackup &);
00213     virtual void visit(ProxyCmdCompleteBackup &);
00214     virtual void visit(ProxyCmdAbandonBackup &);
00215     virtual void visit(ProxyCmdRestoreFromBackup &);
00216 
00217 public:
00225     virtual int64_t executeCommand(ProxyCmd &cmd);
00226 
00227     static inline StreamGraphHandle &getStreamGraphHandleFromLong(jlong);
00228     static inline ExecStream &getExecStreamFromLong(jlong);
00229     static inline TxnHandle &getTxnHandleFromLong(jlong);
00230     static inline ExecutionHandle &getExecutionHandleFromLong(jlong);
00231     static inline jobject getObjectFromLong(jlong jHandle);
00232 
00242     static void readTupleDescriptor(
00243         TupleDescriptor &tupleDesc,
00244         ProxyTupleDescriptor &javaTupleDesc,
00245         StoredTypeDescriptorFactory const &typeFactory);
00246 
00254     static void readTupleProjection(
00255         TupleProjection &tupleProj,
00256         SharedProxyTupleProjection pJavaTupleProj);
00257 
00258     static SharedErrorTarget newErrorTarget(
00259         jobject fennelJavaErrorTarget);
00260 };
00261 
00262 inline jobject CmdInterpreter::getObjectFromLong(jlong jHandle)
00263 {
00264     jobject *pGlobalRef = reinterpret_cast<jobject *>(jHandle);
00265     return *pGlobalRef;
00266 }
00267 
00268 inline CmdInterpreter::StreamGraphHandle &
00269 CmdInterpreter::getStreamGraphHandleFromLong(jlong jHandle)
00270 {
00271     return *reinterpret_cast<StreamGraphHandle *>(jHandle);
00272 }
00273 
00274 inline ExecStream &CmdInterpreter::getExecStreamFromLong(jlong jHandle)
00275 {
00276     return *reinterpret_cast<ExecStream *>(jHandle);
00277 }
00278 
00279 inline CmdInterpreter::TxnHandle &CmdInterpreter::getTxnHandleFromLong(
00280     jlong jHandle)
00281 {
00282     return *reinterpret_cast<TxnHandle *>(jHandle);
00283 }
00284 
00285 inline CmdInterpreter::ExecutionHandle
00286 &CmdInterpreter::getExecutionHandleFromLong(
00287     jlong jHandle)
00288 {
00289     return *reinterpret_cast<ExecutionHandle *>(jHandle);
00290 }
00291 
00292 // The following macros are used for tracing the JniUtil handle count.
00293 // They are defined here to allow for the allocation of these handle
00294 // types from other locations while still deallocating them in the
00295 // handle class destructors (handle count tracing depends on the handle
00296 // type string being the same at allocation and deallocation time).
00297 #define DBHANDLE_TRACE_TYPE_STR ("DbHandle")
00298 #define TXNHANDLE_TRACE_TYPE_STR ("TxnHandle")
00299 #define STREAMGRAPHHANDLE_TRACE_TYPE_STR ("StreamGraphHandle")
00300 #define EXECHANDLE_TRACE_TYPE_STR ("ExecutionHandle")
00301 
00302 
00303 FENNEL_END_NAMESPACE
00304 
00305 #endif
00306 
00307 // End CmdInterpreter.h

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1