diff --git a/storage/storage_service.c b/storage/storage_service.c index e69c839..5175ad1 100644 --- a/storage/storage_service.c +++ b/storage/storage_service.c @@ -1666,7 +1666,10 @@ void storage_service_destroy() int storage_get_storage_path_index(int *store_path_index) { - int i, t; + int i; + int start; + int end; + int index; *store_path_index = g_store_path_index; if (g_store_path_mode == FDFS_STORE_PATH_LOAD_BALANCE) @@ -1688,27 +1691,25 @@ int storage_get_storage_path_index(int *store_path_index) [*store_path_index].total_mb, g_fdfs_store_paths.paths \ [*store_path_index].free_mb, g_avg_storage_reserved_mb)) { - t = g_store_path_index + 1; - if (t >= g_fdfs_store_paths.count) - { - t = 0; - } - for (i=t; istore_path_count; - if (!tracker_check_reserved_space_path(pStorageServer-> \ - path_total_mbs[write_path_index], pStorageServer-> \ + if (!tracker_check_reserved_space_path(pStorageServer-> + path_total_mbs[write_path_index], pStorageServer-> path_free_mbs[write_path_index], avg_reserved_mb)) { - int i, t; - t = write_path_index + 1; - if (t >= pStoreGroup->store_path_count) - { - t = 0; - } - for (i=t; istore_path_count; i++) - { - if (tracker_check_reserved_space_path( \ - pStorageServer->path_total_mbs[i], \ - pStorageServer->path_free_mbs[i], \ - avg_reserved_mb)) - { - pStorageServer->current_write_path = i; - write_path_index = i; - break; - } - } + int i; + int start; + int end; + int index; - if (i == pStoreGroup->store_path_count) + start = (write_path_index + 1) % pStoreGroup->store_path_count; + end = start + pStoreGroup->store_path_count - 1; + for (i=start; istore_path_count; + if (tracker_check_reserved_space_path( + pStorageServer->path_total_mbs[index], + pStorageServer->path_free_mbs[index], + avg_reserved_mb)) + { + pStorageServer->current_write_path = index; + write_path_index = index; + break; + } + } + + if (i == end) { if (!g_if_use_trunk_file) { @@ -2710,43 +2712,27 @@ static int tracker_deal_service_query_storage( \ return ENOSPC; } - for (i=write_path_index; i \ - store_path_count; i++) + start = write_path_index % pStoreGroup->store_path_count; + end = start + pStoreGroup->store_path_count; + for (i=start; ipath_total_mbs[i], \ - pStorageServer->path_free_mbs[i] + \ - pStoreGroup->trunk_free_mb, \ - avg_reserved_mb)) - { - pStorageServer->current_write_path = i; - write_path_index = i; + index = i % pStoreGroup->store_path_count; + if (tracker_check_reserved_space_path( + pStorageServer->path_total_mbs[index], + pStorageServer->path_free_mbs[index] + + pStoreGroup->trunk_free_mb, avg_reserved_mb)) + { + pStorageServer->current_write_path = index; + write_path_index = index; break; } } - if ( i == pStoreGroup->store_path_count) - { - for (i=0; ipath_total_mbs[i], \ - pStorageServer->path_free_mbs[i] + \ - pStoreGroup->trunk_free_mb, \ - avg_reserved_mb)) - { - pStorageServer->current_write_path = i; - write_path_index = i; - break; - } - } - - if (i == write_path_index) - { - pTask->send.ptr->length = sizeof(TrackerHeader); - return ENOSPC; - } - } - } + if (i == end) + { + pTask->send.ptr->length = sizeof(TrackerHeader); + return ENOSPC; + } + } } if (g_groups.store_path == FDFS_STORE_PATH_ROUND_ROBIN)