Skip to content

Commit 3f4f621

Browse files
committed
added:Upload files support specifying bucket or not specifying
1 parent 72c97b2 commit 3f4f621

File tree

5 files changed

+93
-68
lines changed

5 files changed

+93
-68
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,32 @@ extern "C" BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGIN
9797
/********************************************************************
9898
函数名称:APIHelp_Distributed_UPStorage
9999
函数功能:通过分布式存储列表获得一个存储地址
100-
参数.一:pStl_ListBucket
100+
参数.一:lpszMsgBuffer
101+
In/Out:In
102+
类型:常量字符指针
103+
可空:N
104+
意思:输入要解析的URL
105+
参数.二:pStl_ListBucket
101106
In/Out:In
102107
类型:容器指针
103108
可空:N
104109
意思:输入要解析的列表
105-
参数.:pSt_StorageBucket
110+
参数.:pSt_StorageBucket
106111
In/Out:Out
107112
类型:数据结构指针
108113
可空:N
109114
意思:输出获取到的可用存储
110-
参数.:nMode
115+
参数.:nMode
111116
In/Out:In
112117
类型:整数型
113118
可空:N
114-
意思:输入选择模式
119+
意思:输入LB的模式
115120
返回值
116121
类型:逻辑型
117122
意思:是否成功
118123
备注:
119124
*********************************************************************/
120-
extern "C" BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode);
125+
extern "C" BOOL APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode);
121126
/********************************************************************
122127
函数名称:APIHelp_Distributed_GetPathKey
123128
函数功能:通过BUCKET名称查找对应路径

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 79 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,32 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer,
216216
/********************************************************************
217217
函数名称:APIHelp_Distributed_UPStorage
218218
函数功能:通过分布式存储列表获得一个存储地址
219-
参数.一:pStl_ListBucket
219+
参数.一:lpszMsgBuffer
220+
In/Out:In
221+
类型:常量字符指针
222+
可空:N
223+
意思:输入要解析的URL
224+
参数.二:pStl_ListBucket
220225
In/Out:In
221226
类型:容器指针
222227
可空:N
223228
意思:输入要解析的列表
224-
参数.:pSt_StorageBucket
229+
参数.:pSt_StorageBucket
225230
In/Out:Out
226231
类型:数据结构指针
227232
可空:N
228233
意思:输出获取到的可用存储
234+
参数.四:nMode
235+
In/Out:In
236+
类型:整数型
237+
可空:N
238+
意思:输入LB的模式
229239
返回值
230240
类型:逻辑型
231241
意思:是否成功
232242
备注:
233243
*********************************************************************/
234-
BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode)
244+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket, int nMode)
235245
{
236246
APIHelp_IsErrorOccur = FALSE;
237247

@@ -241,81 +251,91 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUC
241251
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
242252
return FALSE;
243253
}
244-
int nLastLevel = 99999;
245-
list<XENGINE_STORAGEBUCKET> stl_BuckSelect;
246-
//先得到最小级别
247-
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
254+
if (4 == nMode)
248255
{
249-
//只处理启用的
250-
if (stl_ListIterator->bEnable)
256+
if (!APIHelp_Distributed_DLStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket))
251257
{
252-
if (stl_ListIterator->nLevel < nLastLevel)
253-
{
254-
nLastLevel = stl_ListIterator->nLevel; //得到最小级别
255-
}
258+
return FALSE;
256259
}
257260
}
258-
//在来获得这个级别的列表
259-
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
261+
else
260262
{
261-
//只处理启用的
262-
if (stl_ListIterator->bEnable)
263+
int nLastLevel = 99999;
264+
list<XENGINE_STORAGEBUCKET> stl_BuckSelect;
265+
//先得到最小级别
266+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
263267
{
264-
//处理优先级
265-
if (stl_ListIterator->nLevel == nLastLevel)
268+
//只处理启用的
269+
if (stl_ListIterator->bEnable)
266270
{
267-
int nListCount = 0;
268-
__int64u nDirCount = 0; //当前目录大小
269-
CHAR** ppListFile;
270-
SystemApi_File_EnumFile(stl_ListIterator->tszFilePath, &ppListFile, &nListCount, NULL, NULL, TRUE, 1);
271-
for (int j = 0; j < nListCount; j++)
271+
if (stl_ListIterator->nLevel < nLastLevel)
272272
{
273-
struct __stat64 st_FStat;
274-
_stat64(ppListFile[j], &st_FStat);
275-
nDirCount += st_FStat.st_size;
273+
nLastLevel = stl_ListIterator->nLevel; //得到最小级别
276274
}
277-
BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount);
278-
//如果当前目录大小大于设定的大小.那么忽略
279-
if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize))
275+
}
276+
}
277+
//在来获得这个级别的列表
278+
for (auto stl_ListIterator = pStl_ListBucket->begin(); stl_ListIterator != pStl_ListBucket->end(); stl_ListIterator++)
279+
{
280+
//只处理启用的
281+
if (stl_ListIterator->bEnable)
282+
{
283+
//处理优先级
284+
if (stl_ListIterator->nLevel == nLastLevel)
280285
{
281-
continue;
286+
int nListCount = 0;
287+
__int64u nDirCount = 0; //当前目录大小
288+
CHAR** ppListFile;
289+
SystemApi_File_EnumFile(stl_ListIterator->tszFilePath, &ppListFile, &nListCount, NULL, NULL, TRUE, 1);
290+
for (int j = 0; j < nListCount; j++)
291+
{
292+
struct __stat64 st_FStat;
293+
_stat64(ppListFile[j], &st_FStat);
294+
nDirCount += st_FStat.st_size;
295+
}
296+
BaseLib_OperatorMemory_Free((XPPPMEM)&ppListFile, nListCount);
297+
//如果当前目录大小大于设定的大小.那么忽略
298+
if (nDirCount >= APIHelp_Distributed_GetSize(stl_ListIterator->tszBuckSize))
299+
{
300+
continue;
301+
}
302+
stl_BuckSelect.push_back(*stl_ListIterator);
282303
}
283-
stl_BuckSelect.push_back(*stl_ListIterator);
284304
}
285305
}
286-
}
287-
//通过指定模式获得一个key
288-
if (!stl_BuckSelect.empty())
289-
{
290-
APIHelp_IsErrorOccur = TRUE;
291-
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
292-
return FALSE;
293-
}
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())
306+
//通过指定模式获得一个key
307+
if (stl_BuckSelect.empty())
299308
{
300-
xhToken--;
309+
APIHelp_IsErrorOccur = TRUE;
310+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
311+
return FALSE;
301312
}
302-
list<XENGINE_STORAGEBUCKET>::const_iterator stl_ListIterator = stl_BuckSelect.begin();
303-
for (XNETHANDLE i = 0; stl_ListIterator != stl_BuckSelect.end(); stl_ListIterator++, i++)
313+
if (1 == nMode)
304314
{
305-
if (xhToken == i)
315+
XNETHANDLE xhToken = 0;
316+
BaseLib_OperatorHandle_Create(&xhToken, 0, stl_BuckSelect.size(), FALSE);
317+
if (xhToken == stl_BuckSelect.size())
306318
{
307-
*pSt_StorageBucket = *stl_ListIterator;
308-
break;
319+
xhToken--;
320+
}
321+
list<XENGINE_STORAGEBUCKET>::const_iterator stl_ListIterator = stl_BuckSelect.begin();
322+
for (XNETHANDLE i = 0; stl_ListIterator != stl_BuckSelect.end(); stl_ListIterator++, i++)
323+
{
324+
if (xhToken == i)
325+
{
326+
*pSt_StorageBucket = *stl_ListIterator;
327+
break;
328+
}
309329
}
310330
}
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();
331+
else if (2 == nMode)
332+
{
333+
*pSt_StorageBucket = stl_BuckSelect.front();
334+
}
335+
else if (3 == nMode)
336+
{
337+
*pSt_StorageBucket = stl_BuckSelect.back();
338+
}
319339
}
320340

321341
return TRUE;

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, int nMode);
24+
BOOL APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, 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, int nMode)
46+
extern "C" BOOL APIHelp_Distributed_UPStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, XENGINE_STORAGEBUCKET * pSt_StorageBucket, int nMode)
4747
{
48-
return m_APIDistributed.APIHelp_Distributed_UPStorage(pStl_ListBucket, pSt_StorageBucket, nMode);
48+
return m_APIDistributed.APIHelp_Distributed_UPStorage(lpszMsgBuffer, pStl_ListBucket, pSt_StorageBucket, nMode);
4949
}
5050
extern "C" BOOL APIHelp_Distributed_GetPathKey(list<XENGINE_STORAGEBUCKET>*pStl_ListBucket, LPCTSTR lpszBuckKey, TCHAR * ptszFilePath)
5151
{

XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
146146
XENGINE_STORAGEBUCKET st_StorageBucket;
147147
memset(&st_StorageBucket, '\0', sizeof(XENGINE_STORAGEBUCKET));
148148

149-
if (!APIHelp_Distributed_UPStorage(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket, st_LoadbalanceCfg.st_LBLocation.nUPLoadMode))
149+
if (!APIHelp_Distributed_UPStorage(pSt_HTTPParam->tszHttpUri, st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, &st_StorageBucket, st_LoadbalanceCfg.st_LBLocation.nUPLoadMode))
150150
{
151151
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,请求上传文件失败,可能BUCKET:% 不正确,错误:%lX"), lpszClientAddr, pSt_HTTPParam->tszHttpUri, APIHelp_GetLastError());
152152
return FALSE;

0 commit comments

Comments
 (0)