00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00062 explicit DbHandle()
00063 : statsTimer(500)
00064 {
00065 }
00066
00067 virtual ~DbHandle();
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();
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
00118 jobject javaRuntimeContext;
00119
00120 explicit StreamGraphHandle()
00121 : pTxnHandle(0), javaRuntimeContext(0)
00122 {
00123 }
00124
00125 ~StreamGraphHandle();
00126
00127
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
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
00293
00294
00295
00296
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