From f1ab599f1666d516d5de632480d96d8bcb432deb Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Mon, 4 Dec 2023 15:22:57 +0800 Subject: [PATCH] add more description for config item: reserved_storage_space --- conf/tracker.conf | 7 ++++- tracker/fdfs_shared_func.c | 60 ++++++++++++++++++-------------------- tracker/tracker_service.c | 22 +++++++------- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/conf/tracker.conf b/conf/tracker.conf index f5e8ce4..1c207db 100644 --- a/conf/tracker.conf +++ b/conf/tracker.conf @@ -93,14 +93,19 @@ store_path = 0 download_server = 0 # reserved storage space for system or other applications. -# if the free(available) space of any stoarge server in +# if the free(available) space of any stoarge server in # a group <= reserved_storage_space, no file can be uploaded to this group. # bytes unit can be one of follows: ### G or g for gigabyte(GB) ### M or m for megabyte(MB) ### K or k for kilobyte(KB) ### no unit for byte(B) +# ### XX.XX% as ratio such as: reserved_storage_space = 10% +# +# NOTE: +## the absolute reserved space is the sum of all store paths in the storage server +## the reserved space ratio is for each store path reserved_storage_space = 20% #standard log level as syslog, case insensitive, value list: diff --git a/tracker/fdfs_shared_func.c b/tracker/fdfs_shared_func.c index 3a83f95..26f0803 100644 --- a/tracker/fdfs_shared_func.c +++ b/tracker/fdfs_shared_func.c @@ -203,19 +203,19 @@ int fdfs_parse_storage_reserved_space(IniContext *pIniContext, char *pReservedSpaceStr; int64_t storage_reserved; - pReservedSpaceStr = iniGetStrValue(NULL, \ + pReservedSpaceStr = iniGetStrValue(NULL, "reserved_storage_space", pIniContext); if (pReservedSpaceStr == NULL) { - pStorageReservedSpace->flag = \ + pStorageReservedSpace->flag = TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB; pStorageReservedSpace->rs.mb = FDFS_DEF_STORAGE_RESERVED_MB; return 0; } if (*pReservedSpaceStr == '\0') { - logError("file: "__FILE__", line: %d, " \ - "item \"reserved_storage_space\" is empty!", \ + logError("file: "__FILE__", line: %d, " + "item \"reserved_storage_space\" is empty!", __LINE__); return EINVAL; } @@ -227,24 +227,22 @@ int fdfs_parse_storage_reserved_space(IniContext *pIniContext, pStorageReservedSpace->flag = TRACKER_STORAGE_RESERVED_SPACE_FLAG_RATIO; endptr = NULL; *(pReservedSpaceStr + len - 1) = '\0'; - pStorageReservedSpace->rs.ratio = \ + pStorageReservedSpace->rs.ratio = strtod(pReservedSpaceStr, &endptr); if (endptr != NULL && *endptr != '\0') { - logError("file: "__FILE__", line: %d, " \ - "item \"reserved_storage_space\": %s%%"\ - " is invalid!", __LINE__, \ - pReservedSpaceStr); + logError("file: "__FILE__", line: %d, " + "item \"reserved_storage_space\": %s%%" + " is invalid!", __LINE__, pReservedSpaceStr); return EINVAL; } - if (pStorageReservedSpace->rs.ratio <= 0.00 || \ + if (pStorageReservedSpace->rs.ratio <= 0.00 || pStorageReservedSpace->rs.ratio >= 100.00) { - logError("file: "__FILE__", line: %d, " \ - "item \"reserved_storage_space\": %s%%"\ - " is invalid!", __LINE__, \ - pReservedSpaceStr); + logError("file: "__FILE__", line: %d, " + "item \"reserved_storage_space\": %s%%" + " is invalid!", __LINE__, pReservedSpaceStr); return EINVAL; } @@ -312,7 +310,7 @@ int64_t fdfs_get_storage_reserved_space_mb(const int64_t total_mb, bool fdfs_check_reserved_space(FDFSGroupInfo *pGroup, \ FDFSStorageReservedSpace *pStorageReservedSpace) { - if (pStorageReservedSpace->flag == \ + if (pStorageReservedSpace->flag == TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB) { return pGroup->free_mb > pStorageReservedSpace->rs.mb; @@ -330,7 +328,7 @@ bool fdfs_check_reserved_space(FDFSGroupInfo *pGroup, \ pStorageReservedSpace->rs.ratio); */ - return ((double)pGroup->free_mb / (double)pGroup->total_mb) > \ + return ((double)pGroup->free_mb / (double)pGroup->total_mb) > pStorageReservedSpace->rs.ratio; } } @@ -338,12 +336,12 @@ bool fdfs_check_reserved_space(FDFSGroupInfo *pGroup, \ bool fdfs_check_reserved_space_trunk(FDFSGroupInfo *pGroup, \ FDFSStorageReservedSpace *pStorageReservedSpace) { - if (pStorageReservedSpace->flag == \ + if (pStorageReservedSpace->flag == TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB) - { - return (pGroup->free_mb + pGroup->trunk_free_mb > - pStorageReservedSpace->rs.mb); - } + { + return (pGroup->free_mb + pGroup->trunk_free_mb > + pStorageReservedSpace->rs.mb); + } else { if (pGroup->total_mb == 0) @@ -353,20 +351,20 @@ bool fdfs_check_reserved_space_trunk(FDFSGroupInfo *pGroup, \ /* logInfo("storage trunk=%.4f, rs.ratio=%.4f", - ((double)(pGroup->free_mb + pGroup->trunk_free_mb) / \ + ((double)(pGroup->free_mb + pGroup->trunk_free_mb) / (double)pGroup->total_mb), pStorageReservedSpace->rs.ratio); */ - return ((double)(pGroup->free_mb + pGroup->trunk_free_mb) / \ + return ((double)(pGroup->free_mb + pGroup->trunk_free_mb) / (double)pGroup->total_mb) > pStorageReservedSpace->rs.ratio; } } -bool fdfs_check_reserved_space_path(const int64_t total_mb, \ - const int64_t free_mb, const int64_t avg_mb, \ +bool fdfs_check_reserved_space_path(const int64_t total_mb, + const int64_t free_mb, const int64_t avg_mb, FDFSStorageReservedSpace *pStorageReservedSpace) { - if (pStorageReservedSpace->flag == \ + if (pStorageReservedSpace->flag == TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB) { return free_mb > avg_mb; @@ -379,14 +377,14 @@ bool fdfs_check_reserved_space_path(const int64_t total_mb, \ } /* - logInfo("storage path, free_mb=%"PRId64 \ - ", total_mb=%"PRId64", " \ - "real ratio=%.4f, rs.ratio=%.4f", \ - free_mb, total_mb, ((double)free_mb / total_mb), \ + logInfo("storage path, free_mb=%"PRId64 + ", total_mb=%"PRId64", " + "real ratio=%.4f, rs.ratio=%.4f", + free_mb, total_mb, ((double)free_mb / total_mb), pStorageReservedSpace->rs.ratio); */ - return ((double)free_mb / (double)total_mb) > \ + return ((double)free_mb / (double)total_mb) > pStorageReservedSpace->rs.ratio; } } diff --git a/tracker/tracker_service.c b/tracker/tracker_service.c index 786a40f..ec9d5e7 100644 --- a/tracker/tracker_service.c +++ b/tracker/tracker_service.c @@ -2551,9 +2551,9 @@ static int tracker_deal_service_query_storage( \ if (pStoreGroup == NULL) { FDFSGroupInfo **ppGroupEnd; - ppGroupEnd = g_groups.sorted_groups + \ + ppGroupEnd = g_groups.sorted_groups + g_groups.count; - for (ppGroup=ppFoundGroup+1; \ + for (ppGroup=ppFoundGroup+1; ppGroupactive_count == 0) @@ -2565,7 +2565,7 @@ static int tracker_deal_service_query_storage( \ if (tracker_check_reserved_space(*ppGroup)) { pStoreGroup = *ppGroup; - g_groups.current_write_group = \ + g_groups.current_write_group = ppGroup-g_groups.sorted_groups; break; } @@ -2573,7 +2573,7 @@ static int tracker_deal_service_query_storage( \ if (pStoreGroup == NULL) { - for (ppGroup=g_groups.sorted_groups; \ + for (ppGroup=g_groups.sorted_groups; ppGroupactive_count == 0) @@ -2585,7 +2585,7 @@ static int tracker_deal_service_query_storage( \ if (tracker_check_reserved_space(*ppGroup)) { pStoreGroup = *ppGroup; - g_groups.current_write_group = \ + g_groups.current_write_group = ppGroup-g_groups.sorted_groups; break; } @@ -2606,7 +2606,7 @@ static int tracker_deal_service_query_storage( \ return ENOSPC; } - for (ppGroup=g_groups.sorted_groups; \ + for (ppGroup=g_groups.sorted_groups; ppGroupactive_count == 0) @@ -2616,7 +2616,7 @@ static int tracker_deal_service_query_storage( \ if (tracker_check_reserved_space_trunk(*ppGroup)) { pStoreGroup = *ppGroup; - g_groups.current_write_group = \ + g_groups.current_write_group = ppGroup-g_groups.sorted_groups; break; } @@ -2641,7 +2641,7 @@ static int tracker_deal_service_query_storage( \ } else if (g_groups.store_lookup == FDFS_STORE_LOOKUP_SPEC_GROUP) { - if (g_groups.pStoreGroup == NULL || \ + if (g_groups.pStoreGroup == NULL || g_groups.pStoreGroup->active_count == 0) { pTask->send.ptr->length = sizeof(TrackerHeader); @@ -2650,8 +2650,8 @@ static int tracker_deal_service_query_storage( \ if (!tracker_check_reserved_space(g_groups.pStoreGroup)) { - if (!(g_if_use_trunk_file && \ - tracker_check_reserved_space_trunk( \ + if (!(g_if_use_trunk_file && + tracker_check_reserved_space_trunk( g_groups.pStoreGroup))) { pTask->send.ptr->length = sizeof(TrackerHeader); @@ -2755,7 +2755,7 @@ static int tracker_deal_service_query_storage( \ if (g_groups.store_path == FDFS_STORE_PATH_ROUND_ROBIN) { pStorageServer->current_write_path++; - if (pStorageServer->current_write_path >= \ + if (pStorageServer->current_write_path >= pStoreGroup->store_path_count) { pStorageServer->current_write_path = 0;