⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_tpcc.c

📁 oracle数据库tpcc(在线事务处理能力)测试的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*+**************************************************************************
*
*
* COPYRIGHT (c) 1997 BY
*
* DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
*
* ALL RIGHTS RESERVED.
*
*
*
* THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED *
* ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE *
* INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER *
* COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY *
* OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY *
* TRANSFERRED.
*
*
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE *
* AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT *
* CORPORATION.
*
*
*
* DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS *
* SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*
*
*
*
*
****************************************************************************/
/*+
* Abstract: This file contains the Digital created front end functions
* for the tpcc benchmark.
*
* Author: A Bradley & W Carr
* Creation Date: May 1997
*
*
* Modification history:
*
*
* 08/01/2002 Andrew Bond, HP
* - Conversion to run under Linux and Apache
* - Additions by Joe Orton to support Apache 2.0
*/
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "ap_mpm.h"
#include "apr_thread_mutex.h"
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <oci.h>
#include <ocidfn.h>
#include <ociapr.h>
#define MOD_TPCC_C
#include <tpccerr.h>
#include <tpccstruct.h>
#include <oracle_db8.h>
#include <tpccapi.h>
#include <tpcc.h>
#include <mod_tpcc.h>
#ifdef FFE_DEBUG
# include <crtdbg.h>
static int tmpDbgFlag;
static _HFILE hMemFile;
#endif
int tpcc_handler(request_rec *req);
static int tpcc_post_config(apr_pool_t *p, apr_pool_t *plog,apr_pool_t *ptemp, server_rec *s);
static void tpcc_child_init(apr_pool_t *p, server_rec *s);
static apr_status_t tpcc_child_exit(void *data);
#define FORMMAXSIZE 4096
#define MYFILE "/etc/httpd/logs/tpcc.log"
#define BOGUS "Bogus File!"
#define GOOD "Good File!"
int LogFD;
int myerrno;
int max_threads;
static void tpcc_register_hooks(apr_pool_t *p)
{
   fprintf(stderr, "register()");
   ap_hook_handler(tpcc_handler, NULL, NULL, APR_HOOK_MIDDLE);
   ap_hook_post_config(tpcc_post_config, NULL, NULL,APR_HOOK_MIDDLE);
/*
ap_hook_child_init(tpcc_child_init, NULL, NULL,
APR_HOOK_MIDDLE);
*/
}
/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA tpcc_module = {STANDARD20_MODULE_STUFF,
	NULL, /* create per-dir config structures*/
	NULL, /* merge per-dir config structures*/
	NULL, /* create per-server config structures*/
	NULL, /* merge per-server config structures*/
	NULL, /* table of config file commands*/
	tpcc_register_hooks /* register hooks */
};
#define MAX(a,b) ((a)>(b)?(a):(b))
#define PUT_STRING(szString, iLen, pStart, pStruct) \
   pStruct.szStr=szString; pStruct.iIndex=pStart; \
   pStruct.iFieldSize=iLen;
#define CONVERT_SPECIAL(pout,pin,iwid) \
{\
   char *out = pout;\
   char *in = pin; \
   int wid = iwid;\
   while( wid && '\0' != *in )\
   {\
     if( '>' == *in )\
     {\
     	*out++='&'; *out++='g'; *out++='t'; *out++=';'; \
     }\
     else if( '<' == *in )\
     {\
     	*out++='&'; *out++='l'; *out++='t'; *out++=';'; \
     }\
     else if( '&' == *in )\
     {\
     	*out++='&'; *out++='a'; *out++='m'; *out++='p'; *out++=';'; \
     }\
     else if( '\"' == *in )\
     {\
     	*out++='&'; *out++='q'; *out++='u'; *out++='o'; *out++='t';*out++=';';\
     }\
     else\
     {*out++=*in;}\
     in++;\
     wid--;\
   }\
   while( wid-- ) *out++ = ' ';\
}
/* define indexes for the building of the forms */
/* defines for new order */
#define NO_WDID 0
#define NO_WID NO_WDID + 1
#define NO_DID NO_WID + 1
#define NO_DATE NO_DID + 1
#define NO_CID NO_DATE + 1
#define NO_LAST NO_CID + 1
#define NO_CREDIT NO_LAST + 1
#define NO_DISC NO_CREDIT + 1
#define NO_OID NO_DISC + 1
#define NO_LINES NO_OID + 1
#define NO_W_TAX NO_LINES + 1
#define NO_D_TAX NO_W_TAX + 1
#define NO_S_WID NO_D_TAX + 1
#define NO_IID NO_S_WID + 1
#define NO_INAME NO_IID + 1
#define NO_QTY NO_INAME + 1
#define NO_STOCK NO_QTY + 1
#define NO_BG NO_STOCK + 1
#define NO_PRICE NO_BG + 1
#define NO_AMT NO_PRICE + 1
#define NO_STAT NO_AMT + (14*8) + 1
#define NO_TOTAL NO_STAT + 1
/* defines for payment input form */
#define PT_WDID_INPUT 0
#define PT_WID_INPUT PT_WDID_INPUT + 1
/* defines for payment output form */
#define PT_WDID 0
#define PT_LONG_DATE PT_WDID + 1
#define PT_WID PT_LONG_DATE + 1
#define PT_DID PT_WID + 1
#define PT_W_ST_1 PT_DID + 1
#define PT_D_ST_1 PT_W_ST_1 + 1
#define PT_W_ST_2 PT_D_ST_1 + 1
#define PT_D_ST_2 PT_W_ST_2 + 1
#define PT_W_CITY PT_D_ST_2 + 1
#define PT_W_ST PT_W_CITY + 1
#define PT_W_ZIP PT_W_ST + 1
#define PT_D_CITY PT_W_ZIP + 1
#define PT_D_ST PT_D_CITY + 1
#define PT_D_ZIP PT_D_ST + 1
#define PT_CID PT_D_ZIP + 1
#define PT_C_WID PT_CID + 1
#define PT_C_DID PT_C_WID + 1
#define PT_FIRST PT_C_DID + 1
#define PT_MIDDLE PT_FIRST + 1
#define PT_LAST PT_MIDDLE + 1
#define PT_SM_DATE PT_LAST + 1
#define PT_C_STR_1 PT_SM_DATE + 1
#define PT_CREDIT PT_C_STR_1 + 1
#define PT_D_STR_2 PT_CREDIT + 1
#define PT_DISC PT_D_STR_2 + 1
#define PT_C_CITY PT_DISC + 1
#define PT_C_ST PT_C_CITY + 1
#define PT_C_ZIP PT_C_ST + 1
#define PT_C_PHONE PT_C_ZIP + 1
#define PT_AMT PT_C_PHONE + 1
#define PT_BAL PT_AMT + 1
#define PT_LIM PT_BAL + 1
#define PT_CUST_DATA PT_LIM + 1
/* defines for order status */
#define OS_WDID 0
#define OS_WID OS_WDID + 1
#define OS_DID OS_WID + 1
#define OS_CID OS_DID + 1
#define OS_FIRST OS_CID + 1
#define OS_MIDDLE OS_FIRST + 1
#define OS_LAST OS_MIDDLE + 1
#define OS_BAL OS_LAST + 1
#define OS_OID OS_BAL + 1
#define OS_DATE OS_OID + 1
#define OS_CAR_ID OS_DATE + 1
#define OS_S_WID OS_CAR_ID + 1
#define OS_IID OS_S_WID + 1
#define OS_QTY OS_IID + 1
#define OS_AMT OS_QTY + 1
#define OS_SM_DATE OS_AMT + 1
/* defines for delivery form */
#define D_WDID 0
#define D_WID D_WDID + 1
#define D_CAR D_WID + 1
#define D_QUEUE1 D_CAR + 1
#define D_DELTA1 D_QUEUE1 + 1
#define D_WID1 D_DELTA1 + 1
#define D_CAR1 D_WID1 + 1
#define D_OID10 D_CAR1 + 1
#define D_OID11 D_OID10 + 1
#define D_OID12 D_OID11 + 1
#define D_OID13 D_OID12 + 1
#define D_OID14 D_OID13 + 1
#define D_OID15 D_OID14 + 1
#define D_OID16 D_OID15 + 1
#define D_OID17 D_OID16 + 1
#define D_OID18 D_OID17 + 1
#define D_OID19 D_OID18 + 1
#define D_QUEUE2 D_OID19 + 1
#define D_DELTA2 D_QUEUE2 + 1
#define D_WID2 D_DELTA2 + 1
#define D_CAR2 D_WID2 + 1
#define D_OID20 D_CAR2 + 1
#define D_OID21 D_OID20 + 1
#define D_OID22 D_OID21 + 1
#define D_OID23 D_OID22 + 1
#define D_OID24 D_OID23 + 1
#define D_OID25 D_OID24 + 1
#define D_OID26 D_OID25 + 1
#define D_OID27 D_OID26 + 1
#define D_OID28 D_OID27 + 1
#define D_OID29 D_OID28 + 1
/* defines for stock level form */
#define SL_WDID 0
#define SL_WID SL_WDID + 1
#define SL_DID SL_WID + 1
#define SL_TH SL_DID + 1
#define SL_LOW SL_TH + 1
#define WDID(w_id,d_id) (w_id*10+(d_id-1))
#define PANIC_FORM_SIZE 4096
#define NUMBER_POOL_FORM_TYPES 5
#define DELIVERY_FORM 0
#define NEW_ORDER_FORM 1
#define ORDER_STATUS_FORM 2
#define PAYMENT_FORM 3
#define STOCK_LEVEL_FORM 4
#define NUMBER_POOL_RESPONSE_TYPES 5
#define DELIVERY_RESPONSE 0
#define NEW_ORDER_RESPONSE 1
#define ORDER_STATUS_RESPONSE 2
#define PAYMENT_RESPONSE 3
#define STOCK_LEVEL_RESPONSE 4
#ifdef FFE_DEBUG
# define FFE_ASSERT(arg) _ASSERT(arg)
#else
# define FFE_ASSERT(arg)
#endif
#define RESERVE_FORM(type,szForm)\
{\
   apr_thread_mutex_lock( gpForms->critSec[type] );\
   FFE_ASSERT( gpForms->iNextFreeForm[type] <= gpForms->iMaxIndex[type] );\
   szForm = gpForms->index[gpForms->iFirstFormIndex[type] +\
   gpForms->iNextFreeForm[type]++];\
   apr_thread_mutex_unlock( gpForms->critSec[type] );\
}
#define UNRESERVE_FORM(type,szForm)\
{\
   apr_thread_mutex_lock( gpForms->critSec[type] );\
   FFE_ASSERT( gpForms->iNextFreeForm[type] > 0 );\
   gpForms->index[gpForms->iFirstFormIndex[type] +\
   --gpForms->iNextFreeForm[type]] = szForm;\
   apr_thread_mutex_unlock( gpForms->critSec[type] );\
}
#define RESERVE_RESPONSE(type,szResponse)\
{\
   apr_thread_mutex_lock( gpResponses->critSec[type] );\
   FFE_ASSERT(gpResponses->iNextFreeResponse[type]<=gpResponses->iMaxIndex[type]);\
   szResponse = gpResponses->index[gpResponses->iFirstResponseIndex[type] +\
   gpResponses->iNextFreeResponse[type]++];\
   apr_thread_mutex_unlock( gpResponses->critSec[type] );\
}
#define UNRESERVE_RESPONSE(type,szResponse)\
{\
   apr_thread_mutex_lock( gpResponses->critSec[type] );\
   FFE_ASSERT(gpResponses->iNextFreeResponse[type] > 0 );\
   gpResponses->index[gpResponses->iFirstResponseIndex[type] +\
   --gpResponses->iNextFreeResponse[type]] = szResponse;\
   apr_thread_mutex_unlock( gpResponses->critSec[type] );\
}
#define RESERVE_PANIC_FORM(szForm)\
{\
   apr_thread_mutex_lock( gpPanicForms->critSec );\
   FFE_ASSERT( gpPanicForms->iNextFree <= gpPanicForms->iMaxIndex);\
   szForm = gpPanicForms->index[gpPanicForms->iNextFree++];\
   apr_thread_mutex_unlock( gpPanicForms->critSec );\
}
#define UNRESERVE_PANIC_FORM(szForm)\
{\
   apr_thread_mutex_lock( gpPanicForms->critSec );\
   FFE_ASSERT( gpPanicForms->iNextFree > 0 );\
   gpPanicForms->index[--gpPanicForms->iNextFree] = szForm;\
   apr_thread_mutex_unlock( gpPanicForms->critSec );\
}
#if 0
   CMD 0
   FORM ID 3
   LOGIN WAREHOUSE 4
   LOGIN DISTRICT 5
   DELI QUEUE TIME 6
   CARRIER ID 7
   DISTRICT 8
   CUSTOMER 9
   NEWORDER FIELDS A-X,a-u
   CUST LAST NAME Y
   CUST WAREHOUSE Z
   CUST DISTRICT v
   AMOUNT PAID w
   THRESHOLD x
#endif
#define MENU_BAR \
   "<HR>"\
   "<INPUT TYPE=submit NAME=0 VALUE=NewOrder>"\
   "<INPUT TYPE=submit NAME=0 VALUE=Payment>"\
   "<INPUT TYPE=submit NAME=0 VALUE=Delivery>"\
   "<INPUT TYPE=submit NAME=0 VALUE=OrderStatus>"\
   "<INPUT TYPE=submit NAME=0 VALUE=StockLevel>"\
   "<INPUT TYPE=submit NAME=0 VALUE=Exit>"
static char szFormTemplate[] ="<BODY><FORM ACTION=%s METHOD=GET>";
static char szWelcomeFormTemplate[] ="<BODY><FORM ACTION=/%s METHOD=GET>"
"<INPUT TYPE=hidden NAME=3 VALUE=W00>"
"Please Identify your Warehouse and District for this session.<BR>"
"Warehouse ID <INPUT NAME=4 SIZE=5><BR>"
"District ID <INPUT NAME=5 SIZE=2><BR>"
"<HR>"
"<INPUT TYPE=submit NAME=0 VALUE=Submit>"
"</FORM></BODY>";
static char
szWelcomeForm[sizeof(szWelcomeFormTemplate)+FILENAMESIZE];
static int iWelcomeFormLen;
static char szMainMenuFormTemplate[] =
"<BODY><FORM ACTION=%s METHOD=GET>"
"<INPUT TYPE=hidden NAME=3 VALUE=M%06d>"
"%55.55s<BR>"
"Select Desired Transaction.<BR>"
MENU_BAR
"</FORM></BODY>";
static char szDeliveryFormTemp2i[] =
"<INPUT TYPE=hidden NAME=3 VALUE=D######>"
"<INPUT TYPE=hidden NAME=6 VALUE=0>"
"<PRE> Delivery<BR>"
"Warehouse: #####<BR><BR>"
"Carrier Number: <INPUT NAME=7 SIZE=1><BR><BR>"
"Execution Status:<BR></PRE>"
"<HR><INPUT TYPE=submit NAME=0 VALUE=Process>"
"<INPUT TYPE=submit NAME=0 VALUE=Menu>"
"</FORM></BODY>";
static char szDeliveryFormTemp2p[] =
"<INPUT TYPE=hidden NAME=3 VALUE=d######>"
"<PRE> Delivery<BR>"
"Warehouse: #####<BR><BR>"
"Carrier Number: ##<BR><BR>"
"Execution Status: Delivery has been queued.<BR>"
"</PRE>"
MENU_BAR
"</FORM></BODY>";
static char szNewOrderFormTemp2i[] =
"<INPUT TYPE=hidden NAME=3 VALUE=N######>"
"<PRE> New Order<BR>"
"Warehouse: #####"
" District: <INPUT NAME=8 SIZE=2>
Date:<BR>"
"Customer: <INPUT NAME=9 SIZE=4> "
"Name: Credit: %Disc:<BR>"
"Order Number: Number of Lines: "
"W_tax: D_tax:<BR><BR>"
" Supp_W Item_Id Item Name Qty Stock B/G "
"Price Amount<BR>"
" <INPUT NAME=A SIZE=5> <INPUT NAME=B SIZE=6>"
" <INPUT NAME=C SIZE=1><BR>"
" <INPUT NAME=D SIZE=5> <INPUT NAME=E SIZE=6>"
" <INPUT NAME=F SIZE=1><BR>"
" <INPUT NAME=G SIZE=5> <INPUT NAME=H SIZE=6>"
" <INPUT NAME=I SIZE=1><BR>"
" <INPUT NAME=J SIZE=5> <INPUT NAME=K SIZE=6>"
" <INPUT NAME=L SIZE=1><BR>"
" <INPUT NAME=M SIZE=5> <INPUT NAME=N SIZE=6>"
" <INPUT NAME=O SIZE=1><BR>"
" <INPUT NAME=P SIZE=5> <INPUT NAME=Q SIZE=6>"
" <INPUT NAME=R SIZE=1><BR>"
" <INPUT NAME=S SIZE=5> <INPUT NAME=T SIZE=6>"
" <INPUT NAME=U SIZE=1><BR>"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -