thorcommon.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef THORCOMMON_HPP
  14. #define THORCOMMON_HPP
  15. #include "jiface.hpp"
  16. #include "jcrc.hpp"
  17. #include "jlzw.hpp"
  18. #include "jsort.hpp"
  19. #include "jdebug.hpp"
  20. #include "jfile.hpp"
  21. #include "eclhelper.hpp"
  22. #include "thorhelper.hpp"
  23. #include "thorxmlwrite.hpp"
  24. static unsigned const defaultDaliResultOutputMax = 2000; // MB
  25. static unsigned const defaultDaliResultLimit = 10; // MB
  26. static unsigned const defaultMaxCsvRowSize = 10; // MB
  27. #define OPT_OUTPUTLIMIT_LEGACY "outputLimit" // OUTPUT Mb limit (legacy property name, renamed to outputLimitMb in 5.2)
  28. #define OPT_OUTPUTLIMIT "outputLimitMb" // OUTPUT Mb limit (default = 10 [MB])
  29. #define OPT_MAXCSVROWSIZE "maxCsvRowSizeMb" // Upper limit on csv read line size (default = 10 [MB])
  30. class THORHELPER_API CSizingSerializer : implements IRowSerializerTarget
  31. {
  32. size32_t totalsize;
  33. public:
  34. inline CSizingSerializer() { reset(); }
  35. inline void reset() { totalsize = 0; }
  36. inline size32_t size() { return totalsize; }
  37. virtual void put(size32_t len, const void * ptr);
  38. virtual size32_t beginNested(size32_t count);
  39. virtual void endNested(size32_t position);
  40. };
  41. class THORHELPER_API CMemoryRowSerializer: implements IRowSerializerTarget
  42. {
  43. MemoryBuffer & buffer;
  44. unsigned nesting;
  45. public:
  46. inline CMemoryRowSerializer(MemoryBuffer & _buffer)
  47. : buffer(_buffer)
  48. {
  49. nesting = 0;
  50. }
  51. virtual void put(size32_t len, const void * ptr);
  52. virtual size32_t beginNested(size32_t count);
  53. virtual void endNested(size32_t sizePos);
  54. };
  55. // useful package
  56. interface IRowInterfaces: extends IInterface
  57. {
  58. virtual IEngineRowAllocator * queryRowAllocator()=0;
  59. virtual IOutputRowSerializer * queryRowSerializer()=0;
  60. virtual IOutputRowDeserializer * queryRowDeserializer()=0;
  61. virtual IOutputMetaData *queryRowMetaData()=0;
  62. virtual unsigned queryActivityId() const=0;
  63. virtual ICodeContext *queryCodeContext()=0;
  64. };
  65. extern THORHELPER_API void useMemoryMappedRead(bool on);
  66. extern THORHELPER_API IRowInterfaces *createRowInterfaces(IOutputMetaData *meta, unsigned actid, unsigned heapFlags, ICodeContext *context);
  67. enum RowReaderWriterFlags
  68. {
  69. rw_grouped = 0x1,
  70. rw_crc = 0x2,
  71. rw_extend = 0x4,
  72. rw_compress = 0x8,
  73. rw_compressblkcrc = 0x10, // block compression, this sets/checks crc's at block level
  74. rw_fastlz = 0x20, // if rw_compress
  75. rw_autoflush = 0x40,
  76. rw_buffered = 0x80,
  77. rw_lzw = 0x100, // if rw_compress
  78. rw_lz4 = 0x200, // if rw_compress
  79. rw_sparse = 0x400 // NB: mutually exclusive with rw_grouped
  80. };
  81. #define DEFAULT_RWFLAGS (rw_buffered|rw_autoflush|rw_compressblkcrc)
  82. inline bool TestRwFlag(unsigned flags, RowReaderWriterFlags flag) { return 0 != (flags & flag); }
  83. #define COMP_MASK (rw_compress|rw_compressblkcrc|rw_fastlz|rw_lzw|rw_lz4)
  84. #define COMP_TYPE_MASK (rw_fastlz|rw_lzw|rw_lz4)
  85. inline void setCompFlag(const StringBuffer compStr, unsigned &flags)
  86. {
  87. flags &= ~COMP_TYPE_MASK;
  88. if (compStr.length())
  89. {
  90. if (0 == stricmp("FLZ", compStr.str()))
  91. flags |= rw_fastlz;
  92. else if (0 == stricmp("LZ4", compStr.str()))
  93. flags |= rw_lz4;
  94. else // not specifically FLZ or LZ4 so set to LZW (or rowdif)
  95. flags |= rw_lzw;
  96. }
  97. else // default is LZ4
  98. flags |= rw_lz4;
  99. }
  100. inline unsigned getCompMethod(unsigned flags)
  101. {
  102. unsigned compMethod = COMPRESS_METHOD_LZW;
  103. if (TestRwFlag(flags, rw_lzw))
  104. compMethod = COMPRESS_METHOD_LZW;
  105. else if (TestRwFlag(flags, rw_fastlz))
  106. compMethod = COMPRESS_METHOD_FASTLZ;
  107. else if (TestRwFlag(flags, rw_lz4))
  108. compMethod = COMPRESS_METHOD_LZ4;
  109. return compMethod;
  110. }
  111. inline unsigned getCompMethod(const StringBuffer compStr)
  112. {
  113. unsigned compMethod = COMPRESS_METHOD_LZW;
  114. if (compStr.length())
  115. {
  116. if (0 == stricmp("FLZ", compStr.str()))
  117. compMethod = COMPRESS_METHOD_FASTLZ;
  118. else if (0 == stricmp("LZ4", compStr.str()))
  119. compMethod = COMPRESS_METHOD_LZ4;
  120. }
  121. else // default is LZ4
  122. compMethod = COMPRESS_METHOD_LZ4;
  123. return compMethod;
  124. }
  125. interface IExtRowStream: extends IRowStream
  126. {
  127. virtual offset_t getOffset() = 0;
  128. virtual void stop(CRC32 *crcout=NULL) = 0;
  129. virtual const void *prefetchRow(size32_t *sz=NULL) = 0;
  130. virtual void prefetchDone() = 0;
  131. virtual void reinit(offset_t offset,offset_t len,unsigned __int64 maxrows) = 0;
  132. virtual unsigned __int64 getStatistic(StatisticKind kind) = 0;
  133. };
  134. interface IExtRowWriter: extends IRowWriter
  135. {
  136. virtual offset_t getPosition() = 0;
  137. virtual void flush(CRC32 *crcout=NULL) = 0;
  138. };
  139. enum EmptyRowSemantics { ers_forbidden, ers_allow, ers_eogonly };
  140. inline unsigned mapESRToRWFlags(EmptyRowSemantics emptyRowSemantics)
  141. {
  142. switch (emptyRowSemantics)
  143. {
  144. case ers_allow:
  145. return rw_sparse;
  146. case ers_eogonly:
  147. return rw_grouped;
  148. default:
  149. return 0;
  150. }
  151. }
  152. inline EmptyRowSemantics extractESRFromRWFlags(unsigned rwFlags)
  153. {
  154. if (TestRwFlag(rwFlags, rw_sparse))
  155. return ers_allow;
  156. else if (TestRwFlag(rwFlags, rw_grouped))
  157. return ers_eogonly;
  158. else
  159. return ers_forbidden;
  160. }
  161. interface IExpander;
  162. extern THORHELPER_API IExtRowStream *createRowStream(IFile *file, IRowInterfaces *rowif, unsigned flags=DEFAULT_RWFLAGS, IExpander *eexp=NULL);
  163. extern THORHELPER_API IExtRowStream *createRowStreamEx(IFile *file, IRowInterfaces *rowif, offset_t offset=0, offset_t len=(offset_t)-1, unsigned __int64 maxrows=(unsigned __int64)-1, unsigned flags=DEFAULT_RWFLAGS, IExpander *eexp=NULL);
  164. interface ICompressor;
  165. extern THORHELPER_API IExtRowWriter *createRowWriter(IFile *file, IRowInterfaces *rowIf, unsigned flags=DEFAULT_RWFLAGS, ICompressor *compressor=NULL, size32_t compressorBlkSz=0);
  166. extern THORHELPER_API IExtRowWriter *createRowWriter(IFileIO *fileIO, IRowInterfaces *rowIf, unsigned flags=DEFAULT_RWFLAGS, size32_t compressorBlkSz=0);
  167. extern THORHELPER_API IExtRowWriter *createRowWriter(IFileIOStream *strm, IRowInterfaces *rowIf, unsigned flags=DEFAULT_RWFLAGS); // strm should be unbuffered
  168. interface THORHELPER_API IDiskMerger : extends IInterface
  169. {
  170. virtual void put(const void **rows, unsigned numrows) = 0;
  171. virtual void putIndirect(const void ***rowptrs, unsigned numrows) = 0; // like put only with an additional dereference, i.e. row i is *(rowptrs[i])
  172. virtual void put(ISortedRowProvider * rows) = 0;
  173. virtual IRowStream *merge(ICompare *icompare,bool partdedup=false) = 0;
  174. virtual count_t mergeTo(IRowWriter *dest,ICompare *icompare,bool partdedup=false) = 0; // alternative to merge
  175. virtual IRowWriter *createWriteBlock() = 0;
  176. };
  177. extern THORHELPER_API IDiskMerger *createDiskMerger(IRowInterfaces *rowInterfaces, IRowLinkCounter *linker, const char *tempnamebase);
  178. #define TIME_ACTIVITIES
  179. class THORHELPER_API ActivityTimeAccumulator
  180. {
  181. friend class ActivityTimer;
  182. public:
  183. ActivityTimeAccumulator()
  184. {
  185. reset();
  186. }
  187. public:
  188. cycle_t startCycles; // Wall clock time of first entry to this activity
  189. cycle_t totalCycles; // Time spent in this activity
  190. cycle_t endCycles; // Wall clock time of last entry to this activity
  191. unsigned __int64 firstRow; // Timestamp of first row (nanoseconds since epoch)
  192. cycle_t firstExitCycles; // Wall clock time of first exit from this activity
  193. // Return the total amount of time (in nanoseconds) spent in this activity (first entry to last exit)
  194. inline unsigned __int64 elapsed() const { return cycle_to_nanosec(endCycles-startCycles); }
  195. // Return the total amount of time (in nanoseconds) spent in the first call of this activity (first entry to first exit)
  196. inline unsigned __int64 latency() const { return cycle_to_nanosec(latencyCycles()); }
  197. inline cycle_t latencyCycles() const { return firstExitCycles-startCycles; }
  198. void addStatistics(IStatisticGatherer & builder) const;
  199. void addStatistics(CRuntimeStatisticCollection & merged) const;
  200. void merge(const ActivityTimeAccumulator & other);
  201. void reset()
  202. {
  203. startCycles = 0;
  204. totalCycles = 0;
  205. endCycles = 0;
  206. firstRow = 0;
  207. firstExitCycles = 0;
  208. }
  209. };
  210. #ifdef TIME_ACTIVITIES
  211. #include "jdebug.hpp"
  212. class ActivityTimer
  213. {
  214. unsigned __int64 startCycles;
  215. ActivityTimeAccumulator &accumulator;
  216. protected:
  217. const bool enabled;
  218. bool isFirstRow;
  219. public:
  220. ActivityTimer(ActivityTimeAccumulator &_accumulator, const bool _enabled)
  221. : accumulator(_accumulator), enabled(_enabled), isFirstRow(false)
  222. {
  223. if (enabled)
  224. {
  225. startCycles = get_cycles_now();
  226. if (!accumulator.firstRow)
  227. {
  228. isFirstRow = true;
  229. accumulator.startCycles = startCycles;
  230. accumulator.firstRow = getTimeStampNowValue();
  231. }
  232. }
  233. else
  234. startCycles = 0;
  235. }
  236. ~ActivityTimer()
  237. {
  238. if (enabled)
  239. {
  240. cycle_t nowCycles = get_cycles_now();
  241. accumulator.endCycles = nowCycles;
  242. cycle_t elapsedCycles = nowCycles - startCycles;
  243. accumulator.totalCycles += elapsedCycles;
  244. if (isFirstRow)
  245. accumulator.firstExitCycles = nowCycles;
  246. }
  247. }
  248. };
  249. class SimpleActivityTimer
  250. {
  251. cycle_t startCycles;
  252. cycle_t &accumulator;
  253. protected:
  254. const bool enabled;
  255. public:
  256. inline SimpleActivityTimer(cycle_t &_accumulator, const bool _enabled)
  257. : accumulator(_accumulator), enabled(_enabled)
  258. {
  259. if (enabled)
  260. startCycles = get_cycles_now();
  261. else
  262. startCycles = 0;
  263. }
  264. inline ~SimpleActivityTimer()
  265. {
  266. if (enabled)
  267. {
  268. cycle_t nowCycles = get_cycles_now();
  269. cycle_t elapsedCycles = nowCycles - startCycles;
  270. accumulator += elapsedCycles;
  271. }
  272. }
  273. };
  274. #else
  275. struct ActivityTimer
  276. {
  277. inline ActivityTimer(ActivityTimeAccumulator &_accumulator, const bool _enabled) { }
  278. };
  279. struct SimpleActivityTimer
  280. {
  281. inline SimpleActivityTimer(unsigned __int64 &_accumulator, const bool _enabled) { }
  282. };
  283. #endif
  284. class THORHELPER_API IndirectCodeContext : implements ICodeContext
  285. {
  286. public:
  287. IndirectCodeContext(ICodeContext * _ctx = NULL) : ctx(_ctx) {}
  288. void set(ICodeContext * _ctx) { ctx = _ctx; }
  289. virtual const char *loadResource(unsigned id)
  290. {
  291. return ctx->loadResource(id);
  292. }
  293. virtual void setResultBool(const char *name, unsigned sequence, bool value)
  294. {
  295. ctx->setResultBool(name, sequence, value);
  296. }
  297. virtual void setResultData(const char *name, unsigned sequence, int len, const void * data)
  298. {
  299. ctx->setResultData(name, sequence, len, data);
  300. }
  301. virtual void setResultDecimal(const char * stepname, unsigned sequence, int len, int precision, bool isSigned, const void *val)
  302. {
  303. ctx->setResultDecimal(stepname, sequence, len, precision, isSigned, val);
  304. }
  305. virtual void setResultInt(const char *name, unsigned sequence, __int64 value, unsigned size)
  306. {
  307. ctx->setResultInt(name, sequence, value, size);
  308. }
  309. virtual void setResultRaw(const char *name, unsigned sequence, int len, const void * data)
  310. {
  311. ctx->setResultRaw(name, sequence, len, data);
  312. }
  313. virtual void setResultReal(const char * stepname, unsigned sequence, double value)
  314. {
  315. ctx->setResultReal(stepname, sequence, value);
  316. }
  317. virtual void setResultSet(const char *name, unsigned sequence, bool isAll, size32_t len, const void * data, ISetToXmlTransformer * transformer)
  318. {
  319. ctx->setResultSet(name, sequence, isAll, len, data, transformer);
  320. }
  321. virtual void setResultString(const char *name, unsigned sequence, int len, const char * str)
  322. {
  323. ctx->setResultString(name, sequence, len, str);
  324. }
  325. virtual void setResultUInt(const char *name, unsigned sequence, unsigned __int64 value, unsigned size)
  326. {
  327. ctx->setResultUInt(name, sequence, value, size);
  328. }
  329. virtual void setResultUnicode(const char *name, unsigned sequence, int len, UChar const * str)
  330. {
  331. ctx->setResultUnicode(name, sequence, len, str);
  332. }
  333. virtual void setResultVarString(const char * name, unsigned sequence, const char * value)
  334. {
  335. ctx->setResultVarString(name, sequence, value);
  336. }
  337. virtual void setResultVarUnicode(const char * name, unsigned sequence, UChar const * value)
  338. {
  339. ctx->setResultVarUnicode(name, sequence, value);
  340. }
  341. virtual bool getResultBool(const char * name, unsigned sequence)
  342. {
  343. return ctx->getResultBool(name, sequence);
  344. }
  345. virtual void getResultData(unsigned & tlen, void * & tgt, const char * name, unsigned sequence)
  346. {
  347. ctx->getResultData(tlen, tgt, name, sequence);
  348. }
  349. virtual void getResultDecimal(unsigned tlen, int precision, bool isSigned, void * tgt, const char * stepname, unsigned sequence)
  350. {
  351. ctx->getResultDecimal(tlen, precision, isSigned, tgt, stepname, sequence);
  352. }
  353. virtual void getResultRaw(unsigned & tlen, void * & tgt, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer)
  354. {
  355. ctx->getResultRaw(tlen, tgt, name, sequence, xmlTransformer, csvTransformer);
  356. }
  357. virtual void getResultSet(bool & isAll, size32_t & tlen, void * & tgt, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer)
  358. {
  359. ctx->getResultSet(isAll, tlen, tgt, name, sequence, xmlTransformer, csvTransformer);
  360. }
  361. virtual __int64 getResultInt(const char * name, unsigned sequence)
  362. {
  363. return ctx->getResultInt(name, sequence);
  364. }
  365. virtual double getResultReal(const char * name, unsigned sequence)
  366. {
  367. return ctx->getResultReal(name, sequence);
  368. }
  369. virtual void getResultString(unsigned & tlen, char * & tgt, const char * name, unsigned sequence)
  370. {
  371. ctx->getResultString(tlen, tgt, name, sequence);
  372. }
  373. virtual void getResultStringF(unsigned tlen, char * tgt, const char * name, unsigned sequence)
  374. {
  375. ctx->getResultStringF(tlen, tgt, name, sequence);
  376. }
  377. virtual void getResultUnicode(unsigned & tlen, UChar * & tgt, const char * name, unsigned sequence)
  378. {
  379. ctx->getResultUnicode(tlen, tgt, name, sequence);
  380. }
  381. virtual char *getResultVarString(const char * name, unsigned sequence)
  382. {
  383. return ctx->getResultVarString(name, sequence);
  384. }
  385. virtual UChar *getResultVarUnicode(const char * name, unsigned sequence)
  386. {
  387. return ctx->getResultVarUnicode(name, sequence);
  388. }
  389. virtual unsigned getResultHash(const char * name, unsigned sequence)
  390. {
  391. return ctx->getResultHash(name, sequence);
  392. }
  393. virtual unsigned getExternalResultHash(const char * wuid, const char * name, unsigned sequence)
  394. {
  395. return ctx->getExternalResultHash(wuid, name, sequence);
  396. }
  397. virtual char *getWuid()
  398. {
  399. return ctx->getWuid();
  400. }
  401. virtual void getExternalResultRaw(unsigned & tlen, void * & tgt, const char * wuid, const char * stepname, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer)
  402. {
  403. ctx->getExternalResultRaw(tlen, tgt, wuid, stepname, sequence, xmlTransformer, csvTransformer);
  404. }
  405. virtual void executeGraph(const char * graphName, bool realThor, size32_t parentExtractSize, const void * parentExtract)
  406. {
  407. ctx->executeGraph(graphName, realThor, parentExtractSize, parentExtract);
  408. }
  409. virtual char * getExpandLogicalName(const char * logicalName)
  410. {
  411. return ctx->getExpandLogicalName(logicalName);
  412. }
  413. virtual void addWuException(const char * text, unsigned code, unsigned severity, const char *source)
  414. {
  415. ctx->addWuException(text, code, severity, source);
  416. }
  417. virtual void addWuAssertFailure(unsigned code, const char * text, const char * filename, unsigned lineno, unsigned column, bool isAbort)
  418. {
  419. ctx->addWuAssertFailure(code, text, filename, lineno, column, isAbort);
  420. }
  421. virtual IUserDescriptor *queryUserDescriptor()
  422. {
  423. return ctx->queryUserDescriptor();
  424. }
  425. virtual IThorChildGraph * resolveChildQuery(__int64 activityId, IHThorArg * colocal)
  426. {
  427. return ctx->resolveChildQuery(activityId, colocal);
  428. }
  429. virtual unsigned __int64 getDatasetHash(const char * name, unsigned __int64 hash)
  430. {
  431. return ctx->getDatasetHash(name, hash);
  432. }
  433. virtual unsigned getNodes()
  434. {
  435. return ctx->getNodes();
  436. }
  437. virtual unsigned getNodeNum()
  438. {
  439. return ctx->getNodeNum();
  440. }
  441. virtual char *getFilePart(const char *logicalPart, bool create)
  442. {
  443. return ctx->getFilePart(logicalPart, create);
  444. }
  445. virtual unsigned __int64 getFileOffset(const char *logicalPart)
  446. {
  447. return ctx->getFileOffset(logicalPart);
  448. }
  449. virtual IDistributedFileTransaction *querySuperFileTransaction()
  450. {
  451. return ctx->querySuperFileTransaction();
  452. }
  453. virtual char *getEnv(const char *name, const char *defaultValue) const
  454. {
  455. return ctx->getEnv(name, defaultValue);
  456. }
  457. virtual char *getJobName()
  458. {
  459. return ctx->getJobName();
  460. }
  461. virtual char *getJobOwner()
  462. {
  463. return ctx->getJobOwner();
  464. }
  465. virtual char *getClusterName()
  466. {
  467. return ctx->getClusterName();
  468. }
  469. virtual char *getGroupName()
  470. {
  471. return ctx->getGroupName();
  472. }
  473. virtual char * queryIndexMetaData(char const * lfn, char const * xpath)
  474. {
  475. return ctx->queryIndexMetaData(lfn, xpath);
  476. }
  477. virtual unsigned getPriority() const
  478. {
  479. return ctx->getPriority();
  480. }
  481. virtual char *getPlatform()
  482. {
  483. return ctx->getPlatform();
  484. }
  485. virtual char *getOS()
  486. {
  487. return ctx->getOS();
  488. }
  489. virtual IEclGraphResults * resolveLocalQuery(__int64 activityId)
  490. {
  491. return ctx->resolveLocalQuery(activityId);
  492. }
  493. virtual char *getEnv(const char *name, const char *defaultValue)
  494. {
  495. return ctx->getEnv(name, defaultValue);
  496. }
  497. virtual unsigned logString(const char *text) const
  498. {
  499. return ctx->logString(text);
  500. }
  501. virtual const IContextLogger &queryContextLogger() const
  502. {
  503. return ctx->queryContextLogger();
  504. }
  505. virtual IDebuggableContext *queryDebugContext() const
  506. {
  507. return ctx->queryDebugContext();
  508. }
  509. virtual IEngineRowAllocator * getRowAllocator(IOutputMetaData * meta, unsigned activityId) const
  510. {
  511. return ctx->getRowAllocator(meta, activityId);
  512. }
  513. virtual IEngineRowAllocator * getRowAllocatorEx(IOutputMetaData * meta, unsigned activityId, unsigned heapFlags) const
  514. {
  515. return ctx->getRowAllocatorEx(meta, activityId, heapFlags);
  516. }
  517. virtual const char *cloneVString(const char *str) const
  518. {
  519. return ctx->cloneVString(str);
  520. }
  521. virtual const char *cloneVString(size32_t len, const char *str) const
  522. {
  523. return ctx->cloneVString(len, str);
  524. }
  525. virtual void getResultRowset(size32_t & tcount, const byte * * & tgt, const char * name, unsigned sequence, IEngineRowAllocator * _rowAllocator, bool isGrouped, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer) override
  526. {
  527. ctx->getResultRowset(tcount, tgt, name, sequence, _rowAllocator, isGrouped, xmlTransformer, csvTransformer);
  528. }
  529. virtual void getResultDictionary(size32_t & tcount, const byte * * & tgt, IEngineRowAllocator * _rowAllocator, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer, IHThorHashLookupInfo * hasher) override
  530. {
  531. ctx->getResultDictionary(tcount, tgt, _rowAllocator, name, sequence, xmlTransformer, csvTransformer, hasher);
  532. }
  533. virtual void getRowXML(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  534. {
  535. convertRowToXML(lenResult, result, info, row, flags);
  536. }
  537. virtual void getRowJSON(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  538. {
  539. convertRowToJSON(lenResult, result, info, row, flags);
  540. }
  541. virtual const void * fromXml(IEngineRowAllocator * _rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  542. {
  543. return ctx->fromXml(_rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  544. }
  545. virtual const void * fromJson(IEngineRowAllocator * _rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  546. {
  547. return ctx->fromJson(_rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  548. }
  549. virtual IEngineContext *queryEngineContext()
  550. {
  551. return ctx->queryEngineContext();
  552. }
  553. virtual char *getDaliServers()
  554. {
  555. return ctx->getDaliServers();
  556. }
  557. virtual IWorkUnit *updateWorkUnit() const
  558. {
  559. return ctx->updateWorkUnit();
  560. }
  561. virtual ISectionTimer * registerTimer(unsigned activityId, const char * name)
  562. {
  563. return ctx->registerTimer(activityId, name);
  564. }
  565. virtual unsigned getGraphLoopCounter() const override
  566. {
  567. return ctx->getGraphLoopCounter();
  568. }
  569. protected:
  570. ICodeContext * ctx;
  571. };
  572. extern THORHELPER_API bool isActivitySink(ThorActivityKind kind);
  573. extern THORHELPER_API bool isActivitySource(ThorActivityKind kind);
  574. extern THORHELPER_API const char * getActivityText(ThorActivityKind kind);
  575. extern THORHELPER_API void setProcessAffinity(const char * cpus);
  576. extern THORHELPER_API void setAutoAffinity(unsigned curProcess, unsigned processPerNode, const char * optNodes);
  577. extern THORHELPER_API void bindMemoryToLocalNodes();
  578. extern THORHELPER_API IOutputMetaData *getDaliLayoutInfo(IPropertyTree const &props);
  579. #endif // THORHELPER_HPP