From 5187b700aafdb4f6b8d37ba654b1edd62f9b319d Mon Sep 17 00:00:00 2001 From: lihui Date: Tue, 31 Dec 2019 16:55:20 +0800 Subject: [PATCH 1/2] [#1039 TBASE-816] --- src/client/src/tscFunctionImpl.c | 63 +++++++++++++++++--------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 2d913b2f20..e63572f44b 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -3817,31 +3817,29 @@ static void getStatics_f(int64_t *primaryKey, float *data, int32_t numOfRow, dou int16_t *minIndex, int16_t *maxIndex, int32_t *numOfNull) { float fmin = DBL_MAX; float fmax = -DBL_MAX; - float fminIndex = 0; - float fmaxIndex = 0; double dsum = 0; + *minIndex = 0; + *maxIndex = 0; assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { - if (isNull(&data[i], TSDB_DATA_TYPE_FLOAT)) { + if (isNull((const char*) &data[i], TSDB_DATA_TYPE_FLOAT)) { (*numOfNull) += 1; continue; } float fv = 0; - *(int32_t*)(&fv) = *(int32_t*)(&(data[i])); - - //*sum += data[i]; + fv = GET_FLOAT_VAL(&(data[i])); dsum += fv; if (fmin > fv) { fmin = fv; - fminIndex = i; + minIndex = i; } if (fmax < fv) { fmax = fv; - fmaxIndex = i; + maxIndex = i; } // if (isNull(&lastVal, TSDB_DATA_TYPE_FLOAT)) { @@ -3855,46 +3853,46 @@ static void getStatics_f(int64_t *primaryKey, float *data, int32_t numOfRow, dou } double csum = 0; - *(int64_t*)(&csum) = *(int64_t*)sum; + csum = GET_DOUBLE_VAL(sum); csum += dsum; - *(int64_t*)(sum) = *(int64_t*)(&csum); - - *(int32_t*)max = *(int32_t*)(&fmax); - *(int32_t*)min = *(int32_t*)(&fmin); - *(int32_t*)minIndex = *(int32_t*)(&fminIndex); - *(int32_t*)maxIndex = *(int32_t*)(&fmaxIndex); - +#ifdef _TD_ARM_32_ + SET_DOUBLE_VAL_ALIGN(sum, &csum); + SET_DOUBLE_VAL_ALIGN(max, &fmax); + SET_DOUBLE_VAL_ALIGN(min, &fmin); +#else + *sum = csum; + *max = fmax; + *min = fmin; +#endif } static void getStatics_d(int64_t *primaryKey, double *data, int32_t numOfRow, double *min, double *max, double *sum, int16_t *minIndex, int16_t *maxIndex, int32_t *numOfNull) { double dmin = DBL_MAX; double dmax = -DBL_MAX; - double dminIndex = 0; - double dmaxIndex = 0; double dsum = 0; + *minIndex = 0; + *maxIndex = 0; assert(numOfRow <= INT16_MAX); for (int32_t i = 0; i < numOfRow; ++i) { - if (isNull(&data[i], TSDB_DATA_TYPE_DOUBLE)) { + if (isNull((const char*) &data[i], TSDB_DATA_TYPE_DOUBLE)) { (*numOfNull) += 1; continue; } double dv = 0; - *(int64_t*)(&dv) = *(int64_t*)(&(data[i])); - - //*sum += data[i]; + dv = GET_DOUBLE_VAL(&(data[i])); dsum += dv; if (dmin > dv) { dmin = dv; - dminIndex = i; + minIndex = i; } if (dmax < dv) { dmax = dv; - dmaxIndex = i; + maxIndex = i; } // if (isNull(&lastVal, TSDB_DATA_TYPE_DOUBLE)) { @@ -3908,14 +3906,19 @@ static void getStatics_d(int64_t *primaryKey, double *data, int32_t numOfRow, do } double csum = 0; - *(int64_t*)(&csum) = *(int64_t*)sum; + csum = GET_DOUBLE_VAL(sum); csum += dsum; - *(int64_t*)(sum) = *(int64_t*)(&csum); - *(int64_t*)max = *(int64_t*)(&dmax); - *(int64_t*)min = *(int64_t*)(&dmin); - *(int64_t*)minIndex = *(int64_t*)(&dminIndex); - *(int64_t*)maxIndex = *(int64_t*)(&dmaxIndex); + +#ifdef _TD_ARM_32_ + SET_DOUBLE_VAL_ALIGN(sum, &csum); + SET_DOUBLE_VAL_ALIGN(max, &dmax); + SET_DOUBLE_VAL_ALIGN(min, &dmin); +#else + *sum = csum; + *max = dmax; + *min = dmin; +#endif } void getStatistics(char *priData, char *data, int32_t size, int32_t numOfRow, int32_t type, int64_t *min, int64_t *max, From ea33f64fc1c7eca21f6952aa51ad95eb1d12091a Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 31 Dec 2019 17:02:11 +0800 Subject: [PATCH 2/2] #1041 --- src/sdb/src/sdbEngine.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/sdb/src/sdbEngine.c b/src/sdb/src/sdbEngine.c index c115f3c3c0..024360501f 100644 --- a/src/sdb/src/sdbEngine.c +++ b/src/sdb/src/sdbEngine.c @@ -807,20 +807,22 @@ void sdbResetTable(SSdbTable *pTable) { int bytes; int total_size = 0; int real_size = 0; - int64_t oldId; SRowHead *rowHead = NULL; void * pMetaRow = NULL; + int64_t oldId = pTable->id; + int oldNumOfRows = pTable->numOfRows; - oldId = pTable->id; if (sdbOpenSdbFile(pTable) < 0) return; + pTable->numOfRows = oldNumOfRows; total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { + sdbError("failed to allocate row head memory for reset, sdb:%s", pTable->name); return; } - sdbTrace("open sdb file:%s for update", pTable->fn); + sdbPrint("open sdb file:%s for reset table", pTable->fn); while (1) { memset(rowHead, 0, total_size); @@ -841,15 +843,15 @@ void sdbResetTable(SSdbTable *pTable) { } if (rowHead->rowSize < 0 || rowHead->rowSize > pTable->maxRowSize) { - sdbError("error row size in sdb file:%s rowSize:%d maxRowSize:%d", pTable->fn, rowHead->rowSize, - pTable->maxRowSize); + sdbError("error row size in sdb file:%s for reset, id:%d rowSize:%d maxRowSize:%d", + pTable->fn, rowHead->id, rowHead->rowSize, pTable->maxRowSize); pTable->size += sizeof(SRowHead); continue; } bytes = read(pTable->fd, rowHead->data, rowHead->rowSize + sizeof(TSCKSUM)); if (bytes < rowHead->rowSize + sizeof(TSCKSUM)) { - sdbError("failed to read sdb file:%s id:%d rowSize:%d", pTable->fn, rowHead->id, rowHead->rowSize); + sdbError("failed to read sdb file:%s for reset, id:%d rowSize:%d", pTable->fn, rowHead->id, rowHead->rowSize); break; } @@ -897,7 +899,7 @@ void sdbResetTable(SSdbTable *pTable) { tfree(rowHead); - sdbTrace("table:%s is updated, sdbVerion:%ld id:%ld", pTable->name, sdbVersion, pTable->id); + sdbPrint("table:%s is updated, sdbVerion:%ld id:%ld", pTable->name, sdbVersion, pTable->id); } // TODO:A problem here :use snapshot file to sync another node will cause