enh: no shuffle for array with one element

This commit is contained in:
Shungang Li 2024-08-12 10:56:25 +08:00
parent debd1e2308
commit 5d62dce2c2
1 changed files with 9 additions and 7 deletions

View File

@ -947,8 +947,8 @@ _exit:
TAOS_RETURN(code); TAOS_RETURN(code);
} }
static int32_t s3InitEpIndexArray(SArray** pIndexArray) { static int32_t s3InitEpIndexArray(SArray **pIndexArray) {
SArray* indexArray = taosArrayInit(tsS3EpNum, sizeof(int8_t)); SArray *indexArray = taosArrayInit(tsS3EpNum, sizeof(int8_t));
if (!indexArray) { if (!indexArray) {
uError("%s: %s", __func__, "out of memory"); uError("%s: %s", __func__, "out of memory");
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
@ -958,11 +958,13 @@ static int32_t s3InitEpIndexArray(SArray** pIndexArray) {
taosArraySet(indexArray, i, &i); taosArraySet(indexArray, i, &i);
} }
for (int8_t i = 0; i < tsS3EpNum; ++i) { if (tsS3EpNum > 1) {
int8_t j = taosRand() % tsS3EpNum; for (int8_t i = 0; i < tsS3EpNum; ++i) {
int8_t tmp = *(int8_t *)taosArrayGet(indexArray, i); int8_t j = taosRand() % tsS3EpNum;
taosArraySet(indexArray, i, taosArrayGet(indexArray, j)); int8_t tmp = *(int8_t *)taosArrayGet(indexArray, i);
taosArraySet(indexArray, j, &tmp); taosArraySet(indexArray, i, taosArrayGet(indexArray, j));
taosArraySet(indexArray, j, &tmp);
}
} }
*pIndexArray = indexArray; *pIndexArray = indexArray;