Merge pull request #19126 from taosdata/fix/TD-21221-MAIN
feat(util): new ASSERT work
This commit is contained in:
commit
919df1f039
|
@ -20,7 +20,6 @@
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "tdataformat.h"
|
#include "tdataformat.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
|
|
|
@ -1,168 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_UTIL_BUFFER_H_
|
|
||||||
#define _TD_UTIL_BUFFER_H_
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// usage example
|
|
||||||
/*
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "texception.h"
|
|
||||||
|
|
||||||
int32_t main( int32_t argc, char** argv ) {
|
|
||||||
SBufferWriter bw = tbufInitWriter( NULL, false );
|
|
||||||
|
|
||||||
TRY( 1 ) {
|
|
||||||
//--------------------- write ------------------------
|
|
||||||
// reserve 1024 bytes for the buffer to improve performance
|
|
||||||
tbufEnsureCapacity( &bw, 1024 );
|
|
||||||
|
|
||||||
// reserve space for the interger count
|
|
||||||
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
|
|
||||||
// write 5 integers to the buffer
|
|
||||||
for( int32_t i = 0; i < 5; i++) {
|
|
||||||
tbufWriteInt32( &bw, i );
|
|
||||||
}
|
|
||||||
// write the integer count to buffer at reserved position
|
|
||||||
tbufWriteInt32At( &bw, pos, 5 );
|
|
||||||
|
|
||||||
// write a string to the buffer
|
|
||||||
tbufWriteString( &bw, "this is a string.\n" );
|
|
||||||
// acquire the result and close the write buffer
|
|
||||||
size_t size = tbufTell( &bw );
|
|
||||||
char* data = tbufGetData( &bw, false );
|
|
||||||
|
|
||||||
//------------------------ read -----------------------
|
|
||||||
SBufferReader br = tbufInitReader( data, size, false );
|
|
||||||
// read & print out all integers
|
|
||||||
int32_t count = tbufReadInt32( &br );
|
|
||||||
for( int32_t i = 0; i < count; i++ ) {
|
|
||||||
printf( "%d\n", tbufReadInt32(&br) );
|
|
||||||
}
|
|
||||||
// read & print out a string
|
|
||||||
puts( tbufReadString(&br, NULL) );
|
|
||||||
// try read another integer, this result in an error as there no this integer
|
|
||||||
tbufReadInt32( &br );
|
|
||||||
printf( "you should not see this message.\n" );
|
|
||||||
} CATCH( code ) {
|
|
||||||
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
|
|
||||||
} END_TRY
|
|
||||||
|
|
||||||
tbufCloseWriter( &bw );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct SBufferReader {
|
|
||||||
bool endian;
|
|
||||||
const char* data;
|
|
||||||
size_t pos;
|
|
||||||
size_t size;
|
|
||||||
} SBufferReader;
|
|
||||||
|
|
||||||
typedef struct SBufferWriter {
|
|
||||||
bool endian;
|
|
||||||
char* data;
|
|
||||||
size_t pos;
|
|
||||||
size_t size;
|
|
||||||
void* (*allocator)(void*, size_t);
|
|
||||||
} SBufferWriter;
|
|
||||||
|
|
||||||
// common functions & macros for both reader & writer
|
|
||||||
|
|
||||||
#define tbufTell(buf) ((buf)->pos)
|
|
||||||
|
|
||||||
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
|
|
||||||
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
|
|
||||||
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
|
|
||||||
#define tbufInitWriter(Allocator, Endian) \
|
|
||||||
{ .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) }
|
|
||||||
|
|
||||||
void tbufCloseWriter(SBufferWriter* buf);
|
|
||||||
void tbufEnsureCapacity(SBufferWriter* buf, size_t size);
|
|
||||||
size_t tbufReserve(SBufferWriter* buf, size_t size);
|
|
||||||
char* tbufGetData(SBufferWriter* buf, bool takeOver);
|
|
||||||
void tbufWrite(SBufferWriter* buf, const void* data, size_t size);
|
|
||||||
void tbufWriteAt(SBufferWriter* buf, size_t pos, const void* data, size_t size);
|
|
||||||
void tbufWriteStringLen(SBufferWriter* buf, const char* str, size_t len);
|
|
||||||
void tbufWriteString(SBufferWriter* buf, const char* str);
|
|
||||||
// the prototype of tbufWriteBinary and tbufWrite are identical
|
|
||||||
// the difference is: tbufWriteBinary writes the length of the data to the buffer
|
|
||||||
// first, then the actual data, which means the reader don't need to know data
|
|
||||||
// size before read. Write only write the data itself, which means the reader
|
|
||||||
// need to know data size before read.
|
|
||||||
void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len);
|
|
||||||
void tbufWriteBool(SBufferWriter* buf, bool data);
|
|
||||||
void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data);
|
|
||||||
void tbufWriteChar(SBufferWriter* buf, char data);
|
|
||||||
void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data);
|
|
||||||
void tbufWriteInt8(SBufferWriter* buf, int8_t data);
|
|
||||||
void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data);
|
|
||||||
void tbufWriteUint8(SBufferWriter* buf, uint8_t data);
|
|
||||||
void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data);
|
|
||||||
void tbufWriteInt16(SBufferWriter* buf, int16_t data);
|
|
||||||
void tbufWriteInt16At(SBufferWriter* buf, size_t pos, int16_t data);
|
|
||||||
void tbufWriteUint16(SBufferWriter* buf, uint16_t data);
|
|
||||||
void tbufWriteUint16At(SBufferWriter* buf, size_t pos, uint16_t data);
|
|
||||||
void tbufWriteInt32(SBufferWriter* buf, int32_t data);
|
|
||||||
void tbufWriteInt32At(SBufferWriter* buf, size_t pos, int32_t data);
|
|
||||||
void tbufWriteUint32(SBufferWriter* buf, uint32_t data);
|
|
||||||
void tbufWriteUint32At(SBufferWriter* buf, size_t pos, uint32_t data);
|
|
||||||
void tbufWriteInt64(SBufferWriter* buf, int64_t data);
|
|
||||||
void tbufWriteInt64At(SBufferWriter* buf, size_t pos, int64_t data);
|
|
||||||
void tbufWriteUint64(SBufferWriter* buf, uint64_t data);
|
|
||||||
void tbufWriteUint64At(SBufferWriter* buf, size_t pos, uint64_t data);
|
|
||||||
void tbufWriteFloat(SBufferWriter* buf, float data);
|
|
||||||
void tbufWriteFloatAt(SBufferWriter* buf, size_t pos, float data);
|
|
||||||
void tbufWriteDouble(SBufferWriter* buf, double data);
|
|
||||||
void tbufWriteDoubleAt(SBufferWriter* buf, size_t pos, double data);
|
|
||||||
|
|
||||||
/* ------------------------ BUFFER READER FUNCTIONS AND MACROS ------------------------ */
|
|
||||||
// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically
|
|
||||||
#define tbufInitReader(Data, Size, Endian) \
|
|
||||||
{ .endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 : (Size)) }
|
|
||||||
|
|
||||||
size_t tbufSkip(SBufferReader* buf, size_t size);
|
|
||||||
const char* tbufRead(SBufferReader* buf, size_t size);
|
|
||||||
void tbufReadToBuffer(SBufferReader* buf, void* dst, size_t size);
|
|
||||||
const char* tbufReadString(SBufferReader* buf, size_t* len);
|
|
||||||
size_t tbufReadToString(SBufferReader* buf, char* dst, size_t size);
|
|
||||||
const char* tbufReadBinary(SBufferReader* buf, size_t* len);
|
|
||||||
size_t tbufReadToBinary(SBufferReader* buf, void* dst, size_t size);
|
|
||||||
bool tbufReadBool(SBufferReader* buf);
|
|
||||||
char tbufReadChar(SBufferReader* buf);
|
|
||||||
int8_t tbufReadInt8(SBufferReader* buf);
|
|
||||||
uint8_t tbufReadUint8(SBufferReader* buf);
|
|
||||||
int16_t tbufReadInt16(SBufferReader* buf);
|
|
||||||
uint16_t tbufReadUint16(SBufferReader* buf);
|
|
||||||
int32_t tbufReadInt32(SBufferReader* buf);
|
|
||||||
uint32_t tbufReadUint32(SBufferReader* buf);
|
|
||||||
int64_t tbufReadInt64(SBufferReader* buf);
|
|
||||||
uint64_t tbufReadUint64(SBufferReader* buf);
|
|
||||||
float tbufReadFloat(SBufferReader* buf);
|
|
||||||
double tbufReadDouble(SBufferReader* buf);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_UTIL_BUFFER_H_*/
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "mndTelem.h"
|
#include "mndTelem.h"
|
||||||
#include "mndCluster.h"
|
#include "mndCluster.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "thttp.h"
|
#include "thttp.h"
|
||||||
#include "tjson.h"
|
#include "tjson.h"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "nodes.h"
|
#include "nodes.h"
|
||||||
#include "plannodes.h"
|
#include "plannodes.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
#include "tsimplehash.h"
|
#include "tsimplehash.h"
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "tcompression.h"
|
#include "tcompression.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tfunctionInt.h"
|
#include "tfunctionInt.h"
|
||||||
|
|
|
@ -39,7 +39,7 @@ static void median(void *src, int64_t size, int64_t s, int64_t e, const void *pa
|
||||||
doswap(elePtrAt(src, size, s), elePtrAt(src, size, e), size, buf);
|
doswap(elePtrAt(src, size, s), elePtrAt(src, size, e), size, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) <= 0 &&
|
ASSERT(comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) <= 0 &&
|
||||||
comparFn(elePtrAt(src, size, s), elePtrAt(src, size, e), param) <= 0);
|
comparFn(elePtrAt(src, size, s), elePtrAt(src, size, e), param) <= 0);
|
||||||
|
|
||||||
#ifdef _DEBUG_VIEW
|
#ifdef _DEBUG_VIEW
|
||||||
|
|
|
@ -1,424 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "texception.h"
|
|
||||||
|
|
||||||
typedef union Un4B {
|
|
||||||
uint32_t ui;
|
|
||||||
float f;
|
|
||||||
} Un4B;
|
|
||||||
#if __STDC_VERSION__ >= 201112LL
|
|
||||||
static_assert(sizeof(Un4B) == sizeof(uint32_t), "sizeof(Un4B) must equal to sizeof(uint32_t)");
|
|
||||||
static_assert(sizeof(Un4B) == sizeof(float), "sizeof(Un4B) must equal to sizeof(float)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef union Un8B {
|
|
||||||
uint64_t ull;
|
|
||||||
double d;
|
|
||||||
} Un8B;
|
|
||||||
#if __STDC_VERSION__ >= 201112LL
|
|
||||||
static_assert(sizeof(Un8B) == sizeof(uint64_t), "sizeof(Un8B) must equal to sizeof(uint64_t)");
|
|
||||||
static_assert(sizeof(Un8B) == sizeof(double), "sizeof(Un8B) must equal to sizeof(double)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// reader functions
|
|
||||||
|
|
||||||
size_t tbufSkip(SBufferReader* buf, size_t size) {
|
|
||||||
if ((buf->pos + size) > buf->size) {
|
|
||||||
THROW(-1);
|
|
||||||
}
|
|
||||||
size_t old = buf->pos;
|
|
||||||
buf->pos += size;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* tbufRead(SBufferReader* buf, size_t size) {
|
|
||||||
const char* ret = buf->data + buf->pos;
|
|
||||||
tbufSkip(buf, size);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufReadToBuffer(SBufferReader* buf, void* dst, size_t size) {
|
|
||||||
assert(dst != NULL);
|
|
||||||
// always using memcpy, leave optimization to compiler
|
|
||||||
memcpy(dst, tbufRead(buf, size), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t tbufReadLength(SBufferReader* buf) {
|
|
||||||
// maximum length is 65535, if larger length is required
|
|
||||||
// this function and the corresponding write function need to be
|
|
||||||
// revised.
|
|
||||||
uint16_t l = tbufReadUint16(buf);
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* tbufReadString(SBufferReader* buf, size_t* len) {
|
|
||||||
size_t l = tbufReadLength(buf);
|
|
||||||
const char* ret = buf->data + buf->pos;
|
|
||||||
tbufSkip(buf, l + 1);
|
|
||||||
if (ret[l] != 0) {
|
|
||||||
THROW(-1);
|
|
||||||
}
|
|
||||||
if (len != NULL) {
|
|
||||||
*len = l;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tbufReadToString(SBufferReader* buf, char* dst, size_t size) {
|
|
||||||
assert(dst != NULL);
|
|
||||||
size_t len;
|
|
||||||
const char* str = tbufReadString(buf, &len);
|
|
||||||
if (len >= size) {
|
|
||||||
len = size - 1;
|
|
||||||
}
|
|
||||||
memcpy(dst, str, len);
|
|
||||||
dst[len] = 0;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* tbufReadBinary(SBufferReader* buf, size_t* len) {
|
|
||||||
size_t l = tbufReadLength(buf);
|
|
||||||
const char* ret = buf->data + buf->pos;
|
|
||||||
tbufSkip(buf, l);
|
|
||||||
if (len != NULL) {
|
|
||||||
*len = l;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tbufReadToBinary(SBufferReader* buf, void* dst, size_t size) {
|
|
||||||
assert(dst != NULL);
|
|
||||||
size_t len;
|
|
||||||
const char* data = tbufReadBinary(buf, &len);
|
|
||||||
if (len >= size) {
|
|
||||||
len = size;
|
|
||||||
}
|
|
||||||
memcpy(dst, data, len);
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tbufReadBool(SBufferReader* buf) {
|
|
||||||
bool ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
char tbufReadChar(SBufferReader* buf) {
|
|
||||||
char ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int8_t tbufReadInt8(SBufferReader* buf) {
|
|
||||||
int8_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t tbufReadUint8(SBufferReader* buf) {
|
|
||||||
uint8_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t tbufReadInt16(SBufferReader* buf) {
|
|
||||||
int16_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return (int16_t)ntohs(ret);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t tbufReadUint16(SBufferReader* buf) {
|
|
||||||
uint16_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return ntohs(ret);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tbufReadInt32(SBufferReader* buf) {
|
|
||||||
int32_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return (int32_t)ntohl(ret);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t tbufReadUint32(SBufferReader* buf) {
|
|
||||||
uint32_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return ntohl(ret);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t tbufReadInt64(SBufferReader* buf) {
|
|
||||||
int64_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return (int64_t)htobe64(ret); // TODO: ntohll
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t tbufReadUint64(SBufferReader* buf) {
|
|
||||||
uint64_t ret;
|
|
||||||
tbufReadToBuffer(buf, &ret, sizeof(ret));
|
|
||||||
if (buf->endian) {
|
|
||||||
return htobe64(ret); // TODO: ntohll
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tbufReadFloat(SBufferReader* buf) {
|
|
||||||
Un4B _un;
|
|
||||||
tbufReadToBuffer(buf, &_un, sizeof(_un));
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ui = ntohl(_un.ui);
|
|
||||||
}
|
|
||||||
return _un.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
double tbufReadDouble(SBufferReader* buf) {
|
|
||||||
Un8B _un;
|
|
||||||
tbufReadToBuffer(buf, &_un, sizeof(_un));
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ull = htobe64(_un.ull);
|
|
||||||
}
|
|
||||||
return _un.d;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// writer functions
|
|
||||||
|
|
||||||
void tbufCloseWriter(SBufferWriter* buf) {
|
|
||||||
taosMemoryFreeClear(buf->data);
|
|
||||||
// (*buf->allocator)( buf->data, 0 ); // potential memory leak.
|
|
||||||
buf->data = NULL;
|
|
||||||
buf->pos = 0;
|
|
||||||
buf->size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufEnsureCapacity(SBufferWriter* buf, size_t size) {
|
|
||||||
size += buf->pos;
|
|
||||||
if (size > buf->size) {
|
|
||||||
size_t nsize = size + buf->size;
|
|
||||||
char* data = (*buf->allocator)(buf->data, nsize);
|
|
||||||
// TODO: the exception should be thrown by the allocator function
|
|
||||||
if (data == NULL) {
|
|
||||||
THROW(-1);
|
|
||||||
}
|
|
||||||
buf->data = data;
|
|
||||||
buf->size = nsize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t tbufReserve(SBufferWriter* buf, size_t size) {
|
|
||||||
tbufEnsureCapacity(buf, size);
|
|
||||||
size_t old = buf->pos;
|
|
||||||
buf->pos += size;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* tbufGetData(SBufferWriter* buf, bool takeOver) {
|
|
||||||
char* ret = buf->data;
|
|
||||||
if (takeOver) {
|
|
||||||
buf->pos = 0;
|
|
||||||
buf->size = 0;
|
|
||||||
buf->data = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWrite(SBufferWriter* buf, const void* data, size_t size) {
|
|
||||||
assert(data != NULL);
|
|
||||||
tbufEnsureCapacity(buf, size);
|
|
||||||
memcpy(buf->data + buf->pos, data, size);
|
|
||||||
buf->pos += size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteAt(SBufferWriter* buf, size_t pos, const void* data, size_t size) {
|
|
||||||
assert(data != NULL);
|
|
||||||
// this function can only be called to fill the gap on previous writes,
|
|
||||||
// so 'pos + size <= buf->pos' must be true
|
|
||||||
assert(pos + size <= buf->pos);
|
|
||||||
memcpy(buf->data + pos, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tbufWriteLength(SBufferWriter* buf, size_t len) {
|
|
||||||
// maximum length is 65535, if larger length is required
|
|
||||||
// this function and the corresponding read function need to be
|
|
||||||
// revised.
|
|
||||||
assert(len <= 0xffff);
|
|
||||||
tbufWriteUint16(buf, (uint16_t)len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteStringLen(SBufferWriter* buf, const char* str, size_t len) {
|
|
||||||
tbufWriteLength(buf, len);
|
|
||||||
tbufWrite(buf, str, len);
|
|
||||||
tbufWriteChar(buf, '\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteString(SBufferWriter* buf, const char* str) { tbufWriteStringLen(buf, str, strlen(str)); }
|
|
||||||
|
|
||||||
void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len) {
|
|
||||||
tbufWriteLength(buf, len);
|
|
||||||
tbufWrite(buf, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteBool(SBufferWriter* buf, bool data) { tbufWrite(buf, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteChar(SBufferWriter* buf, char data) { tbufWrite(buf, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteInt8(SBufferWriter* buf, int8_t data) { tbufWrite(buf, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteUint8(SBufferWriter* buf, uint8_t data) { tbufWrite(buf, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
|
||||||
|
|
||||||
void tbufWriteInt16(SBufferWriter* buf, int16_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int16_t)htons(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteInt16At(SBufferWriter* buf, size_t pos, int16_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int16_t)htons(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint16(SBufferWriter* buf, uint16_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htons(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint16At(SBufferWriter* buf, size_t pos, uint16_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htons(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteInt32(SBufferWriter* buf, int32_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int32_t)htonl(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteInt32At(SBufferWriter* buf, size_t pos, int32_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int32_t)htonl(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint32(SBufferWriter* buf, uint32_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htonl(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint32At(SBufferWriter* buf, size_t pos, uint32_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htonl(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteInt64(SBufferWriter* buf, int64_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int64_t)htobe64(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteInt64At(SBufferWriter* buf, size_t pos, int64_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = (int64_t)htobe64(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint64(SBufferWriter* buf, uint64_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htobe64(data);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteUint64At(SBufferWriter* buf, size_t pos, uint64_t data) {
|
|
||||||
if (buf->endian) {
|
|
||||||
data = htobe64(data);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteFloat(SBufferWriter* buf, float data) {
|
|
||||||
Un4B _un;
|
|
||||||
_un.f = data;
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ui = htonl(_un.ui);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &_un, sizeof(_un));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteFloatAt(SBufferWriter* buf, size_t pos, float data) {
|
|
||||||
Un4B _un;
|
|
||||||
_un.f = data;
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ui = htonl(_un.ui);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &_un, sizeof(_un));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteDouble(SBufferWriter* buf, double data) {
|
|
||||||
Un8B _un;
|
|
||||||
_un.d = data;
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ull = htobe64(_un.ull);
|
|
||||||
}
|
|
||||||
tbufWrite(buf, &_un, sizeof(_un));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tbufWriteDoubleAt(SBufferWriter* buf, size_t pos, double data) {
|
|
||||||
Un8B _un;
|
|
||||||
_un.d = data;
|
|
||||||
if (buf->endian) {
|
|
||||||
_un.ull = htobe64(_un.ull);
|
|
||||||
}
|
|
||||||
tbufWriteAt(buf, pos, &_un, sizeof(_un));
|
|
||||||
}
|
|
|
@ -244,7 +244,7 @@ int32_t compareJsonVal(const void *pLeft, const void *pRight) {
|
||||||
} else if (leftType == TSDB_DATA_TYPE_NULL) {
|
} else if (leftType == TSDB_DATA_TYPE_NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "data type unexpected");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1285,7 +1285,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return setChkInBytes8;
|
return setChkInBytes8;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
ASSERTS(0, "data type unexpected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1308,7 +1308,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
return setChkNotInBytes8;
|
return setChkNotInBytes8;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
ASSERTS(0, "data type unexpected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,7 +470,7 @@ int32_t tsDecompressStringImp(const char *const input, int32_t compressedSize, c
|
||||||
// TODO: Take care here, we assumes little endian encoding.
|
// TODO: Take care here, we assumes little endian encoding.
|
||||||
int32_t tsCompressTimestampImp(const char *const input, const int32_t nelements, char *const output) {
|
int32_t tsCompressTimestampImp(const char *const input, const int32_t nelements, char *const output) {
|
||||||
int32_t _pos = 1;
|
int32_t _pos = 1;
|
||||||
assert(nelements >= 0);
|
ASSERTS(nelements >= 0, "nelements is negative");
|
||||||
|
|
||||||
if (nelements == 0) return 0;
|
if (nelements == 0) return 0;
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ _exit_over:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelements, char *const output) {
|
int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelements, char *const output) {
|
||||||
assert(nelements >= 0);
|
ASSERTS(nelements >= 0, "nelements is negative");
|
||||||
if (nelements == 0) return 0;
|
if (nelements == 0) return 0;
|
||||||
|
|
||||||
if (input[0] == 0) {
|
if (input[0] == 0) {
|
||||||
|
@ -629,7 +629,7 @@ int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelement
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERT(0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2146,7 +2146,7 @@ int32_t tsCompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, in
|
||||||
int32_t len = tsCompressTimestampImp(pIn, nEle, pBuf);
|
int32_t len = tsCompressTimestampImp(pIn, nEle, pBuf);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo not one or two stage");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2159,7 +2159,7 @@ int32_t tsDecompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut,
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressTimestampImp(pBuf, nEle, pOut);
|
return tsDecompressTimestampImp(pBuf, nEle, pOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2180,7 +2180,7 @@ int32_t tsCompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_
|
||||||
int32_t len = tsCompressFloatImp(pIn, nEle, pBuf);
|
int32_t len = tsCompressFloatImp(pIn, nEle, pBuf);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
|
@ -2203,7 +2203,7 @@ int32_t tsDecompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int3
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressFloatImp(pBuf, nEle, pOut);
|
return tsDecompressFloatImp(pBuf, nEle, pOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
|
@ -2227,7 +2227,7 @@ int32_t tsCompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32
|
||||||
int32_t len = tsCompressDoubleImp(pIn, nEle, pBuf);
|
int32_t len = tsCompressDoubleImp(pIn, nEle, pBuf);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
|
@ -2250,7 +2250,7 @@ int32_t tsDecompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressDoubleImp(pBuf, nEle, pOut);
|
return tsDecompressDoubleImp(pBuf, nEle, pOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
|
@ -2281,7 +2281,7 @@ int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t
|
||||||
}
|
}
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2294,7 +2294,7 @@ int32_t tsDecompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressBoolImp(pBuf, nEle, pOut);
|
return tsDecompressBoolImp(pBuf, nEle, pOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2308,7 +2308,7 @@ int32_t tsCompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int3
|
||||||
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_TINYINT);
|
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_TINYINT);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2321,7 +2321,7 @@ int32_t tsDecompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, in
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_TINYINT);
|
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_TINYINT);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2335,7 +2335,7 @@ int32_t tsCompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int
|
||||||
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_SMALLINT);
|
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_SMALLINT);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2348,7 +2348,7 @@ int32_t tsDecompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, i
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_SMALLINT);
|
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_SMALLINT);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2362,7 +2362,7 @@ int32_t tsCompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t
|
||||||
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_INT);
|
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_INT);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2375,7 +2375,7 @@ int32_t tsDecompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_INT);
|
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_INT);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2389,7 +2389,7 @@ int32_t tsCompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32
|
||||||
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_BIGINT);
|
int32_t len = tsCompressINTImp(pIn, nEle, pBuf, TSDB_DATA_TYPE_BIGINT);
|
||||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2402,7 +2402,7 @@ int32_t tsDecompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int
|
||||||
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
if (tsDecompressStringImp(pIn, nIn, pBuf, nBuf) < 0) return -1;
|
||||||
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_BIGINT);
|
return tsDecompressINTImp(pBuf, nEle, pOut, TSDB_DATA_TYPE_BIGINT);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
ASSERTS(0, "compress algo invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "tdigest.h"
|
#include "tdigest.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "osMath.h"
|
#include "osMath.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
|
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
|
||||||
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
|
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
|
||||||
|
@ -135,24 +136,24 @@ void tdigestCompress(TDigest *t) {
|
||||||
|
|
||||||
if (a->mean <= b->mean) {
|
if (a->mean <= b->mean) {
|
||||||
mergeCentroid(&args, a);
|
mergeCentroid(&args, a);
|
||||||
assert(args.idx < t->size);
|
ASSERTS(args.idx < t->size, "idx over size");
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
mergeCentroid(&args, b);
|
mergeCentroid(&args, b);
|
||||||
assert(args.idx < t->size);
|
ASSERTS(args.idx < t->size, "idx over size");
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < num_unmerged) {
|
while (i < num_unmerged) {
|
||||||
mergeCentroid(&args, &unmerged_centroids[i++]);
|
mergeCentroid(&args, &unmerged_centroids[i++]);
|
||||||
assert(args.idx < t->size);
|
ASSERTS(args.idx < t->size, "idx over size");
|
||||||
}
|
}
|
||||||
taosMemoryFree((void *)unmerged_centroids);
|
taosMemoryFree((void *)unmerged_centroids);
|
||||||
|
|
||||||
while (j < t->num_centroids) {
|
while (j < t->num_centroids) {
|
||||||
mergeCentroid(&args, &t->centroids[j++]);
|
mergeCentroid(&args, &t->centroids[j++]);
|
||||||
assert(args.idx < t->size);
|
ASSERTS(args.idx < t->size, "idx over size");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->total_weight > 0) {
|
if (t->total_weight > 0) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "texception.h"
|
#include "texception.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
static threadlocal SExceptionNode* expList;
|
static threadlocal SExceptionNode* expList;
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ static wrapper wrappers[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2) {
|
void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 0;
|
ca->wrapper = 0;
|
||||||
|
@ -82,7 +83,7 @@ void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2) {
|
void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 1;
|
ca->wrapper = 1;
|
||||||
|
@ -93,7 +94,7 @@ void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupPush_void_ptr(bool failOnly, void* func, void* arg) {
|
void cleanupPush_void_ptr(bool failOnly, void* func, void* arg) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 2;
|
ca->wrapper = 2;
|
||||||
|
@ -103,7 +104,7 @@ void cleanupPush_void_ptr(bool failOnly, void* func, void* arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupPush_int_int(bool failOnly, void* func, int32_t arg) {
|
void cleanupPush_int_int(bool failOnly, void* func, int32_t arg) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 3;
|
ca->wrapper = 3;
|
||||||
|
@ -113,7 +114,7 @@ void cleanupPush_int_int(bool failOnly, void* func, int32_t arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupPush_void(bool failOnly, void* func) {
|
void cleanupPush_void(bool failOnly, void* func) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 4;
|
ca->wrapper = 4;
|
||||||
|
@ -122,7 +123,7 @@ void cleanupPush_void(bool failOnly, void* func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanupPush_int_ptr(bool failOnly, void* func, void* arg) {
|
void cleanupPush_int_ptr(bool failOnly, void* func, void* arg) {
|
||||||
assert(expList->numCleanupAction < expList->maxCleanupAction);
|
ASSERTS(expList->numCleanupAction < expList->maxCleanupAction, "numCleanupAction over maxCleanupAction");
|
||||||
|
|
||||||
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
SCleanupAction* ca = expList->cleanupActions + expList->numCleanupAction++;
|
||||||
ca->wrapper = 5;
|
ca->wrapper = 5;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
// Set the initial value of the multiway merge tree.
|
// Set the initial value of the multiway merge tree.
|
||||||
static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
|
static void tMergeTreeInit(SMultiwayMergeTreeInfo* pTree) {
|
||||||
assert((pTree->totalSources & 0x01) == 0 && (pTree->numOfSources << 1 == pTree->totalSources));
|
ASSERT((pTree->totalSources & 0x01) == 0 && (pTree->numOfSources << 1 == pTree->totalSources));
|
||||||
|
|
||||||
for (int32_t i = 0; i < pTree->totalSources; ++i) {
|
for (int32_t i = 0; i < pTree->totalSources; ++i) {
|
||||||
if (i < pTree->numOfSources) {
|
if (i < pTree->numOfSources) {
|
||||||
|
@ -80,7 +80,7 @@ void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
|
void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
|
||||||
assert(idx <= pTree->totalSources - 1 && idx >= pTree->numOfSources && pTree->totalSources >= 2);
|
ASSERT(idx <= pTree->totalSources - 1 && idx >= pTree->numOfSources && pTree->totalSources >= 2);
|
||||||
|
|
||||||
if (pTree->totalSources == 2) {
|
if (pTree->totalSources == 2) {
|
||||||
pTree->pNode[0].index = 0;
|
pTree->pNode[0].index = 0;
|
||||||
|
@ -115,7 +115,7 @@ void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tMergeTreeRebuild(SMultiwayMergeTreeInfo* pTree) {
|
void tMergeTreeRebuild(SMultiwayMergeTreeInfo* pTree) {
|
||||||
assert((pTree->totalSources & 0x1) == 0);
|
ASSERT((pTree->totalSources & 0x1) == 0);
|
||||||
|
|
||||||
tMergeTreeInit(pTree);
|
tMergeTreeInit(pTree);
|
||||||
for (int32_t i = pTree->totalSources - 1; i >= pTree->numOfSources; i--) {
|
for (int32_t i = pTree->totalSources - 1; i >= pTree->numOfSources; i--) {
|
||||||
|
|
|
@ -125,20 +125,20 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
||||||
assert(!pg->used && pg->pData != NULL);
|
ASSERT(!pg->used && pg->pData != NULL);
|
||||||
|
|
||||||
int32_t size = pBuf->pageSize;
|
int32_t size = pBuf->pageSize;
|
||||||
char* t = NULL;
|
char* t = NULL;
|
||||||
if (pg->offset == -1 || pg->dirty) {
|
if (pg->offset == -1 || pg->dirty) {
|
||||||
void* payload = GET_DATA_PAYLOAD(pg);
|
void* payload = GET_DATA_PAYLOAD(pg);
|
||||||
t = doCompressData(payload, pBuf->pageSize, &size, pBuf);
|
t = doCompressData(payload, pBuf->pageSize, &size, pBuf);
|
||||||
assert(size >= 0);
|
ASSERTS(size >= 0, "size is negative");
|
||||||
}
|
}
|
||||||
|
|
||||||
// this page is flushed to disk for the first time
|
// this page is flushed to disk for the first time
|
||||||
if (pg->dirty) {
|
if (pg->dirty) {
|
||||||
if (pg->offset == -1) {
|
if (pg->offset == -1) {
|
||||||
assert(pg->dirty == true);
|
ASSERTS(pg->dirty == true, "pg->dirty is false");
|
||||||
|
|
||||||
pg->offset = allocatePositionInFile(pBuf, size);
|
pg->offset = allocatePositionInFile(pBuf, size);
|
||||||
pBuf->nextPos += size;
|
pBuf->nextPos += size;
|
||||||
|
@ -210,7 +210,7 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
||||||
|
|
||||||
static char* flushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
static char* flushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
||||||
int32_t ret = TSDB_CODE_SUCCESS;
|
int32_t ret = TSDB_CODE_SUCCESS;
|
||||||
assert(((int64_t)pBuf->numOfPages * pBuf->pageSize) == pBuf->totalBufSize && pBuf->numOfPages >= pBuf->inMemPages);
|
ASSERT(((int64_t)pBuf->numOfPages * pBuf->pageSize) == pBuf->totalBufSize && pBuf->numOfPages >= pBuf->inMemPages);
|
||||||
|
|
||||||
if (pBuf->pFile == NULL) {
|
if (pBuf->pFile == NULL) {
|
||||||
if ((ret = createDiskFile(pBuf)) != TSDB_CODE_SUCCESS) {
|
if ((ret = createDiskFile(pBuf)) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -272,7 +272,7 @@ static SListNode* getEldestUnrefedPage(SDiskbasedBuf* pBuf) {
|
||||||
SListNode* pn = NULL;
|
SListNode* pn = NULL;
|
||||||
while ((pn = tdListNext(&iter)) != NULL) {
|
while ((pn = tdListNext(&iter)) != NULL) {
|
||||||
SPageInfo* pageInfo = *(SPageInfo**)pn->data;
|
SPageInfo* pageInfo = *(SPageInfo**)pn->data;
|
||||||
assert(pageInfo->pageId >= 0 && pageInfo->pn == pn);
|
ASSERT(pageInfo->pageId >= 0 && pageInfo->pn == pn);
|
||||||
|
|
||||||
if (!pageInfo->used) {
|
if (!pageInfo->used) {
|
||||||
// printf("%d is chosen\n", pageInfo->pageId);
|
// printf("%d is chosen\n", pageInfo->pageId);
|
||||||
|
@ -303,7 +303,7 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
|
||||||
tdListPopNode(pBuf->lruList, pn);
|
tdListPopNode(pBuf->lruList, pn);
|
||||||
|
|
||||||
SPageInfo* d = *(SPageInfo**)pn->data;
|
SPageInfo* d = *(SPageInfo**)pn->data;
|
||||||
assert(d->pn == pn);
|
ASSERTS(d->pn == pn, "d->pn not equal pn");
|
||||||
|
|
||||||
d->pn = NULL;
|
d->pn = NULL;
|
||||||
taosMemoryFreeClear(pn);
|
taosMemoryFreeClear(pn);
|
||||||
|
@ -353,7 +353,7 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem
|
||||||
pPBuf->freePgList = tdListNew(POINTER_BYTES);
|
pPBuf->freePgList = tdListNew(POINTER_BYTES);
|
||||||
|
|
||||||
// at least more than 2 pages must be in memory
|
// at least more than 2 pages must be in memory
|
||||||
assert(inMemBufSize >= pagesize * 2);
|
ASSERT(inMemBufSize >= pagesize * 2);
|
||||||
|
|
||||||
pPBuf->lruList = tdListNew(POINTER_BYTES);
|
pPBuf->lruList = tdListNew(POINTER_BYTES);
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to LRU list
|
// add to LRU list
|
||||||
assert(listNEles(pBuf->lruList) < pBuf->inMemPages && pBuf->inMemPages > 0);
|
ASSERT(listNEles(pBuf->lruList) < pBuf->inMemPages && pBuf->inMemPages > 0);
|
||||||
lruListPushFront(pBuf->lruList, pi);
|
lruListPushFront(pBuf->lruList, pi);
|
||||||
|
|
||||||
// allocate buf
|
// allocate buf
|
||||||
|
@ -421,11 +421,11 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
||||||
assert(pBuf != NULL && id >= 0);
|
ASSERT(pBuf != NULL && id >= 0);
|
||||||
pBuf->statis.getPages += 1;
|
pBuf->statis.getPages += 1;
|
||||||
|
|
||||||
SPageInfo** pi = taosHashGet(pBuf->all, &id, sizeof(int32_t));
|
SPageInfo** pi = taosHashGet(pBuf->all, &id, sizeof(int32_t));
|
||||||
assert(pi != NULL && *pi != NULL);
|
ASSERT(pi != NULL && *pi != NULL);
|
||||||
|
|
||||||
if ((*pi)->pData != NULL) { // it is in memory
|
if ((*pi)->pData != NULL) { // it is in memory
|
||||||
// no need to update the LRU list if only one page exists
|
// no need to update the LRU list if only one page exists
|
||||||
|
@ -435,7 +435,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SPageInfo** pInfo = (SPageInfo**)((*pi)->pn->data);
|
SPageInfo** pInfo = (SPageInfo**)((*pi)->pn->data);
|
||||||
assert(*pInfo == *pi);
|
ASSERT(*pInfo == *pi);
|
||||||
|
|
||||||
lruListMoveToFront(pBuf->lruList, (*pi));
|
lruListMoveToFront(pBuf->lruList, (*pi));
|
||||||
(*pi)->used = true;
|
(*pi)->used = true;
|
||||||
|
@ -444,7 +444,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
||||||
#endif
|
#endif
|
||||||
return (void*)(GET_DATA_PAYLOAD(*pi));
|
return (void*)(GET_DATA_PAYLOAD(*pi));
|
||||||
} else { // not in memory
|
} else { // not in memory
|
||||||
assert((*pi)->pData == NULL && (*pi)->pn == NULL &&
|
ASSERT((*pi)->pData == NULL && (*pi)->pn == NULL &&
|
||||||
(((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
|
(((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
|
||||||
|
|
||||||
char* availablePage = NULL;
|
char* availablePage = NULL;
|
||||||
|
@ -482,7 +482,9 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
|
void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
|
||||||
assert(pBuf != NULL && page != NULL);
|
if (ASSERTS(pBuf != NULL && page != NULL, "pBuf or page is NULL")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
SPageInfo* ppi = getPageInfoFromPayload(page);
|
SPageInfo* ppi = getPageInfoFromPayload(page);
|
||||||
releaseBufPageInfo(pBuf, ppi);
|
releaseBufPageInfo(pBuf, ppi);
|
||||||
}
|
}
|
||||||
|
@ -491,8 +493,10 @@ void releaseBufPageInfo(SDiskbasedBuf* pBuf, SPageInfo* pi) {
|
||||||
#ifdef BUF_PAGE_DEBUG
|
#ifdef BUF_PAGE_DEBUG
|
||||||
uDebug("page_releaseBufPageInfo pageId:%d, used:%d, offset:%" PRId64, pi->pageId, pi->used, pi->offset);
|
uDebug("page_releaseBufPageInfo pageId:%d, used:%d, offset:%" PRId64, pi->pageId, pi->used, pi->offset);
|
||||||
#endif
|
#endif
|
||||||
// assert(pi->pData != NULL && pi->used == true);
|
if (ASSERTS(pi->pData != NULL, "pi->pData is NULL")) {
|
||||||
assert(pi->pData != NULL);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pi->used = false;
|
pi->used = false;
|
||||||
pBuf->statis.releasePages += 1;
|
pBuf->statis.releasePages += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "trbtree.h"
|
#include "trbtree.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *x) {
|
static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *x) {
|
||||||
SRBTreeNode *y = x->right;
|
SRBTreeNode *y = x->right;
|
||||||
|
@ -258,7 +259,7 @@ static void rbtree_delete_fixup(rbtree_t *rbtree, rbnode_t *child, rbnode_t *chi
|
||||||
child_parent->color = BLACK;
|
child_parent->color = BLACK;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(sibling != RBTREE_NULL);
|
ASSERTS(sibling != RBTREE_NULL, "sibling is NULL");
|
||||||
|
|
||||||
/* get a new sibling, by rotating at sibling. See which child
|
/* get a new sibling, by rotating at sibling. See which child
|
||||||
of sibling is red */
|
of sibling is red */
|
||||||
|
@ -288,11 +289,11 @@ static void rbtree_delete_fixup(rbtree_t *rbtree, rbnode_t *child, rbnode_t *chi
|
||||||
sibling->color = child_parent->color;
|
sibling->color = child_parent->color;
|
||||||
child_parent->color = BLACK;
|
child_parent->color = BLACK;
|
||||||
if (child_parent->right == child) {
|
if (child_parent->right == child) {
|
||||||
assert(sibling->left->color == RED);
|
ASSERTS(sibling->left->color == RED, "slibing->left->color=%d not equal RED", sibling->left->color);
|
||||||
sibling->left->color = BLACK;
|
sibling->left->color = BLACK;
|
||||||
rbtree_rotate_right(rbtree, child_parent);
|
rbtree_rotate_right(rbtree, child_parent);
|
||||||
} else {
|
} else {
|
||||||
assert(sibling->right->color == RED);
|
ASSERTS(sibling->right->color == RED, "slibing->right->color=%d not equal RED", sibling->right->color);
|
||||||
sibling->right->color = BLACK;
|
sibling->right->color = BLACK;
|
||||||
rbtree_rotate_left(rbtree, child_parent);
|
rbtree_rotate_left(rbtree, child_parent);
|
||||||
}
|
}
|
||||||
|
@ -315,18 +316,18 @@ static void swap_np(rbnode_t **x, rbnode_t **y) {
|
||||||
/** Update parent pointers of child trees of 'parent' */
|
/** Update parent pointers of child trees of 'parent' */
|
||||||
static void change_parent_ptr(rbtree_t *rbtree, rbnode_t *parent, rbnode_t *old, rbnode_t *new) {
|
static void change_parent_ptr(rbtree_t *rbtree, rbnode_t *parent, rbnode_t *old, rbnode_t *new) {
|
||||||
if (parent == RBTREE_NULL) {
|
if (parent == RBTREE_NULL) {
|
||||||
assert(rbtree->root == old);
|
ASSERTS(rbtree->root == old, "root not equal old");
|
||||||
if (rbtree->root == old) rbtree->root = new;
|
if (rbtree->root == old) rbtree->root = new;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(parent->left == old || parent->right == old || parent->left == new || parent->right == new);
|
ASSERT(parent->left == old || parent->right == old || parent->left == new || parent->right == new);
|
||||||
if (parent->left == old) parent->left = new;
|
if (parent->left == old) parent->left = new;
|
||||||
if (parent->right == old) parent->right = new;
|
if (parent->right == old) parent->right = new;
|
||||||
}
|
}
|
||||||
/** Update parent pointer of a node 'child' */
|
/** Update parent pointer of a node 'child' */
|
||||||
static void change_child_ptr(rbtree_t *rbtree, rbnode_t *child, rbnode_t *old, rbnode_t *new) {
|
static void change_child_ptr(rbtree_t *rbtree, rbnode_t *child, rbnode_t *old, rbnode_t *new) {
|
||||||
if (child == RBTREE_NULL) return;
|
if (child == RBTREE_NULL) return;
|
||||||
assert(child->parent == old || child->parent == new);
|
ASSERT(child->parent == old || child->parent == new);
|
||||||
if (child->parent == old) child->parent = new;
|
if (child->parent == old) child->parent = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +372,7 @@ rbnode_t *rbtree_delete(rbtree_t *rbtree, void *key) {
|
||||||
|
|
||||||
/* now delete to_delete (which is at the location where the smright previously was) */
|
/* now delete to_delete (which is at the location where the smright previously was) */
|
||||||
}
|
}
|
||||||
assert(to_delete->left == RBTREE_NULL || to_delete->right == RBTREE_NULL);
|
ASSERT(to_delete->left == RBTREE_NULL || to_delete->right == RBTREE_NULL);
|
||||||
|
|
||||||
if (to_delete->left != RBTREE_NULL)
|
if (to_delete->left != RBTREE_NULL)
|
||||||
child = to_delete->left;
|
child = to_delete->left;
|
||||||
|
|
|
@ -466,7 +466,7 @@ static void taosLockList(int64_t *lockedBy) {
|
||||||
static void taosUnlockList(int64_t *lockedBy) {
|
static void taosUnlockList(int64_t *lockedBy) {
|
||||||
int64_t tid = taosGetSelfPthreadId();
|
int64_t tid = taosGetSelfPthreadId();
|
||||||
if (atomic_val_compare_exchange_64(lockedBy, tid, 0) != tid) {
|
if (atomic_val_compare_exchange_64(lockedBy, tid, 0) != tid) {
|
||||||
assert(false);
|
ASSERTS(false, "atomic_val_compare_exchange_64 tid failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,8 +159,7 @@ static void lockTimerList(timer_list_t* list) {
|
||||||
static void unlockTimerList(timer_list_t* list) {
|
static void unlockTimerList(timer_list_t* list) {
|
||||||
int64_t tid = taosGetSelfPthreadId();
|
int64_t tid = taosGetSelfPthreadId();
|
||||||
if (atomic_val_compare_exchange_64(&(list->lockedBy), tid, 0) != tid) {
|
if (atomic_val_compare_exchange_64(&(list->lockedBy), tid, 0) != tid) {
|
||||||
assert(false);
|
ASSERTS(false, "%" PRId64 " trying to unlock a timer list not locked by current thread.", tid);
|
||||||
tmrError("%" PRId64 " trying to unlock a timer list not locked by current thread.", tid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +505,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* han
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(timer->refCount == 1);
|
ASSERTS(timer->refCount == 1, "timer refCount=%d not expected 1", timer->refCount);
|
||||||
memset(timer, 0, sizeof(*timer));
|
memset(timer, 0, sizeof(*timer));
|
||||||
*pTmrId = (tmr_h)doStartTimer(timer, fp, mseconds, param, ctrl);
|
*pTmrId = (tmr_h)doStartTimer(timer, fp, mseconds, param, ctrl);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
void *tmemmem(const char *haystack, int32_t hlen, const char *needle, int32_t nlen) {
|
void *tmemmem(const char *haystack, int32_t hlen, const char *needle, int32_t nlen) {
|
||||||
const char *limit;
|
const char *limit;
|
||||||
|
@ -117,7 +118,7 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
|
||||||
if ((*num) >= size) {
|
if ((*num) >= size) {
|
||||||
size = (size << 1);
|
size = (size << 1);
|
||||||
split = taosMemoryRealloc(split, POINTER_BYTES * size);
|
split = taosMemoryRealloc(split, POINTER_BYTES * size);
|
||||||
assert(NULL != split);
|
ASSERTS(NULL != split, "realloc memory failed. size=%d", POINTER_BYTES * size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +159,9 @@ char *strtolower(char *dst, const char *src) {
|
||||||
int32_t esc = 0;
|
int32_t esc = 0;
|
||||||
char quote = 0, *p = dst, c;
|
char quote = 0, *p = dst, c;
|
||||||
|
|
||||||
assert(dst != NULL);
|
if (ASSERTS(dst != NULL, "dst is NULL")) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (c = *src++; c; c = *src++) {
|
for (c = *src++; c; c = *src++) {
|
||||||
if (esc) {
|
if (esc) {
|
||||||
|
@ -185,7 +188,10 @@ char *strntolower(char *dst, const char *src, int32_t n) {
|
||||||
int32_t esc = 0;
|
int32_t esc = 0;
|
||||||
char quote = 0, *p = dst, c;
|
char quote = 0, *p = dst, c;
|
||||||
|
|
||||||
assert(dst != NULL);
|
if (ASSERTS(dst != NULL, "dst is NULL")) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
return dst;
|
return dst;
|
||||||
|
@ -214,7 +220,10 @@ char *strntolower(char *dst, const char *src, int32_t n) {
|
||||||
char *strntolower_s(char *dst, const char *src, int32_t n) {
|
char *strntolower_s(char *dst, const char *src, int32_t n) {
|
||||||
char *p = dst, c;
|
char *p = dst, c;
|
||||||
|
|
||||||
assert(dst != NULL);
|
if (ASSERTS(dst != NULL, "dst is NULL")) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue