1/*
2 * Legal Notice
3 *
4 * This document and associated source code (the "Work") is a part of a
5 * benchmark specification maintained by the TPC.
6 *
7 * The TPC reserves all right, title, and interest to the Work as provided
8 * under U.S. and international laws, including without limitation all patent
9 * and trademark rights therein.
10 *
11 * No Warranty
12 *
13 * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION
14 * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE
15 * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER
16 * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
17 * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES,
18 * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
19 * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF
20 * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE.
21 * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
22 * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT
23 * WITH REGARD TO THE WORK.
24 * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO
25 * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE
26 * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS
27 * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT,
28 * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY,
29 * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT
30 * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD
31 * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * Contributors
34 * - Sergey Vasilevskiy
35 * - Doug Johnson
36 */
37
38/*
39 * Class that generates transaction input data for the Customer Emulator (CE).
40 */
41
42#ifndef CE_TXN_INPUT_GENERATOR_H
43#define CE_TXN_INPUT_GENERATOR_H
44
45#include "utilities/EGenUtilities_stdafx.h"
46#include "TxnHarnessStructs.h"
47#include "DriverParamSettings.h"
48#include "EGenLogger.h"
49
50#include "input/DataFileManager.h"
51#include "Brokers.h"
52#include "HoldingsAndTradesTable.h"
53
54namespace TPCE {
55
56class CCETxnInputGenerator {
57 CRandom m_rnd; // used inside for parameter generation
58 CPerson m_Person;
59 CCustomerSelection m_CustomerSelection;
60 CCustomerAccountsAndPermissionsTable m_AccsAndPerms;
61 CHoldingsAndTradesTable m_Holdings;
62 CBrokersTable m_Brokers;
63 const CCompanyFile &m_pCompanies;
64 const CSecurityFile &m_pSecurities;
65 const IndustryDataFile_t &m_pIndustries;
66 const SectorDataFile_t &m_pSectors;
67 const StatusTypeDataFile_t &m_pStatusType;
68 const TradeTypeDataFile_t &m_pTradeType;
69 PDriverCETxnSettings m_pDriverCETxnSettings;
70 CBaseLogger *m_pLogger;
71
72 TIdent m_iConfiguredCustomerCount;
73 TIdent m_iActiveCustomerCount;
74
75 TIdent m_iMyStartingCustomerId;
76 TIdent m_iMyCustomerCount;
77 INT32 m_iPartitionPercent;
78
79 INT32 m_iScaleFactor;
80 INT32 m_iHoursOfInitialTrades;
81 INT64 m_iMaxActivePrePopulatedTradeID;
82
83 INT64 m_iTradeLookupFrame2MaxTimeInMilliSeconds;
84 INT64 m_iTradeLookupFrame3MaxTimeInMilliSeconds;
85 INT64 m_iTradeLookupFrame4MaxTimeInMilliSeconds;
86
87 INT64 m_iTradeUpdateFrame2MaxTimeInMilliSeconds;
88 INT64 m_iTradeUpdateFrame3MaxTimeInMilliSeconds;
89
90 // number of securities (scaled based on active customers)
91 TIdent m_iActiveSecurityCount;
92 TIdent m_iActiveCompanyCount;
93 // number of industries (from flat file)
94 INT32 m_iIndustryCount;
95 // number of sector names (from flat file)
96 INT32 m_iSectorCount;
97 // starting ids
98 TIdent m_iStartFromCompany;
99 CDateTime m_StartTime; // start time of initial trades
100 CDateTime m_EndTime; // end time of initial trades
101
102 INT32 m_iTradeOrderRollbackLimit;
103 INT32 m_iTradeOrderRollbackLevel;
104
105 /*
106 * Perform initialization common to all constructors.
107 *
108 * PARAMETERS:
109 * IN pDriverCETxnSettings - initial transaction parameter
110 * settings
111 *
112 * RETURNS:
113 * none.
114 */
115 void Initialize();
116
117 /*
118 * Generate Non-Uniform customer ID.
119 *
120 * PARAMETERS:
121 * OUT iCustomerId - generated C_ID
122 * OUT iCustomerTier - generated C_TIER
123 *
124 * RETURNS:
125 * none.
126 */
127 void GenerateNonUniformRandomCustomerId(TIdent &iCustomerId, eCustomerTier &iCustomerTier);
128
129 /*
130 * Generate customer account ID (uniformly distributed).
131 *
132 * PARAMETERS:
133 * none.
134 *
135 * RETURNS:
136 * CA_ID uniformly distributed across all load units.
137 */
138 TIdent GenerateRandomCustomerAccountId(void);
139
140 /*
141 * Generate a trade id to be used in Trade-Lookup / Trade-Update Frame 1.
142 *
143 * PARAMETERS:
144 * IN AValue - parameter to NURAND function
145 * IN SValue - parameter to NURAND function
146 *
147 * RETURNS:
148 * T_ID, distributed non-uniformly.
149 */
150 TTrade GenerateNonUniformTradeID(INT32 AValue, INT32 SValue);
151
152 /*
153 * Generate a trade timestamp to be used in Trade-Lookup / Trade-Update.
154 *
155 * PARAMETERS:
156 * OUT dts - returned timestamp
157 * IN MaxTimeInMilliSeconds - time interval (from the first
158 * initial trade) in which to generate the timestamp IN AValue - parameter
159 * to NURAND function IN SValue - parameter to NURAND
160 * function
161 *
162 * RETURNS:
163 * none.
164 */
165 void GenerateNonUniformTradeDTS(TIMESTAMP_STRUCT &dts, INT64 MaxTimeInMilliSeconds, INT32 AValue, INT32 SValue);
166
167public:
168 /*
169 * Constructor - no partitioning by C_ID.
170 *
171 * PARAMETERS:
172 * IN dfm - Data file manager
173 * IN iConfiguredCustomerCount - number of configured
174 * customers in the database IN iActiveCustomerCount - number of
175 * active customers in the database IN iScaleFactor - scale
176 * factor (number of customers per 1 tpsE) of the database IN
177 * iHoursOfInitialTrades - number of hours of the initial trades
178 * portion of the database IN pLogger - reference to
179 * parameter logging object IN pDriverCETxnSettings - initial
180 * transaction parameter settings
181 *
182 * RETURNS:
183 * not applicable.
184 */
185 CCETxnInputGenerator(const DataFileManager &dfm, TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount,
186 INT32 iScaleFactor, INT32 iHoursOfInitialTrades, CBaseLogger *pLogger,
187 const PDriverCETxnSettings pDriverCETxnTunables);
188
189 /*
190 * Constructor - no partitioning by C_ID, RNG seed provided.
191 *
192 * RNG seed is for testing/engineering work allowing repeatable transaction
193 * parameter stream. This constructor is NOT legal for a benchmark
194 * publication.
195 *
196 * PARAMETERS:
197 * IN dfm - Data file manager
198 * IN iConfiguredCustomerCount - number of configured
199 * customers in the database IN iActiveCustomerCount - number of
200 * active customers in the database IN iScaleFactor - scale
201 * factor (number of customers per 1 tpsE) of the database IN
202 * iHoursOfInitialTrades - number of hours of the initial trades
203 * portion of the database IN RNGSeed - initial seed
204 * for random number generator IN pLogger - reference
205 * to parameter logging object IN pDriverCETxnSettings - initial
206 * transaction parameter settings
207 *
208 * RETURNS:
209 * not applicable.
210 */
211 CCETxnInputGenerator(const DataFileManager &dfm, TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount,
212 INT32 iScaleFactor, INT32 iHoursOfInitialTrades, RNGSEED RNGSeed, CBaseLogger *pLogger,
213 const PDriverCETxnSettings pDriverCETxnTunables);
214
215 /*
216 * Constructor - partitioning by C_ID.
217 *
218 * PARAMETERS:
219 * IN dfm - Data file manager
220 * IN iConfiguredCustomerCount - number of configured
221 * customers in the database IN iActiveCustomerCount - number of
222 * active customers in the database IN iScaleFactor - scale
223 * factor (number of customers per 1 tpsE) of the database IN
224 * iHoursOfInitialTrades - number of hours of the initial trades
225 * portion of the database IN iMyStartingCustomerId - first customer
226 * id (1-based) of the partition for this instance IN iMyCustomerCount -
227 * number of customers in the partition for this instance IN
228 * iPartitionPercent - the percentage of C_IDs generated within
229 * this instance's partition IN pLogger - reference to
230 * parameter logging object IN pDriverCETxnSettings - initial
231 * transaction parameter settings
232 *
233 * RETURNS:
234 * not applicable.
235 */
236 CCETxnInputGenerator(const DataFileManager &dfm, TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount,
237 INT32 iScaleFactor, INT32 iHoursOfInitialTrades, TIdent iMyStartingCustomerId,
238 TIdent iMyCustomerCount, INT32 iPartitionPercent, CBaseLogger *pLogger,
239 const PDriverCETxnSettings pDriverCETxnTunables);
240
241 /*
242 * Constructor - partitioning by C_ID, RNG seed provided.
243 *
244 * RNG seed is for testing/engineering work allowing repeatable transaction
245 * parameter stream. This constructor is NOT legal for a benchmark
246 * publication.
247 *
248 * PARAMETERS:
249 * IN dfm - Data file manager
250 * IN iConfiguredCustomerCount - number of configured
251 * customers in the database IN iActiveCustomerCount - number of
252 * active customers in the database IN iScaleFactor - scale
253 * factor (number of customers per 1 tpsE) of the database IN
254 * iHoursOfInitialTrades - number of hours of the initial trades
255 * portion of the database IN iMyStartingCustomerId - first customer
256 * id (1-based) of the partition for this instance IN iMyCustomerCount -
257 * number of customers in the partition for this instance IN
258 * iPartitionPercent - the percentage of C_IDs generated within
259 * this instance's partition IN pLogger - reference to
260 * parameter logging object IN pDriverCETxnSettings - initial
261 * transaction parameter settings
262 *
263 * RETURNS:
264 * not applicable.
265 */
266 CCETxnInputGenerator(const DataFileManager &dfm, TIdent iConfiguredCustomerCount, TIdent iActiveCustomerCount,
267 INT32 iScaleFactor, INT32 iHoursOfInitialTrades, TIdent iMyStartingCustomerId,
268 TIdent iMyCustomerCount, INT32 iPartitionPercent, RNGSEED RNGSeed, CBaseLogger *pLogger,
269 const PDriverCETxnSettings pDriverCETxnTunables);
270
271 /*
272 * Return internal random number generator seed.
273 *
274 * PARAMETERS:
275 * none.
276 *
277 * RETURNS:
278 * current random number generator seed.
279 */
280 RNGSEED GetRNGSeed(void);
281
282 /*
283 * Set internal random number generator seed.
284 *
285 * PARAMETERS:
286 * IN RNGSeed - new random number generator seed
287 *
288 * RETURNS:
289 * none.
290 */
291 void SetRNGSeed(RNGSEED RNGSeed);
292
293 /*
294 * Refresh internal information from the external transaction parameters.
295 * This function should be called anytime the external transaction
296 * parameter structure changes.
297 *
298 * PARAMETERS:
299 * none.
300 *
301 * RETURNS:
302 * none.
303 */
304 void UpdateTunables();
305
306 /*
307 * Generate Broker-Volume transaction input.
308 *
309 * PARAMETERS:
310 * OUT TxnReq - input parameter structure filled
311 * in for the transaction.
312 *
313 * RETURNS:
314 * the number of brokers generated.
315 */
316 void GenerateBrokerVolumeInput(TBrokerVolumeTxnInput &TxnReq);
317
318 /*
319 * Generate Customer-Position transaction input.
320 *
321 * PARAMETERS:
322 * OUT TxnReq - input parameter structure filled
323 * in for the transaction.
324 *
325 * RETURNS:
326 * none.
327 */
328 void GenerateCustomerPositionInput(TCustomerPositionTxnInput &TxnReq);
329
330 /*
331 * Generate Market-Watch transaction input.
332 *
333 * PARAMETERS:
334 * OUT TxnReq - input parameter structure filled
335 * in for the transaction.
336 *
337 * RETURNS:
338 * none.
339 */
340 void GenerateMarketWatchInput(TMarketWatchTxnInput &TxnReq);
341
342 /*
343 * Generate Security-Detail transaction input.
344 *
345 * PARAMETERS:
346 * OUT TxnReq - input parameter structure filled
347 * in for the transaction.
348 *
349 * RETURNS:
350 * none.
351 */
352 void GenerateSecurityDetailInput(TSecurityDetailTxnInput &TxnReq);
353
354 /*
355 * Generate Trade-Lookup transaction input.
356 *
357 * PARAMETERS:
358 * OUT TxnReq - input parameter structure filled
359 * in for the transaction.
360 *
361 * RETURNS:
362 * none.
363 */
364 void GenerateTradeLookupInput(TTradeLookupTxnInput &TxnReq);
365
366 /*
367 * Generate Trade-Order transaction input.
368 *
369 * PARAMETERS:
370 * OUT TxnReq - input parameter structure filled
371 * in for the transaction. OUT TradeType - integer
372 * representation of generated trade type (as eTradeTypeID enum). OUT
373 * bExecutorIsAccountOwner - whether Trade-Order frame 2 should (FALSE) or
374 * shouldn't (TRUE) be called.
375 *
376 * RETURNS:
377 * none.
378 */
379 void GenerateTradeOrderInput(TTradeOrderTxnInput &TxnReq, INT32 &iTradeType, bool &bExecutorIsAccountOwner);
380
381 /*
382 * Generate Trade-Status transaction input.
383 *
384 * PARAMETERS:
385 * OUT TxnReq - input parameter structure filled
386 * in for the transaction.
387 *
388 * RETURNS:
389 * none.
390 */
391 void GenerateTradeStatusInput(TTradeStatusTxnInput &TxnReq);
392
393 /*
394 * Generate Trade-Update transaction input.
395 *
396 * PARAMETERS:
397 * OUT TxnReq - input parameter structure filled
398 * in for the transaction.
399 *
400 * RETURNS:
401 * none.
402 */
403 void GenerateTradeUpdateInput(TTradeUpdateTxnInput &TxnReq);
404};
405
406} // namespace TPCE
407
408#endif // #ifndef CE_TXN_INPUT_GENERATOR_H
409