Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1040 lines
28 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: wkspace.cpp
  6. //
  7. // Contents: DB workspace
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. #include "TLSdef.h"
  14. #include "server.h"
  15. #include "wkspace.h"
  16. #include "utils.h"
  17. #include "globals.h"
  18. /////////////////////////////////////////////////////////////
  19. //
  20. // Try to save some memory
  21. //
  22. //
  23. JBInstance __TlsDbWorkSpace::g_JbInstance;
  24. static TLSDbWorkSpacePool g_WorkSpacePool;
  25. typedef map<PVOID, PVOID> ACQUIREDHANDLELIST;
  26. CCriticalSection AcquiredHandleListLock;
  27. ACQUIREDHANDLELIST AcquiredHandleList;
  28. LONG g_lWorkSpacePoolDeleted = 0;
  29. #if DBG
  30. DWORD g_dwNumWorkSpaceAllocated = 0;
  31. #endif
  32. //-----------------------------------------------
  33. //
  34. // Table for work item storage,
  35. //
  36. //
  37. JBSession g_WkItemSession(__TlsDbWorkSpace::g_JbInstance);
  38. JBDatabase g_WkItemDatabase(g_WkItemSession);
  39. WorkItemTable g_WkItemTable(g_WkItemDatabase);
  40. //--------------------------------------------------------
  41. BOOL
  42. TLSGetESEError(
  43. const JET_ERR jetErrCode,
  44. LPTSTR* pszString
  45. )
  46. /*++
  47. --*/
  48. {
  49. JBError jbError;
  50. return jbError.GetJBErrString(
  51. jetErrCode,
  52. pszString
  53. );
  54. }
  55. //--------------------------------------------------------
  56. WorkItemTable*
  57. GetWorkItemStorageTable()
  58. {
  59. BOOL bSuccess = TRUE;
  60. //
  61. // verify session and database is correct.
  62. //
  63. if(g_WkItemSession.IsValid() == FALSE)
  64. {
  65. SetLastError(ERROR_INVALID_PARAMETER);
  66. return NULL;
  67. }
  68. if(g_WkItemDatabase.IsValid() == FALSE)
  69. {
  70. SetLastError(ERROR_INVALID_PARAMETER);
  71. return NULL;
  72. }
  73. if(g_WkItemTable.IsValid() == FALSE)
  74. {
  75. bSuccess = g_WkItemTable.OpenTable(
  76. TRUE,
  77. JET_bitTableUpdatable
  78. );
  79. if(bSuccess == FALSE)
  80. {
  81. LPTSTR pString = NULL;
  82. SetLastError(SET_JB_ERROR(g_WkItemTable.GetLastJetError()));
  83. TLSGetESEError(g_WkItemTable.GetLastJetError(), &pString);
  84. TLSLogEvent(
  85. EVENTLOG_ERROR_TYPE,
  86. TLS_E_SERVICEINIT,
  87. TLS_E_JB_OPENTABLE,
  88. g_WkItemTable.GetTableName(),
  89. g_WkItemTable.GetLastJetError(),
  90. (pString != NULL) ? pString : _TEXT("")
  91. );
  92. if(pString != NULL)
  93. {
  94. LocalFree(pString);
  95. }
  96. }
  97. }
  98. return (bSuccess == TRUE) ? &g_WkItemTable : NULL;
  99. }
  100. //--------------------------------------------------------
  101. DWORD
  102. CloseWorkSpacePool()
  103. {
  104. DWORD dwNumWkSpace = g_WorkSpacePool.GetNumberAvailable();
  105. TLSDbWorkSpace* jbWkSpace=NULL;
  106. DWORD dwErrCode=ERROR_SUCCESS;
  107. //
  108. // Mark workspace pool deleted, this is for backup/restore
  109. // that it will close entire workspace pool but RPC context
  110. // rundown might happen after we close the workspace pool
  111. //
  112. InterlockedExchange(
  113. &g_lWorkSpacePoolDeleted,
  114. 1
  115. );
  116. #if DBG
  117. DBGPrintf(
  118. DBG_INFORMATION,
  119. DBG_FACILITY_HANDLEPOOL,
  120. DBGLEVEL_FUNCTION_TRACE,
  121. _TEXT("CloseWorkSpace() - Total %d, Num Available %d\n"),
  122. g_dwNumWorkSpaceAllocated,
  123. dwNumWkSpace
  124. );
  125. #endif
  126. while(dwNumWkSpace)
  127. {
  128. jbWkSpace = NULL;
  129. dwErrCode=g_WorkSpacePool.AcquireHandle(
  130. &jbWkSpace,
  131. INFINITE
  132. );
  133. if(jbWkSpace)
  134. delete jbWkSpace;
  135. dwNumWkSpace--;
  136. #if DBG
  137. g_dwNumWorkSpaceAllocated--;
  138. #endif
  139. }
  140. AcquiredHandleListLock.Lock();
  141. if(AcquiredHandleList.empty() != TRUE)
  142. {
  143. ACQUIREDHANDLELIST::iterator it;
  144. for(it = AcquiredHandleList.begin(); it != AcquiredHandleList.end(); it++)
  145. {
  146. if((*it).second != NULL)
  147. {
  148. jbWkSpace = (TLSDbWorkSpace*) (*it).second;
  149. delete jbWkSpace;
  150. #if DBG
  151. g_dwNumWorkSpaceAllocated--;
  152. DBGPrintf(
  153. DBG_INFORMATION,
  154. DBG_FACILITY_HANDLEPOOL,
  155. DBGLEVEL_FUNCTION_TRACE,
  156. _TEXT("Close Allocated WorkSpace()...\n")
  157. );
  158. #endif
  159. }
  160. else
  161. {
  162. TLSASSERT(FALSE);
  163. }
  164. }
  165. AcquiredHandleList.erase(AcquiredHandleList.begin(), AcquiredHandleList.end());
  166. }
  167. AcquiredHandleListLock.UnLock();
  168. g_WkItemTable.CloseTable();
  169. g_WkItemDatabase.CloseDatabase();
  170. g_WkItemSession.EndSession();
  171. #if DBG
  172. if( 0 != g_dwNumWorkSpaceAllocated )
  173. {
  174. TLSASSERT(FALSE);
  175. }
  176. #endif
  177. //
  178. // Delete log file so that to prevent long database recovery
  179. //
  180. __TlsDbWorkSpace::g_JbInstance.JBTerminate(
  181. JET_bitTermComplete,
  182. TRUE
  183. );
  184. return ERROR_SUCCESS;
  185. }
  186. //--------------------------------------------------------
  187. BOOL
  188. IsValidAllocatedWorkspace(
  189. PTLSDbWorkSpace p
  190. )
  191. /*++
  192. Abstract:
  193. Verify an allocated workspace handle is in our
  194. allocated list.
  195. --*/
  196. {
  197. BOOL bSuccess = TRUE;
  198. ACQUIREDHANDLELIST::iterator it;
  199. AcquiredHandleListLock.Lock();
  200. it = AcquiredHandleList.find(p);
  201. bSuccess = (it != AcquiredHandleList.end());
  202. AcquiredHandleListLock.UnLock();
  203. return bSuccess;
  204. }
  205. //--------------------------------------------------------
  206. void
  207. ReleaseWorkSpace(
  208. PTLSDbWorkSpace *p
  209. )
  210. /*
  211. */
  212. {
  213. if( g_lWorkSpacePoolDeleted == 1 )
  214. {
  215. //
  216. // DB workspace pool has been deleted, acquired workspace
  217. // handle will be deleted via AcquireHandleList
  218. //
  219. // overactive assert here... there is a race condition possible,
  220. // this assert is to verify that this if statement handles it.
  221. TLSASSERT(FALSE);
  222. return;
  223. }
  224. TLSASSERT(p != NULL && *p != NULL);
  225. if(p != NULL)
  226. {
  227. ACQUIREDHANDLELIST::iterator it;
  228. AcquiredHandleListLock.Lock();
  229. it = AcquiredHandleList.find(*p);
  230. if(it != AcquiredHandleList.end())
  231. {
  232. AcquiredHandleList.erase(it);
  233. }
  234. else
  235. {
  236. TLSASSERT(FALSE);
  237. }
  238. AcquiredHandleListLock.UnLock();
  239. }
  240. if(p)
  241. {
  242. DBGPrintf(
  243. DBG_INFORMATION,
  244. DBG_FACILITY_HANDLEPOOL,
  245. DBGLEVEL_FUNCTION_TRACE,
  246. _TEXT("Releasing workspace 0x%08x...\n"),
  247. *p
  248. );
  249. if(*p)
  250. {
  251. (*p)->Cleanup();
  252. g_WorkSpacePool.ReleaseHandle(*p);
  253. *p = NULL;
  254. }
  255. }
  256. }
  257. //--------------------------------------------------------
  258. TLSDbWorkSpace*
  259. AllocateWorkSpace(
  260. DWORD dwWaitTime /* INFINITE */
  261. )
  262. /*
  263. */
  264. {
  265. TLSDbWorkSpace* jbWkSpace=NULL;
  266. BOOL bSuccess;
  267. DBGPrintf(
  268. DBG_INFORMATION,
  269. DBG_FACILITY_HANDLEPOOL,
  270. DBGLEVEL_FUNCTION_TRACE,
  271. _TEXT("Allocating a workspace...\n")
  272. );
  273. bSuccess = g_WorkSpacePool.AcquireHandleEx(
  274. GetServiceShutdownHandle(),
  275. &jbWkSpace,
  276. dwWaitTime
  277. );
  278. if(bSuccess == TRUE)
  279. {
  280. DBGPrintf(
  281. DBG_INFORMATION,
  282. DBG_FACILITY_HANDLEPOOL,
  283. DBGLEVEL_FUNCTION_TRACE,
  284. _TEXT("Allocated 0x%08x...\n"),
  285. jbWkSpace
  286. );
  287. AcquiredHandleListLock.Lock();
  288. AcquiredHandleList[jbWkSpace] = jbWkSpace;
  289. AcquiredHandleListLock.UnLock();
  290. }
  291. else
  292. {
  293. DBGPrintf(
  294. DBG_INFORMATION,
  295. DBG_FACILITY_HANDLEPOOL,
  296. DBGLEVEL_FUNCTION_TRACE,
  297. _TEXT("Can't allocate workspace - %d are in use...\n"),
  298. AcquiredHandleList.size()
  299. );
  300. }
  301. return jbWkSpace;
  302. }
  303. //--------------------------------------------------------
  304. DWORD
  305. GetNumberOfWorkSpaceHandle()
  306. {
  307. return g_WorkSpacePool.GetNumberAvailable();
  308. }
  309. //--------------------------------------------------------
  310. BOOL
  311. TLSJbInitDatabaseEngine(
  312. IN JBSession& jbSession,
  313. IN JBDatabase& jbDatabase,
  314. IN LPCTSTR szDatabaseFile,
  315. IN LPCTSTR szUserName,
  316. IN LPCTSTR szPassword
  317. )
  318. /*++
  319. --*/
  320. {
  321. BOOL bSuccess = TRUE;
  322. DWORD dwErrCode;
  323. if(jbSession.IsValid() == FALSE)
  324. {
  325. bSuccess = jbSession.BeginSession(
  326. szUserName,
  327. szPassword
  328. );
  329. if(bSuccess == FALSE)
  330. {
  331. LPTSTR pString = NULL;
  332. TLSGetESEError(jbSession.GetLastJetError(), &pString);
  333. TLSLogEvent(
  334. EVENTLOG_ERROR_TYPE,
  335. TLS_E_DBGENERAL,
  336. TLS_E_JB_BEGINSESSION,
  337. jbSession.GetLastJetError(),
  338. (pString != NULL) ? pString : _TEXT("")
  339. );
  340. if(pString != NULL)
  341. {
  342. LocalFree(pString);
  343. }
  344. DBGPrintf(
  345. DBG_ERROR,
  346. DBG_FACILITY_JETBLUE,
  347. DBGLEVEL_FUNCTION_ERROR,
  348. _TEXT("Error : Initialize JetBlue session - error code %d\n"),
  349. jbSession.GetLastJetError()
  350. );
  351. dwErrCode = SET_JB_ERROR(jbSession.GetLastJetError());
  352. SetLastError(dwErrCode);
  353. TLSASSERT(FALSE);
  354. goto cleanup;
  355. }
  356. }
  357. //
  358. // Open Database
  359. if(jbDatabase.IsValid() == FALSE)
  360. {
  361. bSuccess = jbDatabase.OpenDatabase(szDatabaseFile);
  362. if(bSuccess == FALSE)
  363. {
  364. JET_ERR errCode = jbDatabase.GetLastJetError();
  365. if(errCode != JET_errFileNotFound)
  366. {
  367. if(errCode == JET_errDatabaseCorrupted)
  368. {
  369. TLSLogErrorEvent(TLS_E_CORRUPT_DATABASE);
  370. }
  371. else
  372. {
  373. LPTSTR pString = NULL;
  374. TLSGetESEError(errCode, &pString);
  375. //
  376. // other type of error
  377. //
  378. TLSLogEvent(
  379. EVENTLOG_ERROR_TYPE,
  380. TLS_E_DBGENERAL,
  381. TLS_E_JB_OPENDATABASE,
  382. szDatabaseFile,
  383. errCode,
  384. (pString != NULL) ? pString : _TEXT("")
  385. );
  386. if(pString != NULL)
  387. {
  388. LocalFree(pString);
  389. }
  390. }
  391. DBGPrintf(
  392. DBG_ERROR,
  393. DBG_FACILITY_JETBLUE,
  394. DBGLEVEL_FUNCTION_ERROR,
  395. _TEXT("Error : Can't create database because OpenDatabase failed with %d\n"),
  396. errCode
  397. );
  398. dwErrCode = SET_JB_ERROR(errCode);
  399. SetLastError(dwErrCode);
  400. TLSASSERT(FALSE);
  401. return FALSE;
  402. }
  403. // create a new database file
  404. bSuccess = jbDatabase.CreateDatabase(szDatabaseFile);
  405. if(bSuccess == FALSE)
  406. {
  407. LPTSTR pString = NULL;
  408. TLSGetESEError(jbDatabase.GetLastJetError(), &pString);
  409. TLSLogEvent(
  410. EVENTLOG_ERROR_TYPE,
  411. TLS_E_DBGENERAL,
  412. TLS_E_JB_CREATEDATABASE,
  413. szDatabaseFile,
  414. jbDatabase.GetLastJetError(),
  415. (pString != NULL) ? pString : _TEXT("")
  416. );
  417. if(pString != NULL)
  418. {
  419. LocalFree(pString);
  420. }
  421. DBGPrintf(
  422. DBG_ERROR,
  423. DBG_FACILITY_JETBLUE,
  424. DBGLEVEL_FUNCTION_ERROR,
  425. _TEXT("Error : can't create new database - error code %d\n"),
  426. jbDatabase.GetLastJetError()
  427. );
  428. dwErrCode = SET_JB_ERROR(jbDatabase.GetLastJetError());
  429. SetLastError(dwErrCode);
  430. }
  431. }
  432. }
  433. cleanup:
  434. return bSuccess;
  435. }
  436. //--------------------------------------------------------
  437. BOOL
  438. InitializeWorkSpacePool(
  439. IN int num_workspace,
  440. IN LPCTSTR szDatabaseFile,
  441. IN LPCTSTR szUserName,
  442. IN LPCTSTR szPassword,
  443. IN LPCTSTR szChkPointDirPath,
  444. IN LPCTSTR szTempDirPath,
  445. IN LPCTSTR szLogDirPath,
  446. IN BOOL bUpdatable
  447. )
  448. /*
  449. */
  450. {
  451. DWORD dwErrCode=ERROR_SUCCESS;
  452. int index=0;
  453. BOOL bSuccess=TRUE;
  454. BOOL bWkItemSuccess = TRUE;
  455. DBGPrintf(
  456. DBG_ERROR,
  457. DBG_FACILITY_JETBLUE,
  458. DBGLEVEL_FUNCTION_ERROR,
  459. _TEXT("InitializeWorkSpacePool()... %d\n"),
  460. num_workspace
  461. );
  462. if(__TlsDbWorkSpace::g_JbInstance.IsValid() == FALSE)
  463. {
  464. bSuccess = TLSJbInstanceInit(
  465. __TlsDbWorkSpace::g_JbInstance,
  466. szChkPointDirPath,
  467. szTempDirPath,
  468. szLogDirPath
  469. );
  470. if(bSuccess != TRUE)
  471. {
  472. TLSASSERT(FALSE);
  473. goto cleanup;
  474. }
  475. }
  476. if(g_WkItemTable.IsValid() == FALSE)
  477. {
  478. //
  479. // Initialize session for WorkItemTable, critical
  480. // error if this failed
  481. //
  482. bWkItemSuccess = TLSJbInitDatabaseEngine(
  483. g_WkItemSession,
  484. g_WkItemDatabase,
  485. szDatabaseFile,
  486. szUserName,
  487. szPassword
  488. );
  489. if(bWkItemSuccess == FALSE)
  490. {
  491. TLSASSERT(FALSE);
  492. goto cleanup;
  493. }
  494. }
  495. //
  496. // Allocate number of workspace
  497. //
  498. for(index=0; index < num_workspace; index++)
  499. {
  500. PTLSDbWorkSpace pJbWkSpace=NULL;
  501. pJbWkSpace = new TLSDbWorkSpace();
  502. if(pJbWkSpace == NULL)
  503. {
  504. break;
  505. }
  506. if(pJbWkSpace->InitWorkSpace(
  507. TRUE,
  508. szDatabaseFile,
  509. szUserName,
  510. szPassword,
  511. NULL,
  512. NULL,
  513. bUpdatable) == FALSE)
  514. {
  515. delete pJbWkSpace;
  516. break;
  517. }
  518. g_WorkSpacePool.ReleaseHandle(pJbWkSpace);
  519. #if DBG
  520. g_dwNumWorkSpaceAllocated++;
  521. #endif
  522. }
  523. //
  524. // WorkSpace pool has been initialized
  525. //
  526. InterlockedExchange(
  527. &g_lWorkSpacePoolDeleted,
  528. 0
  529. );
  530. cleanup:
  531. if(bWkItemSuccess == FALSE)
  532. {
  533. // critical error, can't initialize session for workitem table.
  534. SetLastError(TLS_E_INIT_WORKSPACE);
  535. return FALSE;
  536. }
  537. //
  538. // We need at least 3 workspace, one for update/insert
  539. // and two for enumeration
  540. //
  541. if(index < num_workspace)
  542. {
  543. SetLastError(TLS_E_INIT_WORKSPACE);
  544. }
  545. return index >= num_workspace;
  546. }
  547. //--------------------------------------------------------
  548. //
  549. // Initialize DB workspace...
  550. //
  551. //--------------------------------------------------------
  552. BOOL
  553. TLSJbInstanceInit(
  554. IN OUT JBInstance& jbInstance,
  555. IN LPCTSTR szChkPointDirPath,
  556. IN LPCTSTR szTempDirPath,
  557. IN LPCTSTR szLogDirPath
  558. )
  559. /*
  560. */
  561. {
  562. //
  563. // Setup system parameters
  564. //
  565. BOOL bSuccess=TRUE;
  566. DWORD dwErrCode;
  567. if(jbInstance.IsValid() == TRUE)
  568. {
  569. jbInstance.SetLastJetError(JET_errAlreadyInitialized);
  570. goto cleanup;
  571. }
  572. //
  573. // Set JetBlue parameter and initialize it
  574. //
  575. if(szChkPointDirPath != NULL)
  576. {
  577. bSuccess = jbInstance.SetSystemParameter(
  578. 0,
  579. JET_paramSystemPath,
  580. 0,
  581. (unsigned char *)szChkPointDirPath
  582. );
  583. if(bSuccess == FALSE)
  584. {
  585. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  586. SetLastError(dwErrCode);
  587. goto cleanup;
  588. }
  589. }
  590. if(szTempDirPath != NULL)
  591. {
  592. bSuccess = jbInstance.SetSystemParameter(
  593. 0,
  594. JET_paramTempPath,
  595. 0,
  596. (unsigned char *)szTempDirPath
  597. );
  598. if(bSuccess == FALSE)
  599. {
  600. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  601. SetLastError(dwErrCode);
  602. goto cleanup;
  603. }
  604. }
  605. if(szLogDirPath != NULL)
  606. {
  607. bSuccess = jbInstance.SetSystemParameter(
  608. 0,
  609. JET_paramLogFilePath,
  610. 0,
  611. (unsigned char *)szLogDirPath
  612. );
  613. if(bSuccess == FALSE)
  614. {
  615. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  616. SetLastError(dwErrCode);
  617. goto cleanup;
  618. }
  619. }
  620. if( g_EsentMaxCacheSize != LSERVER_PARAMETERS_USE_ESENTDEFAULT )
  621. {
  622. //
  623. // Adjust memory usage, ESENT will failed on invalid parameter
  624. //
  625. bSuccess = jbInstance.SetSystemParameter(
  626. 0,
  627. JET_paramCacheSizeMax,
  628. g_EsentMaxCacheSize,
  629. NULL
  630. );
  631. if(bSuccess == TRUE)
  632. {
  633. bSuccess = jbInstance.SetSystemParameter(
  634. 0,
  635. JET_paramStartFlushThreshold,
  636. g_EsentStartFlushThreshold,
  637. NULL
  638. );
  639. if( bSuccess == TRUE )
  640. {
  641. bSuccess = jbInstance.SetSystemParameter(
  642. 0,
  643. JET_paramStopFlushThreshold,
  644. g_EsentStopFlushThreadhold,
  645. NULL
  646. );
  647. }
  648. }
  649. #if DBG
  650. //
  651. // check build, assert.
  652. //
  653. if(bSuccess == FALSE)
  654. {
  655. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  656. TLSASSERT(FALSE);
  657. }
  658. #endif
  659. }
  660. //
  661. // The max. number of buffers to store old version of a record
  662. // (snapshot at the start of a transaction) Each version store is 16k
  663. // bytes. A version store stores structures that hold information
  664. // derived from a snapshot of the database prior to an insert (20 bytes
  665. // roughly) or update (size of the record + 20 bytes).
  666. //
  667. if( g_EsentMaxVerPages != LSERVER_PARAMETERS_USE_ESENTDEFAULT )
  668. {
  669. bSuccess = jbInstance.SetSystemParameter(
  670. 0,
  671. JET_paramMaxVerPages,
  672. g_EsentMaxVerPages,
  673. NULL
  674. );
  675. if(bSuccess == FALSE)
  676. {
  677. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  678. SetLastError(dwErrCode);
  679. goto cleanup;
  680. }
  681. }
  682. bSuccess = jbInstance.SetSystemParameter( 0, JET_paramDeleteOutOfRangeLogs, 1, NULL);
  683. if(bSuccess == FALSE)
  684. {
  685. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  686. SetLastError(dwErrCode);
  687. goto cleanup;
  688. }
  689. //
  690. // Don't let JET logs build up on the disk
  691. //
  692. bSuccess = jbInstance.SetSystemParameter( 0, JET_paramCircularLog, 1, NULL);
  693. if(bSuccess == FALSE)
  694. {
  695. dwErrCode = SET_JB_ERROR(jbInstance.GetLastJetError());
  696. SetLastError(dwErrCode);
  697. goto cleanup;
  698. }
  699. //
  700. // We only use single instance for all the work space.
  701. //
  702. if(jbInstance.JBInitJetInstance() == FALSE)
  703. {
  704. LPTSTR pString = NULL;
  705. TLSGetESEError(jbInstance.GetLastJetError(), &pString);
  706. TLSLogEvent(
  707. EVENTLOG_ERROR_TYPE,
  708. TLS_E_DBGENERAL,
  709. TLS_E_INIT_JETBLUE,
  710. jbInstance.GetLastJetError(),
  711. (pString != NULL) ? pString : _TEXT("")
  712. );
  713. if(pString != NULL)
  714. {
  715. LocalFree(pString);
  716. }
  717. DBGPrintf(
  718. DBG_ERROR,
  719. DBG_FACILITY_JETBLUE,
  720. DBGLEVEL_FUNCTION_ERROR,
  721. _TEXT("Init. JetBlue Instance return error code %d\n"),
  722. jbInstance.GetLastJetError()
  723. );
  724. SetLastError(SET_JB_ERROR(jbInstance.GetLastJetError()));
  725. }
  726. cleanup:
  727. return jbInstance.IsSuccess();
  728. }
  729. //--------------------------------------------------------
  730. //
  731. // TLSDbWorkSpace implementation
  732. //
  733. //--------------------------------------------------------
  734. BOOL
  735. __TlsDbWorkSpace::InitWorkSpace(
  736. BOOL bCreateIfNotExist,
  737. LPCTSTR szDatabaseFile,
  738. LPCTSTR szUserName,
  739. LPCTSTR szPassword,
  740. IN LPCTSTR szChkPointDirPath,
  741. IN LPCTSTR szTempDirPath,
  742. IN BOOL bUpdatable
  743. )
  744. /*
  745. */
  746. {
  747. BOOL bSuccess;
  748. DWORD dwErrCode;
  749. //
  750. // Initialize JetBlue Instance
  751. if(g_JbInstance.IsValid() == FALSE)
  752. {
  753. SetLastError(TLS_E_INTERNAL);
  754. bSuccess = FALSE;
  755. goto cleanup;
  756. }
  757. DBGPrintf(
  758. DBG_ERROR,
  759. DBG_FACILITY_JETBLUE,
  760. DBGLEVEL_FUNCTION_ERROR,
  761. _TEXT("InitWorkSpace()...\n")
  762. );
  763. bSuccess = TLSJbInitDatabaseEngine(
  764. m_JetSession,
  765. m_JetDatabase,
  766. szDatabaseFile,
  767. szUserName,
  768. szPassword
  769. );
  770. if(bSuccess == FALSE)
  771. {
  772. goto cleanup;
  773. }
  774. //
  775. // Open all table we need
  776. //
  777. bSuccess = m_LicPackTable.OpenTable(
  778. TRUE,
  779. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  780. );
  781. if(bSuccess == FALSE)
  782. {
  783. SetLastError(SET_JB_ERROR(m_LicPackTable.GetLastJetError()));
  784. LPTSTR pString = NULL;
  785. TLSGetESEError(m_LicPackTable.GetLastJetError(), &pString);
  786. TLSLogEvent(
  787. EVENTLOG_ERROR_TYPE,
  788. TLS_E_DBGENERAL,
  789. TLS_E_JB_OPENTABLE,
  790. m_LicPackTable.GetTableName(),
  791. m_LicPackTable.GetLastJetError(),
  792. (pString != NULL) ? pString : _TEXT("")
  793. );
  794. if(pString != NULL)
  795. {
  796. LocalFree(pString);
  797. }
  798. DBGPrintf(
  799. DBG_ERROR,
  800. DBG_FACILITY_JETBLUE,
  801. DBGLEVEL_FUNCTION_ERROR,
  802. _TEXT("Can't open table %s, error code %d\n"),
  803. m_LicPackTable.GetTableName(),
  804. m_LicPackTable.GetLastJetError()
  805. );
  806. goto cleanup;
  807. }
  808. bSuccess = m_LicPackDescTable.OpenTable(
  809. TRUE,
  810. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  811. );
  812. if(bSuccess == FALSE)
  813. {
  814. SetLastError(SET_JB_ERROR(m_LicPackDescTable.GetLastJetError()));
  815. LPTSTR pString = NULL;
  816. TLSGetESEError(m_LicPackDescTable.GetLastJetError(), &pString);
  817. TLSLogEvent(
  818. EVENTLOG_ERROR_TYPE,
  819. TLS_E_DBGENERAL,
  820. TLS_E_JB_OPENTABLE,
  821. m_LicPackDescTable.GetTableName(),
  822. m_LicPackDescTable.GetLastJetError(),
  823. (pString != NULL) ? pString : _TEXT("")
  824. );
  825. if(pString != NULL)
  826. {
  827. LocalFree(pString);
  828. }
  829. DBGPrintf(
  830. DBG_ERROR,
  831. DBG_FACILITY_JETBLUE,
  832. DBGLEVEL_FUNCTION_ERROR,
  833. _TEXT("Can't open table %s, error code %d\n"),
  834. m_LicPackDescTable.GetTableName(),
  835. m_LicPackDescTable.GetLastJetError()
  836. );
  837. goto cleanup;
  838. }
  839. bSuccess = m_LicensedTable.OpenTable(
  840. TRUE,
  841. (bUpdatable) ? JET_bitTableUpdatable : JET_bitTableReadOnly
  842. );
  843. if(bSuccess == FALSE)
  844. {
  845. SetLastError(SET_JB_ERROR(m_LicensedTable.GetLastJetError()));
  846. LPTSTR pString = NULL;
  847. TLSGetESEError(m_LicensedTable.GetLastJetError(), &pString);
  848. TLSLogEvent(
  849. EVENTLOG_ERROR_TYPE,
  850. TLS_E_DBGENERAL,
  851. TLS_E_JB_OPENTABLE,
  852. m_LicensedTable.GetTableName(),
  853. m_LicensedTable.GetLastJetError(),
  854. (pString != NULL) ? pString : _TEXT("")
  855. );
  856. if(pString != NULL)
  857. {
  858. LocalFree(pString);
  859. }
  860. DBGPrintf(
  861. DBG_ERROR,
  862. DBG_FACILITY_JETBLUE,
  863. DBGLEVEL_FUNCTION_ERROR,
  864. _TEXT("Can't open table %s, error code %d\n"),
  865. m_LicensedTable.GetTableName(),
  866. m_LicensedTable.GetLastJetError()
  867. );
  868. goto cleanup;
  869. }
  870. cleanup:
  871. return bSuccess;
  872. }