Skip to content

Commit 5b0c08a

Browse files
committed
fixed:APIHelp_Distributed_RandomAddr mode type incorrent
modify:upload interface support loadbalance mode
1 parent 34c0e58 commit 5b0c08a

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,17 @@ extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGIN
107107
类型:数据结构指针
108108
可空:N
109109
意思:输出获取到的可用存储
110+
参数.三:nMode
111+
In/Out:In
112+
类型:整数型
113+
可空:N
114+
意思:输入选择模式
110115
返回值
111116
类型:逻辑型
112117
意思:是否成功
113118
备注:
114119
*********************************************************************/
115-
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
120+
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode);
116121
/********************************************************************
117122
函数名称:APIHelp_Distributed_GetPathKey
118123
函数功能:通过BUCKET名称查找对应路径

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<string>* pStl_Lis
5757
}
5858

5959
BOOL bFound = FALSE;
60-
if (0 == nMode)
60+
if (1 == nMode)
6161
{
6262
XNETHANDLE xhToken = 0;
6363
BaseLib_OperatorHandle_Create(&xhToken, 0, pStl_ListAddr->size(), FALSE);
@@ -76,18 +76,25 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<string>* pStl_Lis
7676
}
7777
}
7878
}
79-
else if (1 == nMode)
79+
else if (2 == nMode)
8080
{
8181
bFound = TRUE;
8282
_tcscpy(ptszAddr, pStl_ListAddr->front().c_str());
8383
}
84-
else if (2 == nMode)
84+
else if (3 == nMode)
8585
{
8686

8787
bFound = TRUE;
8888
_tcscpy(ptszAddr, pStl_ListAddr->back().c_str());
8989
}
90-
return bFound;
90+
91+
if (!bFound)
92+
{
93+
APIHelp_IsErrorOccur = TRUE;
94+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
95+
return FALSE;
96+
}
97+
return TRUE;
9198
}
9299
/********************************************************************
93100
函数名称:APIHelp_Distributed_FileList
@@ -224,7 +231,7 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer,
224231
意思:是否成功
225232
备注:
226233
*********************************************************************/
227-
BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
234+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode)
228235
{
229236
APIHelp_IsErrorOccur = FALSE;
230237

@@ -234,15 +241,28 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUC
234241
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
235242
return FALSE;
236243
}
237-
BOOL bFound = FALSE;
238-
int nLastLevel = 9999;
244+
int nLastLevel = 99999;
245+
list<XENGINE_STORAGEBUCKET> stl_BuckSelect;
246+
//先得到最小级别
239247
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
240248
{
241249
//只处理启用的
242250
if (stl_ListIterator->bEnable)
243251
{
244-
//处理优先级
245252
if (stl_ListIterator->nLevel < nLastLevel)
253+
{
254+
nLastLevel = stl_ListIterator->nLevel; //得到最小级别
255+
}
256+
}
257+
}
258+
//在来获得这个级别的列表
259+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
260+
{
261+
//只处理启用的
262+
if (stl_ListIterator->bEnable)
263+
{
264+
//处理优先级
265+
if (stl_ListIterator->nLevel == nLastLevel)
246266
{
247267
int nListCount = 0;
248268
__int64u nDirCount = 0; //当前目录大小
@@ -260,18 +280,44 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUC
260280
{
261281
continue;
262282
}
263-
bFound = TRUE;
264-
nLastLevel = stl_ListIterator->nLevel;
265-
*pSt_StorageBucket = *stl_ListIterator;
283+
stl_BuckSelect.push_back(*stl_ListIterator);
266284
}
267285
}
268286
}
269-
if (!bFound)
287+
//通过指定模式获得一个key
288+
if (!stl_BuckSelect.empty())
270289
{
271290
APIHelp_IsErrorOccur = TRUE;
272291
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
273292
return FALSE;
274293
}
294+
if (1 == nMode)
295+
{
296+
XNETHANDLE xhToken = 0;
297+
BaseLib_OperatorHandle_Create(&xhToken, 0, stl_BuckSelect.size(), FALSE);
298+
if (xhToken == stl_BuckSelect.size())
299+
{
300+
xhToken--;
301+
}
302+
list<XENGINE_STORAGEBUCKET>::const_iterator stl_ListIterator = stl_BuckSelect.begin();
303+
for (XNETHANDLE i = 0; stl_ListIterator != stl_BuckSelect.end(); stl_ListIterator++, i++)
304+
{
305+
if (xhToken == i)
306+
{
307+
*pSt_StorageBucket = *stl_ListIterator;
308+
break;
309+
}
310+
}
311+
}
312+
else if (2 == nMode)
313+
{
314+
*pSt_StorageBucket = stl_BuckSelect.front();
315+
}
316+
else if (3 == nMode)
317+
{
318+
*pSt_StorageBucket = stl_BuckSelect.back();
319+
}
320+
275321
return TRUE;
276322
}
277323
/********************************************************************

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CAPIHelp_Distributed
2121
BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr, int nMode);
2222
BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
2323
BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
24-
BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
24+
BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode);
2525
BOOL APIHelp_Distributed_GetPathKey(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR* ptszFilePath);
2626
protected:
2727
BOOL APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE* pSt_DBFile);

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGIN
4343
{
4444
return m_APIDistributed.APIHelp_Distributed_DLStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket);
4545
}
46-
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket)
46+
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket, int nMode)
4747
{
48-
return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket);
48+
return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket, nMode);
4949
}
5050
extern "C" BOOL APIHelp_Distributed_GetPathKey(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR * ptszFilePath)
5151
{

0 commit comments

Comments
 (0)