From df498661191525ff56048f5fbc295e3e7fcdaaf7 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 19 Nov 2024 14:16:27 +0800 Subject: [PATCH 01/22] update:build workflows --- .github/workflows/linuxbuild.yml | 13 ++++++++++--- .github/workflows/macbuild.yml | 11 +++++++++-- .github/workflows/msbuild.yml | 19 +++++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linuxbuild.yml b/.github/workflows/linuxbuild.yml index 932e144..10a3136 100644 --- a/.github/workflows/linuxbuild.yml +++ b/.github/workflows/linuxbuild.yml @@ -3,8 +3,9 @@ name: ubuntu build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -61,4 +62,10 @@ jobs: - name: test run: | cd XEngine_Release - ./XEngine_MQServiceApp -t \ No newline at end of file + ./XEngine_MQServiceApp -t + + - name: Upload folder as artifact with ubuntu + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Ubuntu + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/macbuild.yml b/.github/workflows/macbuild.yml index 37a16b1..f1008f2 100644 --- a/.github/workflows/macbuild.yml +++ b/.github/workflows/macbuild.yml @@ -3,8 +3,9 @@ name: macos build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -62,3 +63,9 @@ jobs: run: | cd XEngine_Release ./XEngine_MQServiceApp -t + + - name: Upload folder as artifact with mac + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Mac + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 6cb9efa..9963974 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -3,8 +3,9 @@ name: windows build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -75,3 +76,17 @@ jobs: ./VSCopy-x86.bat ./XEngine_MQServiceApp.exe -t shell: pwsh + + - name: Upload folder as artifact with x86 + if: matrix.configuration == 'Release' && matrix.platform == 'x86' + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_32-Windows + path: XEngine_Release/ + + - name: Upload folder as artifact with x64 + if: matrix.configuration == 'Release' && matrix.platform == 'x64' + uses: actions/upload-artifact@v4 + with: + name: XEngine_MQServiceApp-x86_64-Windows + path: XEngine_Release/ \ No newline at end of file From 3990487122407be8bf40fa3ad690eb614bc2ada1 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 19 Nov 2024 14:17:09 +0800 Subject: [PATCH 02/22] added:issue translator and release workflows --- .github/workflows/issue-translator.yml | 15 +++++ .github/workflows/release.yml | 89 ++++++++++++++++++++++++++ XEngine_Source/XEngine_Depend | 2 +- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/issue-translator.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/issue-translator.yml b/.github/workflows/issue-translator.yml new file mode 100644 index 0000000..d9fdac8 --- /dev/null +++ b/.github/workflows/issue-translator.yml @@ -0,0 +1,15 @@ +name: Issue Translator +on: + issue_comment: + types: [created] + issues: + types: [opened] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: usthe/issues-translate-action@v2.7 + with: + IS_MODIFY_TITLE: false + CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ebe97a1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: release packet + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # 检出代码并包含标签 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download linuxbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: linuxbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + - name: Download macbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: macbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + - name: Download msbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: msbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./XRelease/ + + - name: Display structure of downloaded files + run: ls -al ./XRelease/ + + - name: Get current version and increment X + id: versioning + run: | + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "Latest tag: $latest_tag" + # 提取 X 的值并递增 + major=$(echo $latest_tag | cut -d '.' -f 1) + minor=$(echo $latest_tag | cut -d '.' -f 2) + patch=$(echo $latest_tag | cut -d '.' -f 3) + build=$(echo $latest_tag | cut -d '.' -f 4) + + new_minor=$((minor + 1)) + new_version="$major.$new_minor.$patch.$build" + echo "New version: $new_version" + echo "new_tag=$new_version" >> $GITHUB_OUTPUT + echo "prev_tag=$latest_tag" >> $GITHUB_OUTPUT + + - name: Create and push new tag + run: | + git tag ${{ steps.versioning.outputs.new_tag }} + git push origin ${{ steps.versioning.outputs.new_tag }} + + - name: Generate release notes + run: | + logs=$(git log ${{ steps.versioning.outputs.prev_tag }}..${{ steps.versioning.outputs.new_tag }} --pretty=format:"* %h - %s - %an - %cd" --no-merges) + release_notes=$(echo "$logs" | sed 's/ qyt$/ @xengine-qyt/') + echo "$release_notes" + echo "$release_notes" > release_notes.txt + + - name: Release + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: false + prerelease: false + tag_name: ${{ steps.versioning.outputs.new_tag }} + name: XEngine_AuthorizeService ${{ steps.versioning.outputs.new_tag }} + body_path: release_notes.txt + files: ./XRelease/*.zip diff --git a/XEngine_Source/XEngine_Depend b/XEngine_Source/XEngine_Depend index bf32fe9..d1d1ee7 160000 --- a/XEngine_Source/XEngine_Depend +++ b/XEngine_Source/XEngine_Depend @@ -1 +1 @@ -Subproject commit bf32fe97c51e74c15c7f3998c6cf88220ddfc36c +Subproject commit d1d1ee7952a0a93a1beb183a8dee281d9231ff3d From a2c9a810176131e57958eb55919a4dbcbab35efc Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 19 Nov 2024 14:33:34 +0800 Subject: [PATCH 03/22] update:depend library and fix workflows. --- .github/workflows/linuxbuild.yml | 2 +- .github/workflows/release.yml | 2 +- XEngine_Source/XEngine_Depend | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linuxbuild.yml b/.github/workflows/linuxbuild.yml index 10a3136..2d9766d 100644 --- a/.github/workflows/linuxbuild.yml +++ b/.github/workflows/linuxbuild.yml @@ -18,7 +18,7 @@ jobs: matrix: include: - os: ubuntu-22.04 - - os: ubuntu-24.04 + #- os: ubuntu-24.04 runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ebe97a1..6c7bf69 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -84,6 +84,6 @@ jobs: draft: false prerelease: false tag_name: ${{ steps.versioning.outputs.new_tag }} - name: XEngine_AuthorizeService ${{ steps.versioning.outputs.new_tag }} + name: XEngine_MQService ${{ steps.versioning.outputs.new_tag }} body_path: release_notes.txt files: ./XRelease/*.zip diff --git a/XEngine_Source/XEngine_Depend b/XEngine_Source/XEngine_Depend index d1d1ee7..1c1452f 160000 --- a/XEngine_Source/XEngine_Depend +++ b/XEngine_Source/XEngine_Depend @@ -1 +1 @@ -Subproject commit d1d1ee7952a0a93a1beb183a8dee281d9231ff3d +Subproject commit 1c1452f13720d22834e09c7e4e78042698411486 From aa462987dd1fe4d429904a5890c7a93cb2d17200 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 20 Nov 2024 15:22:09 +0800 Subject: [PATCH 04/22] improved:start parameter parse --- XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp index e8fe2d1..22a9ab7 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Config.cpp @@ -30,15 +30,15 @@ bool MQ_Service_Parament(int argc, char** argv, XENGINE_SERVERCONFIG* pSt_Startl } else if (0 == _tcsxcmp("-TP",argv[i])) { - pSt_StartlParam->nTCPPort = _ttxoi(argv[i + 1]); + pSt_StartlParam->nTCPPort = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-HP",argv[i])) { - pSt_StartlParam->nHttpPort = _ttxoi(argv[i + 1]); + pSt_StartlParam->nHttpPort = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-d",argv[i])) { - pSt_StartlParam->bDeamon = _ttxoi(argv[i + 1]); + pSt_StartlParam->bDeamon = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-t", argv[i])) { From afdd0534f957afa4ea6890e5a5e6f4d27820651a Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 20 Nov 2024 15:30:35 +0800 Subject: [PATCH 05/22] added:coredump file support on windows --- .../XEngine_MQServiceApp/MQService_Hdr.h | 2 ++ .../XEngine_MQServiceApp.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h index feb0c0e..73d0b06 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h @@ -3,6 +3,7 @@ #include #include #include +#include #else #include #include @@ -98,6 +99,7 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_WSProtocol.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_MQTTProtocol.lib") #pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"Dbghelp.lib") #ifdef _DEBUG #ifdef _WIN64 #pragma comment(lib,"../x64/Debug/MQCore_ConfigModule.lib") diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index 64fd830..52d6740 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -84,12 +84,37 @@ static int ServiceApp_Deamon(int wait) #endif return 0; } +#ifdef _MSC_BUILD +LONG WINAPI Coredump_ExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers) +{ + static int i = 0; + XCHAR tszFileStr[MAX_PATH] = {}; + XCHAR tszTimeStr[128] = {}; + BaseLib_OperatorTime_TimeToStr(tszTimeStr); + _xstprintf(tszFileStr, _X("./XEngine_Coredump/dumpfile_%s_%d.dmp"), tszTimeStr, i++); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_FATAL, _X("主程序:软件崩溃,写入dump:%s"), tszFileStr); + HANDLE hDumpFile = CreateFileA(tszFileStr, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (INVALID_HANDLE_VALUE != hDumpFile) + { + MINIDUMP_EXCEPTION_INFORMATION st_DumpInfo = {}; + st_DumpInfo.ExceptionPointers = pExceptionPointers; + st_DumpInfo.ThreadId = GetCurrentThreadId(); + st_DumpInfo.ClientPointers = TRUE; + // 写入 dump 文件 + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &st_DumpInfo, NULL, NULL); + CloseHandle(hDumpFile); + } + return EXCEPTION_EXECUTE_HANDLER; +} +#endif int main(int argc, char** argv) { #ifdef _WINDOWS WSADATA st_WSAData; WSAStartup(MAKEWORD(2, 2), &st_WSAData); + + SetUnhandledExceptionFilter(Coredump_ExceptionFilter); #endif int nRet = -1; LPCXSTR lpszHTTPMime = _X("./XEngine_Config/HttpMime.types"); From 7cb4250910a3560a8db1d15f09522c0edaa601c9 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 20 Nov 2024 15:44:27 +0800 Subject: [PATCH 06/22] fixed:sometime crashed when exist --- XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index 52d6740..69bb3fb 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -381,7 +381,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,发行版本次数:%d,当前运行版本:%s。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceCfg.st_XVer.pStl_ListStorage->size(), st_ServiceCfg.st_XVer.pStl_ListStorage->front().c_str()); - while (bIsRun) + while (true) { if (bIsTest) { From bb22daaecc839f281fbba75d0a01a179b84ecf94 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 20 Nov 2024 16:55:29 +0800 Subject: [PATCH 07/22] modify:release path structure --- .../{XEngine_Log/.gitignore => XEngine_Coredump/keepfile} | 0 XEngine_Release/XEngine_Log/keepfile | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename XEngine_Release/{XEngine_Log/.gitignore => XEngine_Coredump/keepfile} (100%) create mode 100644 XEngine_Release/XEngine_Log/keepfile diff --git a/XEngine_Release/XEngine_Log/.gitignore b/XEngine_Release/XEngine_Coredump/keepfile similarity index 100% rename from XEngine_Release/XEngine_Log/.gitignore rename to XEngine_Release/XEngine_Coredump/keepfile diff --git a/XEngine_Release/XEngine_Log/keepfile b/XEngine_Release/XEngine_Log/keepfile new file mode 100644 index 0000000..e69de29 From 1d9795c7757d02293e4361de024e989dcd4476b5 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 14:09:14 +0800 Subject: [PATCH 08/22] update:read me and release.yml --- .github/workflows/release.yml | 2 +- README.en.md | 2 ++ README.md | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c7bf69..a52b626 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -71,7 +71,7 @@ jobs: - name: Generate release notes run: | - logs=$(git log ${{ steps.versioning.outputs.prev_tag }}..${{ steps.versioning.outputs.new_tag }} --pretty=format:"* %h - %s - %an - %cd" --no-merges) + logs=$(git log ${{ steps.versioning.outputs.prev_tag }}..${{ steps.versioning.outputs.new_tag }} --pretty=format:"* %h - %s - %an" --no-merges) release_notes=$(echo "$logs" | sed 's/ qyt$/ @xengine-qyt/') echo "$release_notes" echo "$release_notes" > release_notes.txt diff --git a/README.en.md b/README.en.md index 53a0c16..bbb9984 100644 --- a/README.en.md +++ b/README.en.md @@ -33,6 +33,7 @@ this software support following features 17. binary message 18. http interface management 19. message attritube +20. point to point message ## install @@ -113,6 +114,7 @@ Address:app.xyry.org Port:TCP 5200,WEBSOCKET 5201,HTTP Management Interface 5202 2. Create new Feat_xxx branch 3. Submit the code 4. New Pull Request +5. Submit develop branch ## Follow us If you think this software is helpful to you, please give us a START diff --git a/README.md b/README.md index 07d9c04..f8974e5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ c c++Message Service 17. 二进制消息 18. http接口管理 19. 消息属性 +20. 点对点消息 ## 安装教程 @@ -119,6 +120,7 @@ make FLAGS=CleanAll 清理编译 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request +5. 提交到develop分支 ## 关注我们 如果你觉得这个软件对你有帮助,请你给我们一个START吧 From 9ad39331b61f223cfde4ec7da4d7337780dcbf4a Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 14:26:29 +0800 Subject: [PATCH 09/22] fixed:get online user is incorrect when publish message --- XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp index 3fb0c82..c97eebf 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp @@ -453,7 +453,7 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY; //只有在线用户才需要即时通知 - if (SessionModule_Client_GetExist(NULL, tszUserName)) + if (SessionModule_Client_GetExist(NULL, ppSt_ListUser[i]->tszUserName)) { //如果发送指定用户被指定. if ((_tcsxlen(st_MQProtocol.tszMQUsr) > 0) && (0 != _tcsxnicmp(st_MQProtocol.tszMQUsr, tszUserName, _tcsxlen(st_MQProtocol.tszMQUsr)))) From 0288b972eb465a7b36d1323bce8c48e8d2e8509c Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 14:33:41 +0800 Subject: [PATCH 10/22] fixed:immediate notify user process is incorrect --- .../MQService_TCPTask.cpp | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp index c97eebf..34ce1d5 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp @@ -434,39 +434,51 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC } else { - int nListCount = 0; - XENGINE_DBUSERKEY** ppSt_ListUser; - DBModule_MQUser_KeyList(NULL, st_MQProtocol.tszMQKey, &ppSt_ListUser, &nListCount); + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY; - for (int i = 0; i < nListCount; i++) + if (_tcsxlen(st_MQProtocol.tszMQUsr) > 0) { - //跳过自己 - if (0 == _tcsxncmp(tszUserName, ppSt_ListUser[i]->tszUserName, _tcsxlen(tszUserName)) && (0 == st_MQProtocol.st_MSGAttr.byAttrSelf)) + //如果发送指定用户被指定. + if (SessionModule_Client_GetExist(NULL, st_MQProtocol.tszMQUsr)) { - continue; + int nClientType = 0; + XCHAR tszUserAddr[128] = {}; + + SessionModule_Client_GetAddr(st_MQProtocol.tszMQUsr, tszUserAddr); + SessionModule_Client_GetType(tszUserAddr, &nClientType); + ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); + XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); } - nSDLen = 0; - int nClientType = 0; - XCHAR tszUserAddr[128]; - memset(tszUserAddr, '\0', sizeof(tszUserAddr)); - memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + } + else + { + int nListCount = 0; + XENGINE_DBUSERKEY** ppSt_ListUser; + DBModule_MQUser_KeyList(NULL, st_MQProtocol.tszMQKey, &ppSt_ListUser, &nListCount); - pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY; - //只有在线用户才需要即时通知 - if (SessionModule_Client_GetExist(NULL, ppSt_ListUser[i]->tszUserName)) + for (int i = 0; i < nListCount; i++) { - //如果发送指定用户被指定. - if ((_tcsxlen(st_MQProtocol.tszMQUsr) > 0) && (0 != _tcsxnicmp(st_MQProtocol.tszMQUsr, tszUserName, _tcsxlen(st_MQProtocol.tszMQUsr)))) + //跳过自己 + if (0 == _tcsxncmp(tszUserName, ppSt_ListUser[i]->tszUserName, _tcsxlen(tszUserName)) && (0 == st_MQProtocol.st_MSGAttr.byAttrSelf)) { continue; } - SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr); - SessionModule_Client_GetType(tszUserAddr, &nClientType); - ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); - XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); + nSDLen = 0; + int nClientType = 0; + XCHAR tszUserAddr[128]; + memset(tszUserAddr, '\0', sizeof(tszUserAddr)); + memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + //只有在线用户才需要即时通知 + if (SessionModule_Client_GetExist(NULL, ppSt_ListUser[i]->tszUserName)) + { + SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr); + SessionModule_Client_GetType(tszUserAddr, &nClientType); + ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ)); + XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType); + } } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); } _xstprintf(st_DBQueue.tszQueuePublishTime, _X("0")); } From 881bc04b884788cc103cc430a46c7f4325367f02 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 16:55:57 +0800 Subject: [PATCH 11/22] added:memory cache module --- .../MQCore_MemoryCache/MQCore_MemoryCache.def | 10 + .../MQCore_MemoryCache.vcxproj | 189 +++++++++++++++ .../MQCore_MemoryCache.vcxproj.filters | 56 +++++ .../MQCore_MemoryCache.vcxproj.user | 4 + XEngine_Source/MQCore_MemoryCache/Makefile | 69 ++++++ .../MemoryCache_DBData/MemoryCache_DBData.cpp | 227 ++++++++++++++++++ .../MemoryCache_DBData/MemoryCache_DBData.h | 60 +++++ .../MQCore_MemoryCache/MemoryCache_Define.h | 89 +++++++ .../MQCore_MemoryCache/MemoryCache_Error.h | 18 ++ XEngine_Source/MQCore_MemoryCache/dllmain.cpp | 19 ++ XEngine_Source/MQCore_MemoryCache/framework.h | 5 + XEngine_Source/MQCore_MemoryCache/pch.cpp | 51 ++++ XEngine_Source/MQCore_MemoryCache/pch.h | 46 ++++ XEngine_Source/Makefile | 5 +- XEngine_Source/XEngine_MQServiceApp.sln | 10 + 15 files changed, 857 insertions(+), 1 deletion(-) create mode 100644 XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def create mode 100644 XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj create mode 100644 XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters create mode 100644 XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user create mode 100644 XEngine_Source/MQCore_MemoryCache/Makefile create mode 100644 XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp create mode 100644 XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h create mode 100644 XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h create mode 100644 XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h create mode 100644 XEngine_Source/MQCore_MemoryCache/dllmain.cpp create mode 100644 XEngine_Source/MQCore_MemoryCache/framework.h create mode 100644 XEngine_Source/MQCore_MemoryCache/pch.cpp create mode 100644 XEngine_Source/MQCore_MemoryCache/pch.h diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def new file mode 100644 index 0000000..f04e829 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def @@ -0,0 +1,10 @@ +LIBRARY + +EXPORTS + MemoryCache_GetLastError + + MemoryCache_DBData_Init + MemoryCache_DBData_Destory + MemoryCache_DBData_DataInsert + MemoryCache_DBData_DataQuery + MemoryCache_DBData_DataDelete \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj new file mode 100644 index 0000000..981a9f5 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj @@ -0,0 +1,189 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {8c55d3e0-fec2-4a6c-a374-651516ed8f99} + MQCoreMemoryCache + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);..\MQCore_MemoryCache;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + + + $(XEngine_Include);$(IncludePath) + + + $(XEngine_Include);$(IncludePath) + + + + Level3 + true + WIN32;_DEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + true + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + _DEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + false + MQCore_MemoryCache.def + + + + + Level3 + true + true + true + NDEBUG;MQCOREMEMORYCACHE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + + + Windows + true + true + true + false + MQCore_MemoryCache.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters new file mode 100644 index 0000000..da7be03 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {4c036899-9b97-4388-94f1-12e980800877} + + + {d3182e9a-8f45-4138-b4e2-a793c976d18d} + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件\MemoryCache_DBData + + + + + 源文件 + + + 源文件 + + + 源文件\MemoryCache_DBData + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/Makefile b/XEngine_Source/MQCore_MemoryCache/Makefile new file mode 100644 index 0000000..8a8a2b6 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/Makefile @@ -0,0 +1,69 @@ +CC = g++ -Wall -std=c++17 -fPIC +PLATFORM = linux +PLATVER = +PLATDIR = +FILEEXT = +LIBFLAG = +RELEASE = 0 +LOADHDR = -I ./ +LOADSO = +LIB = +LIBEX = +OBJECTS = MemoryCache_DBData.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c +DEBUG = +else + ifeq ($(PLATFORM),mac) + FLAGS = -c + DEBUG = -g + else + FLAGS = -c -lc_p + DEBUG = -g -pg + endif +endif + +ifeq ($(PLATFORM),linux) + ifeq (/etc/redhat-release,$(wildcard /etc/redhat-release)) + PLATVER = -D __CENTOS__ + PLATDIR = XEngine_Linux/Centos + else + PLATVER = -D __UBUNTU__ + PLATDIR = XEngine_Linux/Ubuntu + endif + FILEEXT = so + LIBFLAG = -shared + LIBEX = -lpthread -lrt -ldl + LOADBIN = -Wl,-rpath=./,--disable-new-dtags +else ifeq ($(PLATFORM),mac) + CC += -Wno-deprecated-declarations + PLATVER = -D __MACOS__ + PLATDIR = XEngine_Mac + FILEEXT = dylib + LIBFLAG = -dynamiclib + LIBEX = -lpthread -ldl + LOADBIN = -Wl,-rpath,@loader_path/./ +endif + + +all:$(OBJECTS) + $(CC) $(DEBUG) $(OBJECTS) -o libMQCore_MemoryCache.$(FILEEXT) $(LIBFLAG) $(LIB) $(LIBEX) $(LOADSO) $(LOADBIN) + +MemoryCache_DBData.o:./MemoryCache_DBData/MemoryCache_DBData.cpp + $(CC) $(DEBUG) $(FLAGS) $(PLATVER) $(LOADHDR) ./MemoryCache_DBData/MemoryCache_DBData.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(PLATVER) $(LOADHDR) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libMQCore_MemoryCache.$(FILEEXT) + cp ./libMQCore_MemoryCache.$(FILEEXT) ../../XEngine_Release/libMQCore_MemoryCache.$(FILEEXT) + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.$(FILEEXT) \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp new file mode 100644 index 0000000..fb84bc6 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -0,0 +1,227 @@ +#include "pch.h" +#include "MemoryCache_DBData.h" +/******************************************************************** +// Created: 2024/11/21 16:35:54 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData\MemoryCache_DBData.cpp +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData +// File Base: MemoryCache_DBData +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 数据库高速缓存 +// History: +*********************************************************************/ +CMemoryCache_DBData::CMemoryCache_DBData() +{ +} +CMemoryCache_DBData::~CMemoryCache_DBData() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:MemoryCache_DBData_Init +函数功能:初始化高速缓存管理器 + 参数.一:nTimeLast + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最后更新时间存在秒数 + 参数.二:nTimeStart + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最大保留时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) +{ + MemoryCache_IsErrorOccur = false; + + bIsRun = true; + + m_nTimeLast = nTimeLast; + m_nTimeStart = nTimeStart; + + pSTDThread = std::make_unique(DBModule_MQUser_TimeThread, this); + if (NULL == pSTDThread) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD; + return false; + } + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_Destory +函数功能:销毁高速缓存管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_Destory() +{ + MemoryCache_IsErrorOccur = false; + + bIsRun = false; + if (NULL != pSTDThread) + { + pSTDThread->join(); + } + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataInsert +函数功能:插入一条数据到高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + MEMORYCACHE_DBINFO st_DBInfo = {}; + + st_DBInfo.nTimeStart = time(NULL); + st_DBInfo.st_DBMessageInfo = *pSt_DBMessageInfo; + + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + st_LockerQuery.lock(); + stl_MapQuery[stl_Key] = st_DBInfo; + st_LockerQuery.unlock(); + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataQuery +函数功能:查询高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要查询的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + st_LockerQuery.lock_shared(); + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; + st_LockerQuery.unlock_shared(); + return false; + } + stl_MapIterator->second.nTimeLast = time(NULL); + *pSt_DBMessageInfo = stl_MapIterator->second.st_DBMessageInfo; + st_LockerQuery.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:MemoryCache_DBData_DataDelete +函数功能:删除高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要操作的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == pSt_DBMessageInfo) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + st_LockerQuery.lock(); + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; + st_LockerQuery.unlock(); + return false; + } + stl_MapQuery.erase(stl_Key); + st_LockerQuery.unlock(); + return true; +} +////////////////////////////////////////////////////////////////////////// +// 线程函数 +////////////////////////////////////////////////////////////////////////// +XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_TimeThread(XPVOID lParam) +{ + CMemoryCache_DBData* pClass_This = (CMemoryCache_DBData*)lParam; + + std::list stl_ListDelete; + while (pClass_This->bIsRun) + { + time_t nTimeEnd = time(NULL); + pClass_This->st_LockerQuery.lock_shared(); + for (auto stl_MapIterator = pClass_This->stl_MapQuery.begin(); stl_MapIterator != pClass_This->stl_MapQuery.end(); stl_MapIterator++) + { + if (stl_MapIterator->second.nTimeLast > (nTimeEnd - pClass_This->m_nTimeLast)) + { + stl_ListDelete.push_back(stl_MapIterator->second.st_DBMessageInfo); + } + else if (pClass_This->m_nTimeStart > 0 && (nTimeEnd - pClass_This->m_nTimeStart)) + { + stl_ListDelete.push_back(stl_MapIterator->second.st_DBMessageInfo); + } + } + pClass_This->st_LockerQuery.unlock_shared(); + + for (auto stl_ListIterator = stl_ListDelete.begin(); stl_ListIterator != stl_ListDelete.end(); stl_ListIterator++) + { + XENGINE_DBMESSAGEQUEUE st_DBMessage = *stl_ListIterator; + pClass_This->MemoryCache_DBData_DataDelete(&st_DBMessage); + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + return 0; +} \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h new file mode 100644 index 0000000..a0c1e3a --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h @@ -0,0 +1,60 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 16:35:19 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData\MemoryCache_DBData.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_DBData +// File Base: MemoryCache_DBData +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 数据库高速缓存 +// History: +*********************************************************************/ +typedef struct +{ + XENGINE_DBMESSAGEQUEUE st_DBMessageInfo; + time_t nTimeStart; + time_t nTimeLast; +}MEMORYCACHE_DBINFO; + +struct TupleHash +{ + template + std::size_t operator()(const std::tuple& t) const + { + return std::apply([](auto&&... args) + { + // 使用std::hash对每个元素分别哈希并组合结果 + std::size_t seed = 0; + ((seed ^= std::hash>()(args) + 0x9e3779b9 + (seed << 6) + (seed >> 2)), ...); + return seed; + }, t); + } +}; + +class CMemoryCache_DBData +{ +public: + CMemoryCache_DBData(); + ~CMemoryCache_DBData(); +public: + bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); + bool MemoryCache_DBData_Destory(); +public: + bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); + bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); + bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +protected: + static XHTHREAD CALLBACK DBModule_MQUser_TimeThread(XPVOID lParam); +private: + bool bIsRun = false; + int m_nTimeLast = 0; + int m_nTimeStart = 0; +private: + std::shared_mutex st_LockerList; + std::shared_mutex st_LockerQuery; + std::unique_ptr pSTDThread; +private: + std::list stl_ListInsert; + std::unordered_map, MEMORYCACHE_DBINFO, TupleHash> stl_MapQuery; +}; \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h new file mode 100644 index 0000000..4da763f --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h @@ -0,0 +1,89 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 15:09:57 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_Define.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: MemoryCache_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出的函数 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG MemoryCache_GetLastError(int *pInt_SysError = NULL); +/************************************************************************* + 高速缓存导出函数 +**************************************************************************/ +/******************************************************************** +函数名称:MemoryCache_DBData_Init +函数功能:初始化高速缓存管理器 + 参数.一:nTimeLast + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最后更新时间存在秒数 + 参数.二:nTimeStart + In/Out:In + 类型:整数型 + 可空:N + 意思:允许的最大保留时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); +/******************************************************************** +函数名称:MemoryCache_DBData_Destory +函数功能:销毁高速缓存管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_Destory(); +/******************************************************************** +函数名称:MemoryCache_DBData_DataInsert +函数功能:插入一条数据到高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_DataQuery +函数功能:查询高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要查询的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_DataDelete +函数功能:删除高速缓存 + 参数.一:pSt_DBMessageInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要操作的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h new file mode 100644 index 0000000..c3dea5b --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Error.h @@ -0,0 +1,18 @@ +#pragma once +/******************************************************************** +// Created: 2024/11/21 15:10:20 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\MemoryCache_Error.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: MemoryCache_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出的错误 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD 0x1A0001 //创建线程失败 +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT 0x1A0002 //参数错误 +#define ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND 0x1A0003 //没有找到 \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/dllmain.cpp b/XEngine_Source/MQCore_MemoryCache/dllmain.cpp new file mode 100644 index 0000000..daed8c8 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/MQCore_MemoryCache/framework.h b/XEngine_Source/MQCore_MemoryCache/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/MQCore_MemoryCache/pch.cpp b/XEngine_Source/MQCore_MemoryCache/pch.cpp new file mode 100644 index 0000000..f830df4 --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/pch.cpp @@ -0,0 +1,51 @@ +#include "pch.h" +#include "MemoryCache_DBData/MemoryCache_DBData.h" +/******************************************************************** +// Created: 2024/11/21 15:01:53 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\pch.cpp +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +bool MemoryCache_IsErrorOccur = false; +XLONG MemoryCache_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CMemoryCache_DBData m_MemoryDBData; +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG MemoryCache_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return MemoryCache_dwErrorCode; +} +/************************************************************************* + 高速缓存导出函数 +**************************************************************************/ +extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) +{ + return m_MemoryDBData.MemoryCache_DBData_Init(nTimeLast, nTimeStart); +} +extern "C" bool MemoryCache_DBData_Destory() +{ + return m_MemoryDBData.MemoryCache_DBData_Destory(); +} +extern "C" bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataInsert(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataQuery(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) +{ + return m_MemoryDBData.MemoryCache_DBData_DataDelete(pSt_DBMessageInfo); +} \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/pch.h b/XEngine_Source/MQCore_MemoryCache/pch.h new file mode 100644 index 0000000..d03194b --- /dev/null +++ b/XEngine_Source/MQCore_MemoryCache/pch.h @@ -0,0 +1,46 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _MSC_BUILD +// 添加要在此处预编译的标头 +#include "framework.h" +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../MQCore_DBModule/DBModule_Define.h" +#include "../MQCore_DBModule/DBModule_Error.h" +#include "MemoryCache_Define.h" +#include "MemoryCache_Error.h" +/******************************************************************** +// Created: 2024/11/21 14:44:49 +// File Name: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache\pch.h +// File Path: D:\XEngine_MQService\XEngine_Source\MQCore_MemoryCache +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头 +// History: +*********************************************************************/ +extern bool MemoryCache_IsErrorOccur; +extern XLONG MemoryCache_dwErrorCode; \ No newline at end of file diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index b2e6f23..36bf6fc 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -8,6 +8,7 @@ BASE_THIRDPART_REPORT = ./XEngine_Depend/XEngine_Module/XEngine_InfoReport BASE_CONFIG_PATH = ./MQCore_ConfigModule BASE_PROTOCOL_PATH = ./MQCore_ProtocolModule +BASE_MEMORYCACHE_PATH = ./MQCore_MemoryCache BASE_DATABASE_PATH = ./MQCore_DBModule BASE_SESSION_PATH = ./MQCore_SessionModule @@ -20,7 +21,7 @@ else ifeq ($(PLATFORM),mac) endif XENGINE_MODULES = libjsoncpp.so libXEngine_InfoReport.so \ - libMQCore_ConfigModule.so libMQCore_ProtocolModule.so libMQCore_SessionModule.so libMQCore_DBModule.so \ + libMQCore_ConfigModule.so libMQCore_ProtocolModule.so libMQCore_SessionModule.so libMQCore_MemoryCache.so libMQCore_DBModule.so \ XEngine_MQServiceApp.exe .PHONY:MakeAll @@ -46,6 +47,8 @@ libMQCore_ProtocolModule.so: make -C $(BASE_PROTOCOL_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libMQCore_SessionModule.so: make -C $(BASE_SESSION_PATH) PLATFORM=$(PLATFORM) $(FLAGS) +libMQCore_MemoryCache.so: + make -C $(BASE_MEMORYCACHE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libMQCore_DBModule.so: make -C $(BASE_DATABASE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) diff --git a/XEngine_Source/XEngine_MQServiceApp.sln b/XEngine_Source/XEngine_MQServiceApp.sln index 718dfab..35cf8e3 100644 --- a/XEngine_Source/XEngine_MQServiceApp.sln +++ b/XEngine_Source/XEngine_MQServiceApp.sln @@ -41,6 +41,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_InfoReport", "XEngi {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MQCore_MemoryCache", "MQCore_MemoryCache\MQCore_MemoryCache.vcxproj", "{8C55D3E0-FEC2-4A6C-A374-651516ED8F99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -105,6 +107,14 @@ Global {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x64.Build.0 = Release|x64 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.ActiveCfg = Release|Win32 {F6520D2C-BB8E-45BB-964B-F5D6A4318A89}.Release|x86.Build.0 = Release|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x64.ActiveCfg = Debug|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x64.Build.0 = Debug|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x86.ActiveCfg = Debug|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Debug|x86.Build.0 = Debug|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x64.ActiveCfg = Release|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x64.Build.0 = Release|x64 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x86.ActiveCfg = Release|Win32 + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From a67c132057ce67b883bad68b325694008d6ff222 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 17:32:40 +0800 Subject: [PATCH 12/22] added:memory cache configure supported --- XEngine_Source/MQCore_ConfigModule/Config_Define.h | 6 ++++++ XEngine_Source/MQCore_ConfigModule/Config_Error.h | 3 ++- .../MQCore_ConfigModule/Config_Json/Config_Json.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Define.h b/XEngine_Source/MQCore_ConfigModule/Config_Define.h index bb2b912..5a8eec7 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Define.h +++ b/XEngine_Source/MQCore_ConfigModule/Config_Define.h @@ -55,6 +55,12 @@ typedef struct XCHAR tszPassLogout[MAX_PATH]; int nTimeout; }st_XPass; + struct + { + bool bEnable; + int nTimeLast; + int nTimeStart; + }st_XMemory; struct { bool bEnable; diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Error.h b/XEngine_Source/MQCore_ConfigModule/Config_Error.h index e4c57df..c0aa55d 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Error.h +++ b/XEngine_Source/MQCore_ConfigModule/Config_Error.h @@ -21,4 +21,5 @@ #define ERROR_MQ_MODULE_CONFIG_JSON_XSQL 0x0020006 #define ERROR_MQ_MODULE_CONFIG_JSON_XPASS 0x0020007 #define ERROR_MQ_MODULE_CONFIG_JSON_XVER 0x0020008 -#define ERROR_MQ_MODULE_CONFIG_JSON_XREPORT 0x0020009 \ No newline at end of file +#define ERROR_MQ_MODULE_CONFIG_JSON_XREPORT 0x0020009 +#define ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY 0x0020010 \ No newline at end of file diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp index 56d3146..d66eb91 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp +++ b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp @@ -123,6 +123,17 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassRegister, st_JsonXPass["tszPassRegister"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassUNReg, st_JsonXPass["tszPassUNReg"].asCString()); + if (st_JsonRoot["XMemory"].empty() || (3 != st_JsonRoot["XMemory"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY; + return false; + } + Json::Value st_JsonXMemory = st_JsonRoot["XMemory"]; + pSt_ServerConfig->st_XMemory.bEnable = st_JsonXMemory["bEnable"].asBool(); + pSt_ServerConfig->st_XMemory.nTimeLast = st_JsonXMemory["nTimeLast"].asInt(); + pSt_ServerConfig->st_XMemory.nTimeStart = st_JsonXMemory["nTimeStart"].asInt(); + if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size())) { Config_IsErrorOccur = true; From cef9679abd911cd38040c1996482cb660cbbfabd Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 21 Nov 2024 17:36:19 +0800 Subject: [PATCH 13/22] update:configure file --- XEngine_Release/XEngine_Config/XEngine_Config.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index d35b3c0..0e40c31 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -25,7 +25,7 @@ "SQLAddr":"10.0.3.154", "SQLPort":3306, "SQLUser":"root", - "SQLPass":"123123" + "SQLPass":"123123aa" }, "XPass":{ "nTimeout":2, @@ -34,6 +34,11 @@ "tszPassLogin":"", "tszPassLogout":"" }, + "XMemory":{ + "bEnable":true, + "nTimeLast":3600, + "nTimeStart":0 + }, "XReport":{ "bEnable":true, "tszServiceName":"XEngine_MQService", From 76cf584c27572730d5bd8ebf1db1a3e54af8b7b6 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Mon, 25 Nov 2024 14:14:17 +0800 Subject: [PATCH 14/22] added:Message Data Queue Cache Support --- .../MQCore_DBModule/DBModule_Define.h | 7 ++++- .../DBModule_MQData/DBModule_MQData.cpp | 29 ++++++++++++++++++- .../DBModule_MQData/DBModule_MQData.h | 5 ++-- XEngine_Source/MQCore_DBModule/Makefile | 4 +-- XEngine_Source/MQCore_DBModule/pch.cpp | 4 +-- XEngine_Source/MQCore_DBModule/pch.h | 15 ++++++++++ .../MemoryCache_DBData/MemoryCache_DBData.cpp | 10 ++++++- XEngine_Source/XEngine_MQServiceApp.sln | 4 +++ .../XEngine_MQServiceApp/MQService_Hdr.h | 6 ++++ XEngine_Source/XEngine_MQServiceApp/Makefile | 4 +-- .../XEngine_MQServiceApp.cpp | 18 +++++++++++- 11 files changed, 94 insertions(+), 12 deletions(-) diff --git a/XEngine_Source/MQCore_DBModule/DBModule_Define.h b/XEngine_Source/MQCore_DBModule/DBModule_Define.h index 45316f1..911c403 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_Define.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_Define.h @@ -71,12 +71,17 @@ extern "C" XLONG DBModule_GetLastError(int *pInt_SysError = NULL); 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 + 参数.二:bMemoryCache + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector); +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache = true); /******************************************************************** 函数名称:DBModule_MQData_Destory 函数功能:销毁数据库管理器 diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp index f621880..faf2cb4 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp @@ -30,12 +30,17 @@ CDBModule_MQData::~CDBModule_MQData() 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 + 参数.二:bMemoryCache + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector) +bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache) { DBModule_IsErrorOccur = false; @@ -45,6 +50,7 @@ bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBCo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT; return false; } + m_bMemoryCache = bMemoryCache; //连接数据库 _tcsxcpy(pSt_DBConnector->tszDBName, _X("XEngine_MQData")); if (!DataBase_MySQL_Connect(&xhDBSQL, pSt_DBConnector)) @@ -115,6 +121,10 @@ bool CDBModule_MQData::DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo DBModule_dwErrorCode = DataBase_GetLastError(); return false; } + if (m_bMemoryCache) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** @@ -140,6 +150,14 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT; return false; } + + if (m_bMemoryCache) + { + if (MemoryCache_DBData_DataQuery(pSt_DBInfo)) + { + return true; + } + } //查询 XNETHANDLE xhTable = 0; __int64u nllLine = 0; @@ -216,6 +234,11 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) _tcsxcpy(pSt_DBInfo->tszQueueCreateTime, pptszResult[nPos]); } DataBase_MySQL_FreeResult(xhDBSQL, xhTable); + + if (m_bMemoryCache) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** @@ -270,6 +293,10 @@ bool CDBModule_MQData::DBModule_MQData_Modify(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_NOTFOUND; return false; } + if (m_bMemoryCache) + { + MemoryCache_DBData_DataInsert(pSt_DBInfo); + } return true; } /******************************************************************** diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h index 492cfbc..dca3ac9 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h @@ -17,7 +17,7 @@ class CDBModule_MQData CDBModule_MQData(); ~CDBModule_MQData(); public: - bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector); + bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache = true); bool DBModule_MQData_Destory(); bool DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); bool DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); @@ -29,5 +29,6 @@ class CDBModule_MQData bool DBModule_MQData_ShowTable(XCHAR*** pppszTableName, int* pInt_ListCount); bool DBModule_MQData_GetLeftCount(LPCXSTR lpszTableName, int nSerial, int* pInt_Count); private: - XNETHANDLE xhDBSQL; + bool m_bMemoryCache = false; + XNETHANDLE xhDBSQL = 0; }; \ No newline at end of file diff --git a/XEngine_Source/MQCore_DBModule/Makefile b/XEngine_Source/MQCore_DBModule/Makefile index e7217a8..cb608ab 100644 --- a/XEngine_Source/MQCore_DBModule/Makefile +++ b/XEngine_Source/MQCore_DBModule/Makefile @@ -6,8 +6,8 @@ FILEEXT = LIBFLAG = RELEASE = 0 LOADHDR = -I ./ -LOADSO = -LIB = -lXEngine_BaseLib -lHelpComponents_DataBase +LOADSO = -L ../MQCore_MemoryCache +LIB = -lXEngine_BaseLib -lHelpComponents_DataBase -lMQCore_MemoryCache LIBEX = OBJECTS = DBModule_MQData.o DBModule_MQUser.o pch.o diff --git a/XEngine_Source/MQCore_DBModule/pch.cpp b/XEngine_Source/MQCore_DBModule/pch.cpp index 9f58222..87050c7 100644 --- a/XEngine_Source/MQCore_DBModule/pch.cpp +++ b/XEngine_Source/MQCore_DBModule/pch.cpp @@ -31,9 +31,9 @@ extern "C" XLONG DBModule_GetLastError(int* pInt_SysError) /************************************************************************* 消息队列导出函数 **************************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector) +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector, bool bMemoryCache) { - return m_DBData.DBModule_MQData_Init(pSt_DBConnector); + return m_DBData.DBModule_MQData_Init(pSt_DBConnector, bMemoryCache); } extern "C" bool DBModule_MQData_Destory() { diff --git a/XEngine_Source/MQCore_DBModule/pch.h b/XEngine_Source/MQCore_DBModule/pch.h index 45ca327..3fbb3a7 100644 --- a/XEngine_Source/MQCore_DBModule/pch.h +++ b/XEngine_Source/MQCore_DBModule/pch.h @@ -30,6 +30,8 @@ using namespace std; #include #include "DBModule_Define.h" #include "DBModule_Error.h" +#include "../MQCore_MemoryCache/MemoryCache_Define.h" +#include "../MQCore_MemoryCache/MemoryCache_Error.h" /******************************************************************** // Created: 2022/02/23 16:14:35 // File Name: D:\XEngine_MQService\XEngine_Source\MQCore_DBModule\pch.h @@ -47,4 +49,17 @@ extern XLONG DBModule_dwErrorCode; #ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_DataBase.lib") +#ifdef _DEBUG +#ifdef _WIN64 +#pragma comment(lib,"../x64/Debug/MQCore_MemoryCache.lib") +#else +#pragma comment(lib,"../Debug/MQCore_MemoryCache.lib") +#endif +#else +#ifdef _WIN64 +#pragma comment(lib,"../x64/Release/MQCore_MemoryCache.lib") +#else +#pragma comment(lib,"../Release/MQCore_MemoryCache.lib") +#endif +#endif #endif \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp index fb84bc6..9092587 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -108,7 +108,15 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); st_LockerQuery.lock(); - stl_MapQuery[stl_Key] = st_DBInfo; + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + stl_MapQuery[stl_Key] = st_DBInfo; + } + else + { + stl_MapIterator->second.st_DBMessageInfo = *pSt_DBMessageInfo; + } st_LockerQuery.unlock(); return true; } diff --git a/XEngine_Source/XEngine_MQServiceApp.sln b/XEngine_Source/XEngine_MQServiceApp.sln index 35cf8e3..3315a56 100644 --- a/XEngine_Source/XEngine_MQServiceApp.sln +++ b/XEngine_Source/XEngine_MQServiceApp.sln @@ -8,6 +8,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_MQServiceApp", "XEn {32D3FC68-6252-4D20-BB07-6C98BD753D11} = {32D3FC68-6252-4D20-BB07-6C98BD753D11} {5475F316-F9E9-4FF5-95ED-F7C9474709A3} = {5475F316-F9E9-4FF5-95ED-F7C9474709A3} {77321E0D-15DB-4C6E-8872-115CBBE41F27} = {77321E0D-15DB-4C6E-8872-115CBBE41F27} + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} = {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} {B0EB2A7A-53C1-4E9F-A851-19539099671C} = {B0EB2A7A-53C1-4E9F-A851-19539099671C} {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} = {F1736B3F-03A2-4FC7-B045-A12BA8D724FB} {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} = {F6520D2C-BB8E-45BB-964B-F5D6A4318A89} @@ -31,6 +32,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MQCore_Hdr", "MQCore_Hdr", EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MQCore_DBModule", "MQCore_DBModule\MQCore_DBModule.vcxproj", "{5475F316-F9E9-4FF5-95ED-F7C9474709A3}" + ProjectSection(ProjectDependencies) = postProject + {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} = {8C55D3E0-FEC2-4A6C-A374-651516ED8F99} + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XEngine_Depend", "XEngine_Depend", "{BAC91AAE-D438-4999-9541-EB8804B12F0C}" EndProject diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h index 73d0b06..e9113e9 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h @@ -59,6 +59,8 @@ typedef std::string tstring; #include "../MQCore_DBModule/DBModule_Error.h" #include "../MQCore_ProtocolModule/Protocol_Define.h" #include "../MQCore_ProtocolModule/Protocol_Error.h" +#include "../MQCore_MemoryCache/MemoryCache_Define.h" +#include "../MQCore_MemoryCache/MemoryCache_Error.h" extern bool bIsRun; extern bool bIsTest; @@ -107,12 +109,14 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"../x64/Debug/MQCore_SessionModule.lib") #pragma comment(lib,"../x64/Debug/MQCore_DBModule.lib") #pragma comment(lib,"../x64/Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Debug/MQCore_MemoryCache.lib") #else #pragma comment(lib,"../Debug/MQCore_ConfigModule.lib") #pragma comment(lib,"../Debug/MQCore_ProtocolModule.lib") #pragma comment(lib,"../Debug/MQCore_SessionModule.lib") #pragma comment(lib,"../Debug/MQCore_DBModule.lib") #pragma comment(lib,"../Debug/XEngine_InfoReport.lib") +#pragma comment(lib,"../Debug/MQCore_MemoryCache.lib") #endif #else #ifdef _WIN64 @@ -121,12 +125,14 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig; #pragma comment(lib,"../x64/Release/MQCore_SessionModule.lib") #pragma comment(lib,"../x64/Release/MQCore_DBModule.lib") #pragma comment(lib,"../x64/Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../x64/Release/MQCore_MemoryCache.lib") #else #pragma comment(lib,"../Release/MQCore_ConfigModule.lib") #pragma comment(lib,"../Release/MQCore_ProtocolModule.lib") #pragma comment(lib,"../Release/MQCore_SessionModule.lib") #pragma comment(lib,"../Release/MQCore_DBModule.lib") #pragma comment(lib,"../Release/XEngine_InfoReport.lib") +#pragma comment(lib,"../Release/MQCore_MemoryCache.lib") #endif #endif #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/Makefile b/XEngine_Source/XEngine_MQServiceApp/Makefile index cfa2922..21f212f 100644 --- a/XEngine_Source/XEngine_MQServiceApp/Makefile +++ b/XEngine_Source/XEngine_MQServiceApp/Makefile @@ -4,10 +4,10 @@ PLATVER = PLATDIR = RELEASE = 0 LOADHDR = -I ./ -LOADSO = -L ../MQCore_ConfigModule -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule -L ../MQCore_DBModule \ +LOADSO = -L ../MQCore_ConfigModule -L ../MQCore_ProtocolModule -L ../MQCore_SessionModule -L ../MQCore_MemoryCache -L ../MQCore_DBModule \ -L ../XEngine_Depend/XEngine_Module/jsoncpp -L ../XEngine_Depend/XEngine_Module/XEngine_InfoReport LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXClient_APIHelp -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_WSProtocol -lRfcComponents_HttpProtocol -lRfcComponents_MQTTProtocol \ - -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule -lMQCore_DBModule \ + -lMQCore_ConfigModule -lMQCore_ProtocolModule -lMQCore_SessionModule -lMQCore_MemoryCache -lMQCore_DBModule \ -ljsoncpp -lXEngine_InfoReport LIBEX = OBJECTS = MQService_Net.o MQService_Config.o MQService_TCPTask.o MQService_HttpTask.o MQService_WSTask.o MQService_Task.o MQService_MQTTTask.o XEngine_MQServiceApp.o diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index 69bb3fb..a14ade7 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -44,6 +44,7 @@ void ServiceApp_Stop(int signo) DBModule_MQData_Destory(); DBModule_MQUser_Destory(); + MemoryCache_DBData_Destory(); SessionModule_Client_Destory(); HelpComponents_XLog_Destroy(xhLog); @@ -165,9 +166,23 @@ int main(int argc, char** argv) signal(SIGABRT, ServiceApp_Stop); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化服务器信号管理成功")); + if (st_ServiceCfg.st_XMemory.bEnable) + { + if (!MemoryCache_DBData_Init(st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化高速缓存服务失败,错误:%lX"), MemoryCache_GetLastError()); + goto NETSERVICEEXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化高速缓存服务成功,更新最大时间:%d,存储最大时间:%d"), st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,检测到没有启用高速缓存服务"), st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart); + } + if (!bIsTest) { - if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql)) + if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql, st_ServiceCfg.st_XMemory.bEnable)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化消息数据数据库失败,错误:%lX"), DBModule_GetLastError()); goto NETSERVICEEXIT; @@ -419,6 +434,7 @@ int main(int argc, char** argv) DBModule_MQData_Destory(); DBModule_MQUser_Destory(); + MemoryCache_DBData_Destory(); SessionModule_Client_Destory(); HelpComponents_XLog_Destroy(xhLog); From 4961cf7d05c221488e3911c98d1314c00257a48a Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Mon, 25 Nov 2024 14:24:28 +0800 Subject: [PATCH 15/22] fixed:release workflows/msbuild.yml --- .github/workflows/msbuild.yml | 11 +++++------ XEngine_Source/{VSCopy-x64.bat => VSCopy_x64.bat} | 0 XEngine_Source/{VSCopy-x86.bat => VSCopy_x86.bat} | 0 3 files changed, 5 insertions(+), 6 deletions(-) rename XEngine_Source/{VSCopy-x64.bat => VSCopy_x64.bat} (100%) rename XEngine_Source/{VSCopy-x86.bat => VSCopy_x86.bat} (100%) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 9963974..74b2777 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -63,18 +63,17 @@ jobs: cp -r XEngine_Source/Release/*.exe XEngine_Release/ cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ cd XEngine_Release - ./VSCopy-x86.bat + ./VSCopy_x86.bat ./XEngine_MQServiceApp.exe -t shell: pwsh - name: Conditional Step for x86 Debug - if: matrix.configuration == 'Debug' && matrix.platform == 'x86' + if: matrix.configuration == 'Release' && matrix.platform == 'x64' run: | - cp -r XEngine_Source/Debug/*.dll XEngine_Release/ - cp -r XEngine_Source/Debug/*.exe XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.dll XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.exe XEngine_Release/ cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ cd XEngine_Release - ./VSCopy-x86.bat - ./XEngine_MQServiceApp.exe -t + ./VSCopy_x64.bat shell: pwsh - name: Upload folder as artifact with x86 diff --git a/XEngine_Source/VSCopy-x64.bat b/XEngine_Source/VSCopy_x64.bat similarity index 100% rename from XEngine_Source/VSCopy-x64.bat rename to XEngine_Source/VSCopy_x64.bat diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy_x86.bat similarity index 100% rename from XEngine_Source/VSCopy-x86.bat rename to XEngine_Source/VSCopy_x86.bat From 53e304f9cb4d5d07d5aedc67f29a7a55ec114d2d Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Mon, 25 Nov 2024 14:51:11 +0800 Subject: [PATCH 16/22] fixed:copy file workflows/msbuild.yml --- .github/workflows/msbuild.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 74b2777..dea86cb 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -61,7 +61,7 @@ jobs: run: | cp -r XEngine_Source/Release/*.dll XEngine_Release/ cp -r XEngine_Source/Release/*.exe XEngine_Release/ - cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ + cp -r XEngine_Source/VSCopy_x86.bat XEngine_Release/ cd XEngine_Release ./VSCopy_x86.bat ./XEngine_MQServiceApp.exe -t @@ -71,7 +71,7 @@ jobs: run: | cp -r XEngine_Source/x64/Release/*.dll XEngine_Release/ cp -r XEngine_Source/x64/Release/*.exe XEngine_Release/ - cp -r XEngine_Source/VSCopy-x86.bat XEngine_Release/ + cp -r XEngine_Source/VSCopy_x64.bat XEngine_Release/ cd XEngine_Release ./VSCopy_x64.bat shell: pwsh From 0758b3d757c7917cc2dfe2a872a9ca44acb00fb5 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Mon, 25 Nov 2024 15:20:46 +0800 Subject: [PATCH 17/22] modify:delete table to clear cache supported --- .../DBModule_MQData/DBModule_MQData.cpp | 9 +++++ .../MemoryCache_DBData/MemoryCache_DBData.cpp | 35 ++++++++++++++----- .../MemoryCache_DBData/MemoryCache_DBData.h | 1 - 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp index faf2cb4..350f797 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp @@ -602,6 +602,15 @@ bool CDBModule_MQData::DBModule_MQData_DeleteTable(LPCXSTR lpszQueueName) DBModule_dwErrorCode = DataBase_GetLastError(); return false; } + + if (m_bMemoryCache) + { + XENGINE_DBMESSAGEQUEUE st_MessageQueue = {}; + + st_MessageQueue.nQueueSerial = -1; + _tcsxcpy(st_MessageQueue.tszQueueName, lpszQueueName); + MemoryCache_DBData_DataDelete(&st_MessageQueue); + } return true; } /******************************************************************** diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp index 9092587..c7117f0 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -184,18 +184,35 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* return false; } - std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); - st_LockerQuery.lock(); - auto stl_MapIterator = stl_MapQuery.find(stl_Key); - if (stl_MapIterator == stl_MapQuery.end()) + if (-1 == pSt_DBMessageInfo->nQueueSerial) { - MemoryCache_IsErrorOccur = true; - MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; - st_LockerQuery.unlock(); - return false; + for (auto stl_MapIterator = stl_MapQuery.begin(); stl_MapIterator != stl_MapQuery.end(); ) + { + if (std::get<1>((stl_MapIterator->first)) == pSt_DBMessageInfo->tszQueueName) + { + stl_MapIterator = stl_MapQuery.erase(stl_MapIterator); + } + else + { + stl_MapIterator++; + } + } + } + else + { + std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); + + auto stl_MapIterator = stl_MapQuery.find(stl_Key); + if (stl_MapIterator == stl_MapQuery.end()) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; + st_LockerQuery.unlock(); + return false; + } + stl_MapQuery.erase(stl_Key); } - stl_MapQuery.erase(stl_Key); st_LockerQuery.unlock(); return true; } diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h index a0c1e3a..170dfdc 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h @@ -24,7 +24,6 @@ struct TupleHash { return std::apply([](auto&&... args) { - // 使用std::hash对每个元素分别哈希并组合结果 std::size_t seed = 0; ((seed ^= std::hash>()(args) + 0x9e3779b9 + (seed << 6) + (seed >> 2)), ...); return seed; From 7381e5c5e849bb11344812737122b8a04c06fe4c Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 26 Nov 2024 11:31:01 +0800 Subject: [PATCH 18/22] improved:delete memory cache index --- .../MemoryCache_DBData/MemoryCache_DBData.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp index c7117f0..325671c 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -202,16 +202,11 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* else { std::tuple<__int64x, std::string> stl_Key(pSt_DBMessageInfo->nQueueSerial, pSt_DBMessageInfo->tszQueueName); - auto stl_MapIterator = stl_MapQuery.find(stl_Key); - if (stl_MapIterator == stl_MapQuery.end()) + if (stl_MapIterator != stl_MapQuery.end()) { - MemoryCache_IsErrorOccur = true; - MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_NOTFOUND; - st_LockerQuery.unlock(); - return false; + stl_MapQuery.erase(stl_Key); } - stl_MapQuery.erase(stl_Key); } st_LockerQuery.unlock(); return true; From 06f0d4d01fd1245956e17f8b63c08492539b5040 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 28 Nov 2024 15:55:29 +0800 Subject: [PATCH 19/22] added:data insert memory-cache and switch supported --- .../XEngine_Config/XEngine_Config.json | 3 +- .../MQCore_ConfigModule/Config_Define.h | 3 +- .../Config_Json/Config_Json.cpp | 5 +- .../MQCore_DBModule/DBModule_Define.h | 11 ++- .../DBModule_MQData/DBModule_MQData.cpp | 47 +++++++--- .../DBModule_MQData/DBModule_MQData.h | 5 +- XEngine_Source/MQCore_DBModule/pch.cpp | 4 +- .../MQCore_MemoryCache/MQCore_MemoryCache.def | 4 +- .../MemoryCache_DBData/MemoryCache_DBData.cpp | 94 ++++++++++++++++++- .../MemoryCache_DBData/MemoryCache_DBData.h | 8 +- .../MQCore_MemoryCache/MemoryCache_Define.h | 30 +++++- XEngine_Source/MQCore_MemoryCache/pch.cpp | 8 ++ XEngine_Source/MQCore_MemoryCache/pch.h | 6 +- .../XEngine_MQServiceApp.cpp | 4 +- 14 files changed, 195 insertions(+), 37 deletions(-) diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index 0e40c31..e271651 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -35,7 +35,8 @@ "tszPassLogout":"" }, "XMemory":{ - "bEnable":true, + "bDataQueryEnable":true, + "bDataInsertEnable":true, "nTimeLast":3600, "nTimeStart":0 }, diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Define.h b/XEngine_Source/MQCore_ConfigModule/Config_Define.h index 5a8eec7..9636b4c 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Define.h +++ b/XEngine_Source/MQCore_ConfigModule/Config_Define.h @@ -57,7 +57,8 @@ typedef struct }st_XPass; struct { - bool bEnable; + bool bDataQueryEnable; + bool bDataInsertEnable; int nTimeLast; int nTimeStart; }st_XMemory; diff --git a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp index d66eb91..7cf026c 100644 --- a/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp +++ b/XEngine_Source/MQCore_ConfigModule/Config_Json/Config_Json.cpp @@ -123,14 +123,15 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile,XENGINE_SERVERCONFIG _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassRegister, st_JsonXPass["tszPassRegister"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XPass.tszPassUNReg, st_JsonXPass["tszPassUNReg"].asCString()); - if (st_JsonRoot["XMemory"].empty() || (3 != st_JsonRoot["XMemory"].size())) + if (st_JsonRoot["XMemory"].empty() || (4 != st_JsonRoot["XMemory"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MQ_MODULE_CONFIG_JSON_XMEMORY; return false; } Json::Value st_JsonXMemory = st_JsonRoot["XMemory"]; - pSt_ServerConfig->st_XMemory.bEnable = st_JsonXMemory["bEnable"].asBool(); + pSt_ServerConfig->st_XMemory.bDataQueryEnable = st_JsonXMemory["bDataQueryEnable"].asBool(); + pSt_ServerConfig->st_XMemory.bDataInsertEnable = st_JsonXMemory["bDataInsertEnable"].asBool(); pSt_ServerConfig->st_XMemory.nTimeLast = st_JsonXMemory["nTimeLast"].asInt(); pSt_ServerConfig->st_XMemory.nTimeStart = st_JsonXMemory["nTimeStart"].asInt(); diff --git a/XEngine_Source/MQCore_DBModule/DBModule_Define.h b/XEngine_Source/MQCore_DBModule/DBModule_Define.h index 911c403..7e1377e 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_Define.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_Define.h @@ -71,17 +71,22 @@ extern "C" XLONG DBModule_GetLastError(int *pInt_SysError = NULL); 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 - 参数.二:bMemoryCache + 参数.二:bMemoryQuery In/Out:In 类型:逻辑型 可空:Y - 意思:是否启用缓存支持 + 意思:是否启用查询缓存支持 + 参数.三:bMemoryInsert + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用插入缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache = true); +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery = true, bool bMemoryInsert = true); /******************************************************************** 函数名称:DBModule_MQData_Destory 函数功能:销毁数据库管理器 diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp index 350f797..bfb2083 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp @@ -30,17 +30,22 @@ CDBModule_MQData::~CDBModule_MQData() 类型:数据结构指针 可空:N 意思:数据MYSQL数据库连接信息 - 参数.二:bMemoryCache + 参数.二:bMemoryQuery In/Out:In 类型:逻辑型 可空:Y - 意思:是否启用缓存支持 + 意思:是否启用查询缓存支持 + 参数.三:bMemoryInsert + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否启用插入缓存支持 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache) +bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery /* = true */, bool bMemoryInsert /* = true */) { DBModule_IsErrorOccur = false; @@ -50,7 +55,8 @@ bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBCo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_PARAMENT; return false; } - m_bMemoryCache = bMemoryCache; + m_bMemoryQuery = bMemoryQuery; + m_bMemoryInsert = bMemoryInsert; //连接数据库 _tcsxcpy(pSt_DBConnector->tszDBName, _X("XEngine_MQData")); if (!DataBase_MySQL_Connect(&xhDBSQL, pSt_DBConnector)) @@ -59,6 +65,10 @@ bool CDBModule_MQData::DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBCo DBModule_dwErrorCode = DataBase_GetLastError(); return false; } + if (m_bMemoryInsert) + { + MemoryCache_DBData_SetHandle(xhDBSQL); + } return true; } /******************************************************************** @@ -115,13 +125,20 @@ bool CDBModule_MQData::DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo memcpy(tszSQLStatement + nRet, tszSQLCoder, nLen); nRet += nLen; - if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement, &nRet)) - { - DBModule_IsErrorOccur = true; - DBModule_dwErrorCode = DataBase_GetLastError(); - return false; - } - if (m_bMemoryCache) + if (m_bMemoryInsert) + { + MemoryCache_DBData_QueueInsert(tszSQLStatement); + } + else + { + if (!DataBase_MySQL_Execute(xhDBSQL, tszSQLStatement, &nRet)) + { + DBModule_IsErrorOccur = true; + DBModule_dwErrorCode = DataBase_GetLastError(); + return false; + } + } + if (m_bMemoryQuery) { MemoryCache_DBData_DataInsert(pSt_DBInfo); } @@ -151,7 +168,7 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) return false; } - if (m_bMemoryCache) + if (m_bMemoryQuery) { if (MemoryCache_DBData_DataQuery(pSt_DBInfo)) { @@ -235,7 +252,7 @@ bool CDBModule_MQData::DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo) } DataBase_MySQL_FreeResult(xhDBSQL, xhTable); - if (m_bMemoryCache) + if (m_bMemoryQuery) { MemoryCache_DBData_DataInsert(pSt_DBInfo); } @@ -293,7 +310,7 @@ bool CDBModule_MQData::DBModule_MQData_Modify(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo DBModule_dwErrorCode = ERROR_XENGINE_MQCORE_DATABASE_NOTFOUND; return false; } - if (m_bMemoryCache) + if (m_bMemoryQuery) { MemoryCache_DBData_DataInsert(pSt_DBInfo); } @@ -603,7 +620,7 @@ bool CDBModule_MQData::DBModule_MQData_DeleteTable(LPCXSTR lpszQueueName) return false; } - if (m_bMemoryCache) + if (m_bMemoryQuery) { XENGINE_DBMESSAGEQUEUE st_MessageQueue = {}; diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h index dca3ac9..18c696b 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.h @@ -17,7 +17,7 @@ class CDBModule_MQData CDBModule_MQData(); ~CDBModule_MQData(); public: - bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryCache = true); + bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bMemoryQuery = true, bool bMemoryInsert = true); bool DBModule_MQData_Destory(); bool DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); bool DBModule_MQData_Query(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo); @@ -29,6 +29,7 @@ class CDBModule_MQData bool DBModule_MQData_ShowTable(XCHAR*** pppszTableName, int* pInt_ListCount); bool DBModule_MQData_GetLeftCount(LPCXSTR lpszTableName, int nSerial, int* pInt_Count); private: - bool m_bMemoryCache = false; + bool m_bMemoryQuery = false; + bool m_bMemoryInsert = false; XNETHANDLE xhDBSQL = 0; }; \ No newline at end of file diff --git a/XEngine_Source/MQCore_DBModule/pch.cpp b/XEngine_Source/MQCore_DBModule/pch.cpp index 87050c7..a2707e4 100644 --- a/XEngine_Source/MQCore_DBModule/pch.cpp +++ b/XEngine_Source/MQCore_DBModule/pch.cpp @@ -31,9 +31,9 @@ extern "C" XLONG DBModule_GetLastError(int* pInt_SysError) /************************************************************************* 消息队列导出函数 **************************************************************************/ -extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector, bool bMemoryCache) +extern "C" bool DBModule_MQData_Init(DATABASE_MYSQL_CONNECTINFO * pSt_DBConnector, bool bMemoryQuery, bool bMemoryInsert) { - return m_DBData.DBModule_MQData_Init(pSt_DBConnector, bMemoryCache); + return m_DBData.DBModule_MQData_Init(pSt_DBConnector, bMemoryQuery, bMemoryInsert); } extern "C" bool DBModule_MQData_Destory() { diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def index f04e829..a5881ce 100644 --- a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.def @@ -4,7 +4,9 @@ EXPORTS MemoryCache_GetLastError MemoryCache_DBData_Init + MemoryCache_DBData_SetHandle MemoryCache_DBData_Destory MemoryCache_DBData_DataInsert MemoryCache_DBData_DataQuery - MemoryCache_DBData_DataDelete \ No newline at end of file + MemoryCache_DBData_DataDelete + MemoryCache_DBData_QueueInsert \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp index 325671c..95a18c8 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -39,17 +39,25 @@ CMemoryCache_DBData::~CMemoryCache_DBData() 意思:是否成功 备注: *********************************************************************/ -bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) +bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast /* = 3600 */, int nTimeStart /* = 0 */) { MemoryCache_IsErrorOccur = false; bIsRun = true; + m_nTimeLast = nTimeLast; m_nTimeStart = nTimeStart; - pSTDThread = std::make_unique(DBModule_MQUser_TimeThread, this); - if (NULL == pSTDThread) + pSTDThread_Query = std::make_unique(DBModule_MQUser_TimeThread, this); + if (NULL == pSTDThread_Query) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD; + return false; + } + pSTDThread_Insert = std::make_unique(DBModule_MQUser_InsertThread, this); + if (NULL == pSTDThread_Insert) { MemoryCache_IsErrorOccur = true; MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD; @@ -58,6 +66,27 @@ bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) return true; } /******************************************************************** +函数名称:MemoryCache_DBData_SetHandle +函数功能:设置句柄 + 参数.一:xhDBSQL + In/Out:In + 类型:句柄 + 可空:N + 意思:数据库句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL) +{ + MemoryCache_IsErrorOccur = false; + + m_xhDBSQL = xhDBSQL; + + return true; +} +/******************************************************************** 函数名称:MemoryCache_DBData_Destory 函数功能:销毁高速缓存管理器 返回值 @@ -70,9 +99,13 @@ bool CMemoryCache_DBData::MemoryCache_DBData_Destory() MemoryCache_IsErrorOccur = false; bIsRun = false; - if (NULL != pSTDThread) + if (NULL != pSTDThread_Query) + { + pSTDThread_Query->join(); + } + if (NULL != pSTDThread_Insert) { - pSTDThread->join(); + pSTDThread_Insert->join(); } return true; } @@ -211,6 +244,35 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* st_LockerQuery.unlock(); return true; } +/******************************************************************** +函数名称:MemoryCache_DBData_QueueInsert +函数功能:队列插入工具 + 参数.一:lpszSQLStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的语句 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr) +{ + MemoryCache_IsErrorOccur = false; + + if (NULL == lpszSQLStr) + { + MemoryCache_IsErrorOccur = true; + MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; + return false; + } + + st_LockerList.lock(); + stl_ListInsert.push_back(lpszSQLStr); + st_LockerList.unlock(); + return true; +} ////////////////////////////////////////////////////////////////////////// // 线程函数 ////////////////////////////////////////////////////////////////////////// @@ -244,4 +306,26 @@ XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_TimeThread(XPVOID lParam) std::this_thread::sleep_for(std::chrono::seconds(1)); } return 0; +} +XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_InsertThread(XPVOID lParam) +{ + CMemoryCache_DBData* pClass_This = (CMemoryCache_DBData*)lParam; + + while (pClass_This->bIsRun) + { + if (!pClass_This->stl_ListInsert.empty()) + { + pClass_This->st_LockerList.lock(); + std::string m_StrSQLInsert = pClass_This->stl_ListInsert.front(); + pClass_This->stl_ListInsert.pop_front(); + pClass_This->st_LockerList.unlock(); + + if (!DataBase_MySQL_Execute(pClass_This->m_xhDBSQL, m_StrSQLInsert.c_str())) + { + + } + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + return 0; } \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h index 170dfdc..cfa211e 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h @@ -38,21 +38,27 @@ class CMemoryCache_DBData ~CMemoryCache_DBData(); public: bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); + bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL); bool MemoryCache_DBData_Destory(); public: bool MemoryCache_DBData_DataInsert(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +public: + bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr); protected: static XHTHREAD CALLBACK DBModule_MQUser_TimeThread(XPVOID lParam); + static XHTHREAD CALLBACK DBModule_MQUser_InsertThread(XPVOID lParam); private: bool bIsRun = false; int m_nTimeLast = 0; int m_nTimeStart = 0; + XNETHANDLE m_xhDBSQL = 0; private: std::shared_mutex st_LockerList; std::shared_mutex st_LockerQuery; - std::unique_ptr pSTDThread; + std::unique_ptr pSTDThread_Query; + std::unique_ptr pSTDThread_Insert; private: std::list stl_ListInsert; std::unordered_map, MEMORYCACHE_DBINFO, TupleHash> stl_MapQuery; diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h index 4da763f..ff5769d 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h @@ -37,6 +37,20 @@ extern "C" XLONG MemoryCache_GetLastError(int *pInt_SysError = NULL); *********************************************************************/ extern "C" bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); /******************************************************************** +函数名称:MemoryCache_DBData_SetHandle +函数功能:设置句柄 + 参数.一:xhDBSQL + In/Out:In + 类型:句柄 + 可空:N + 意思:数据库句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL); +/******************************************************************** 函数名称:MemoryCache_DBData_Destory 函数功能:销毁高速缓存管理器 返回值 @@ -86,4 +100,18 @@ extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessa 意思:是否成功 备注: *********************************************************************/ -extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); \ No newline at end of file +extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); +/******************************************************************** +函数名称:MemoryCache_DBData_QueueInsert +函数功能:队列插入工具 + 参数.一:lpszSQLStr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的语句 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr); \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/pch.cpp b/XEngine_Source/MQCore_MemoryCache/pch.cpp index f830df4..d56a702 100644 --- a/XEngine_Source/MQCore_MemoryCache/pch.cpp +++ b/XEngine_Source/MQCore_MemoryCache/pch.cpp @@ -33,6 +33,10 @@ extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) { return m_MemoryDBData.MemoryCache_DBData_Init(nTimeLast, nTimeStart); } +extern "C" bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL) +{ + return m_MemoryDBData.MemoryCache_DBData_SetHandle(xhDBSQL); +} extern "C" bool MemoryCache_DBData_Destory() { return m_MemoryDBData.MemoryCache_DBData_Destory(); @@ -48,4 +52,8 @@ extern "C" bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessa extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) { return m_MemoryDBData.MemoryCache_DBData_DataDelete(pSt_DBMessageInfo); +} +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr) +{ + return m_MemoryDBData.MemoryCache_DBData_QueueInsert(lpszSQLStr); } \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/pch.h b/XEngine_Source/MQCore_MemoryCache/pch.h index d03194b..81e84e2 100644 --- a/XEngine_Source/MQCore_MemoryCache/pch.h +++ b/XEngine_Source/MQCore_MemoryCache/pch.h @@ -43,4 +43,8 @@ // History: *********************************************************************/ extern bool MemoryCache_IsErrorOccur; -extern XLONG MemoryCache_dwErrorCode; \ No newline at end of file +extern XLONG MemoryCache_dwErrorCode; + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_DataBase.lib") +#endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index a14ade7..864fe33 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -166,7 +166,7 @@ int main(int argc, char** argv) signal(SIGABRT, ServiceApp_Stop); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化服务器信号管理成功")); - if (st_ServiceCfg.st_XMemory.bEnable) + if (st_ServiceCfg.st_XMemory.bDataQueryEnable || st_ServiceCfg.st_XMemory.bDataInsertEnable) { if (!MemoryCache_DBData_Init(st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart)) { @@ -182,7 +182,7 @@ int main(int argc, char** argv) if (!bIsTest) { - if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql, st_ServiceCfg.st_XMemory.bEnable)) + if (!DBModule_MQData_Init((DATABASE_MYSQL_CONNECTINFO*)&st_ServiceCfg.st_XSql, st_ServiceCfg.st_XMemory.bDataQueryEnable, st_ServiceCfg.st_XMemory.bDataInsertEnable)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化消息数据数据库失败,错误:%lX"), DBModule_GetLastError()); goto NETSERVICEEXIT; From 33438dc9a80db120055c6935846cffe4a8a0be41 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 28 Nov 2024 16:03:25 +0800 Subject: [PATCH 20/22] fixed:build error --- XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj | 2 ++ XEngine_Source/MQCore_MemoryCache/Makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj index 981a9f5..de44dfb 100644 --- a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj @@ -76,6 +76,8 @@ $(XEngine_Include);$(IncludePath) + $(ReferencePath) + $(XEngine_Lib32);$(LibraryPath) $(XEngine_Include);$(IncludePath) diff --git a/XEngine_Source/MQCore_MemoryCache/Makefile b/XEngine_Source/MQCore_MemoryCache/Makefile index 8a8a2b6..03b11ce 100644 --- a/XEngine_Source/MQCore_MemoryCache/Makefile +++ b/XEngine_Source/MQCore_MemoryCache/Makefile @@ -7,7 +7,7 @@ LIBFLAG = RELEASE = 0 LOADHDR = -I ./ LOADSO = -LIB = +LIB = -lHelpComponents_DataBase LIBEX = OBJECTS = MemoryCache_DBData.o pch.o From 771a0a67641e2b9ef850722b82123b3171339db7 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 28 Nov 2024 16:28:20 +0800 Subject: [PATCH 21/22] added:more information print for callback of memory-cache --- .../DBModule_MQData/DBModule_MQData.cpp | 2 +- .../MQCore_MemoryCache.vcxproj | 2 + .../MemoryCache_DBData/MemoryCache_DBData.cpp | 39 ++++++++++++++----- .../MemoryCache_DBData/MemoryCache_DBData.h | 14 +++++-- .../MQCore_MemoryCache/MemoryCache_Define.h | 18 ++++++++- XEngine_Source/MQCore_MemoryCache/pch.cpp | 8 ++-- .../XEngine_MQServiceApp/MQService_Task.cpp | 25 ++++++++++++ .../XEngine_MQServiceApp/MQService_Task.h | 3 +- .../XEngine_MQServiceApp.cpp | 2 +- 9 files changed, 92 insertions(+), 21 deletions(-) diff --git a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp index bfb2083..a4d373e 100644 --- a/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp +++ b/XEngine_Source/MQCore_DBModule/DBModule_MQData/DBModule_MQData.cpp @@ -127,7 +127,7 @@ bool CDBModule_MQData::DBModule_MQData_Insert(XENGINE_DBMESSAGEQUEUE* pSt_DBInfo if (m_bMemoryInsert) { - MemoryCache_DBData_QueueInsert(tszSQLStatement); + MemoryCache_DBData_QueueInsert(tszSQLStatement, pSt_DBInfo); } else { diff --git a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj index de44dfb..49b13b3 100644 --- a/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj +++ b/XEngine_Source/MQCore_MemoryCache/MQCore_MemoryCache.vcxproj @@ -81,9 +81,11 @@ $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp index 95a18c8..772a61f 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.cpp @@ -39,15 +39,16 @@ CMemoryCache_DBData::~CMemoryCache_DBData() 意思:是否成功 备注: *********************************************************************/ -bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast /* = 3600 */, int nTimeStart /* = 0 */) +bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam /* = NULL */) { MemoryCache_IsErrorOccur = false; bIsRun = true; - m_nTimeLast = nTimeLast; m_nTimeStart = nTimeStart; + m_lParam = lParam; + lpCall_MemoryCache = fpCall_MemoryCache; pSTDThread_Query = std::make_unique(DBModule_MQUser_TimeThread, this); if (NULL == pSTDThread_Query) @@ -252,12 +253,17 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* 类型:常量字符指针 可空:N 意思:输入要插入的语句 + 参数.二:pSt_DBMessageInfo + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的数据 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr) +bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) { MemoryCache_IsErrorOccur = false; @@ -267,9 +273,13 @@ bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr) MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT; return false; } + MEMORYCACHE_DBINSERT st_DBInsert = {}; + + st_DBInsert.m_StrSQL = lpszSQLStr; + st_DBInsert.st_DBMessageInfo = *pSt_DBMessageInfo; st_LockerList.lock(); - stl_ListInsert.push_back(lpszSQLStr); + stl_ListInsert.push_back(st_DBInsert); st_LockerList.unlock(); return true; } @@ -301,7 +311,14 @@ XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_TimeThread(XPVOID lParam) for (auto stl_ListIterator = stl_ListDelete.begin(); stl_ListIterator != stl_ListDelete.end(); stl_ListIterator++) { XENGINE_DBMESSAGEQUEUE st_DBMessage = *stl_ListIterator; - pClass_This->MemoryCache_DBData_DataDelete(&st_DBMessage); + if (pClass_This->MemoryCache_DBData_DataDelete(&st_DBMessage)) + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY, true, pClass_This->stl_ListInsert.size(), &st_DBMessage, pClass_This->m_lParam); + } + else + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY, false, pClass_This->stl_ListInsert.size(), &st_DBMessage, pClass_This->m_lParam); + } } std::this_thread::sleep_for(std::chrono::seconds(1)); } @@ -316,16 +333,20 @@ XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_InsertThread(XPVOID lPara if (!pClass_This->stl_ListInsert.empty()) { pClass_This->st_LockerList.lock(); - std::string m_StrSQLInsert = pClass_This->stl_ListInsert.front(); + MEMORYCACHE_DBINSERT st_DBInsert = pClass_This->stl_ListInsert.front(); pClass_This->stl_ListInsert.pop_front(); pClass_This->st_LockerList.unlock(); - if (!DataBase_MySQL_Execute(pClass_This->m_xhDBSQL, m_StrSQLInsert.c_str())) + if (DataBase_MySQL_Execute(pClass_This->m_xhDBSQL, st_DBInsert.m_StrSQL.c_str())) { - + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT, true, pClass_This->stl_ListInsert.size(), &st_DBInsert.st_DBMessageInfo, pClass_This->m_lParam); + } + else + { + pClass_This->lpCall_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT, false, pClass_This->stl_ListInsert.size(), &st_DBInsert.st_DBMessageInfo, pClass_This->m_lParam); } } - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } return 0; } \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h index cfa211e..09ecd58 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_DBData/MemoryCache_DBData.h @@ -16,6 +16,11 @@ typedef struct time_t nTimeStart; time_t nTimeLast; }MEMORYCACHE_DBINFO; +typedef struct +{ + XENGINE_DBMESSAGEQUEUE st_DBMessageInfo; + std::string m_StrSQL; +}MEMORYCACHE_DBINSERT; struct TupleHash { @@ -37,7 +42,7 @@ class CMemoryCache_DBData CMemoryCache_DBData(); ~CMemoryCache_DBData(); public: - bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); + bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam = NULL); bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL); bool MemoryCache_DBData_Destory(); public: @@ -45,7 +50,7 @@ class CMemoryCache_DBData bool MemoryCache_DBData_DataQuery(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); public: - bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr); + bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); protected: static XHTHREAD CALLBACK DBModule_MQUser_TimeThread(XPVOID lParam); static XHTHREAD CALLBACK DBModule_MQUser_InsertThread(XPVOID lParam); @@ -54,12 +59,15 @@ class CMemoryCache_DBData int m_nTimeLast = 0; int m_nTimeStart = 0; XNETHANDLE m_xhDBSQL = 0; + + XPVOID m_lParam; + CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE lpCall_MemoryCache; private: std::shared_mutex st_LockerList; std::shared_mutex st_LockerQuery; std::unique_ptr pSTDThread_Query; std::unique_ptr pSTDThread_Insert; private: - std::list stl_ListInsert; + std::list stl_ListInsert; std::unordered_map, MEMORYCACHE_DBINFO, TupleHash> stl_MapQuery; }; \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h index ff5769d..98d6b74 100644 --- a/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h +++ b/XEngine_Source/MQCore_MemoryCache/MemoryCache_Define.h @@ -10,6 +10,15 @@ // Purpose: 导出的函数 // History: *********************************************************************/ +typedef enum +{ + ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY = 0, + ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT = 1 +}ENUM_MEMORYCACHE_CALLBACK_TYPE; +////////////////////////////////////////////////////////////////////////// +// 导出的回调 +////////////////////////////////////////////////////////////////////////// +typedef void(CALLBACK* CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE)(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam); ////////////////////////////////////////////////////////////////////////// // 导出的函数 ////////////////////////////////////////////////////////////////////////// @@ -35,7 +44,7 @@ extern "C" XLONG MemoryCache_GetLastError(int *pInt_SysError = NULL); 意思:是否成功 备注: *********************************************************************/ -extern "C" bool MemoryCache_DBData_Init(int nTimeLast = 3600, int nTimeStart = 0); +extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam = NULL); /******************************************************************** 函数名称:MemoryCache_DBData_SetHandle 函数功能:设置句柄 @@ -109,9 +118,14 @@ extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMess 类型:常量字符指针 可空:N 意思:输入要插入的语句 + 参数.二:pSt_DBMessageInfo + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的数据 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr); \ No newline at end of file +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo); \ No newline at end of file diff --git a/XEngine_Source/MQCore_MemoryCache/pch.cpp b/XEngine_Source/MQCore_MemoryCache/pch.cpp index d56a702..fe28202 100644 --- a/XEngine_Source/MQCore_MemoryCache/pch.cpp +++ b/XEngine_Source/MQCore_MemoryCache/pch.cpp @@ -29,9 +29,9 @@ extern "C" XLONG MemoryCache_GetLastError(int* pInt_SysError) /************************************************************************* 高速缓存导出函数 **************************************************************************/ -extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart) +extern "C" bool MemoryCache_DBData_Init(int nTimeLast, int nTimeStart, CALLBACK_MESSAGEQUEUE_MODULE_DATABASE_CACHE fpCall_MemoryCache, XPVOID lParam) { - return m_MemoryDBData.MemoryCache_DBData_Init(nTimeLast, nTimeStart); + return m_MemoryDBData.MemoryCache_DBData_Init(nTimeLast, nTimeStart, fpCall_MemoryCache, lParam); } extern "C" bool MemoryCache_DBData_SetHandle(XNETHANDLE xhDBSQL) { @@ -53,7 +53,7 @@ extern "C" bool MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE* pSt_DBMess { return m_MemoryDBData.MemoryCache_DBData_DataDelete(pSt_DBMessageInfo); } -extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr) +extern "C" bool MemoryCache_DBData_QueueInsert(LPCXSTR lpszSQLStr, XENGINE_DBMESSAGEQUEUE* pSt_DBMessageInfo) { - return m_MemoryDBData.MemoryCache_DBData_QueueInsert(lpszSQLStr); + return m_MemoryDBData.MemoryCache_DBData_QueueInsert(lpszSQLStr, pSt_DBMessageInfo); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp index 37e90ab..d70bfcb 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.cpp @@ -60,4 +60,29 @@ void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, DBModule_MQUser_TimeUPDate(pSt_DBInfo); } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("定时任务,消息主题:%s,序列:%lld,定时任务分发成功,客户端个数:%d"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nIDMsg, nListCount); +} +void CALLBACK MessageQueue_CBTask_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam) +{ + if (ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_QUERY == enMemoryType) + { + if (bSuccess) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("高速缓存,消息主题:%s,序列:%lld,删除过期缓存成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("高速缓存,消息主题:%s,序列:%lld,删除过期缓存成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + } + else if (ENUM_MEMORYCACHE_CALLBACK_TYPE_DATA_INSERT == enMemoryType) + { + if (bSuccess) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("高速缓存,消息主题:%s,序列:%lld,插入缓存队列到数据库成功,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("高速缓存,消息主题:%s,序列:%lld,插入缓存队列到数据库失败,缓存剩余队列:%ld"), pSt_DBInfo->tszQueueName, pSt_DBInfo->nQueueSerial, nListCount); + } + } } \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h index 2c29218..b92c117 100644 --- a/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h +++ b/XEngine_Source/XEngine_MQServiceApp/MQService_Task.h @@ -1,3 +1,4 @@ #pragma once -void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, XPVOID lParam); \ No newline at end of file +void CALLBACK MessageQueue_CBTask_TimePublish(XENGINE_DBTIMERELEASE* pSt_DBInfo, XPVOID lParam); +void CALLBACK MessageQueue_CBTask_MemoryCache(ENUM_MEMORYCACHE_CALLBACK_TYPE enMemoryType, bool bSuccess, size_t nListCount, XENGINE_DBMESSAGEQUEUE* pSt_DBInfo, XPVOID lParam); \ No newline at end of file diff --git a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp index 864fe33..d5a0f4b 100644 --- a/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp +++ b/XEngine_Source/XEngine_MQServiceApp/XEngine_MQServiceApp.cpp @@ -168,7 +168,7 @@ int main(int argc, char** argv) if (st_ServiceCfg.st_XMemory.bDataQueryEnable || st_ServiceCfg.st_XMemory.bDataInsertEnable) { - if (!MemoryCache_DBData_Init(st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart)) + if (!MemoryCache_DBData_Init(st_ServiceCfg.st_XMemory.nTimeLast, st_ServiceCfg.st_XMemory.nTimeStart, MessageQueue_CBTask_MemoryCache)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化高速缓存服务失败,错误:%lX"), MemoryCache_GetLastError()); goto NETSERVICEEXIT; From 278c4589bf7fef6f5b242229b1cefd0409d77c84 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Fri, 29 Nov 2024 10:25:24 +0800 Subject: [PATCH 22/22] update:release and configure --- CHANGELOG | 20 +++++++++++++++++++ README.en.md | 1 + README.md | 1 + .../XEngine_Config/XEngine_VerConfig.json | 1 + 4 files changed, 23 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 81606a6..abf0fa7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,23 @@ +XEngine_MQService V3.13.0.1001 + +增加:为DATA消息数据库增加高速缓存支持 +增加:coredump的windows支持 +更新:工作流自动发布支持 +更新:依赖库 +优化:启动参数解析 +修正:某些时候退出崩溃问题 +修正:发布消息时候获取在线用户不正确的问题 +修正:通知用户处理问题 + +added:memory cache module for Data DB +added:coredump file support on windows +update:release workflows supported +update:depend library +improved:start parameter parse +fixed:sometime crashed when exist +fixed:get online user is incorrect when publish message +fixed:immediate notify user process is incorrect +====================================================================================== XEngine_MQService V3.12.0.1001 增加:编译CI工作流支持 diff --git a/README.en.md b/README.en.md index bbb9984..7ff4846 100644 --- a/README.en.md +++ b/README.en.md @@ -34,6 +34,7 @@ this software support following features 18. http interface management 19. message attritube 20. point to point message +21. Memory Database ## install diff --git a/README.md b/README.md index f8974e5..adc954b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ c c++Message Service 18. http接口管理 19. 消息属性 20. 点对点消息 +21. 高速缓存 ## 安装教程 diff --git a/XEngine_Release/XEngine_Config/XEngine_VerConfig.json b/XEngine_Release/XEngine_Config/XEngine_VerConfig.json index 38a5d78..09e04b5 100644 --- a/XEngine_Release/XEngine_Config/XEngine_VerConfig.json +++ b/XEngine_Release/XEngine_Config/XEngine_VerConfig.json @@ -1,5 +1,6 @@ { "XVer":[ + "3.13.0.1001 Build20241129", "3.12.0.1001 Build20240919", "3.11.0.1001 Build20240517", "3.10.0.1001 Build20240305",