diff --git a/include/common/schema.h b/include/common/schema.h new file mode 100644 index 0000000000000000000000000000000000000000..2b19eca76c972dbff713444beeb15b9e763b30af --- /dev/null +++ b/include/common/schema.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_SCHEMA_H_ +#define _TD_SCHEMA_H_ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// ----------------- TSDB COLUMN DEFINITION +typedef struct { + int8_t type; // Column type + int16_t colId; // column ID + int16_t bytes; // column bytes (restore to int16_t in case of misuse) + uint16_t offset; // point offset in SDataRow after the header part. +} STColumn; + +#define colType(col) ((col)->type) +#define colColId(col) ((col)->colId) +#define colBytes(col) ((col)->bytes) +#define colOffset(col) ((col)->offset) + +#define colSetType(col, t) (colType(col) = (t)) +#define colSetColId(col, id) (colColId(col) = (id)) +#define colSetBytes(col, b) (colBytes(col) = (b)) +#define colSetOffset(col, o) (colOffset(col) = (o)) + +// ----------------- TSDB SCHEMA DEFINITION +typedef struct { + int version; // version + int numOfCols; // Number of columns appended + int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + // + // (bytes)) + uint16_t flen; // First part length in a SDataRow after the header part + uint16_t vlen; // pure value part length, excluded the overhead (bytes only) + STColumn columns[]; +} STSchema; + +#define schemaNCols(s) ((s)->numOfCols) +#define schemaVersion(s) ((s)->version) +#define schemaTLen(s) ((s)->tlen) +#define schemaFLen(s) ((s)->flen) +#define schemaVLen(s) ((s)->vlen) +#define schemaColAt(s, i) ((s)->columns + i) +#define tdFreeSchema(s) tfree((s)) + +STSchema *tdDupSchema(STSchema *pSchema); +int tdEncodeSchema(void **buf, STSchema *pSchema); +void * tdDecodeSchema(void *buf, STSchema **pRSchema); + +static FORCE_INLINE int comparColId(const void *key1, const void *key2) { + if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { + return 1; + } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { + return -1; + } else { + return 0; + } +} + +static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { + void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId); + if (ptr == NULL) return NULL; + return (STColumn *)ptr; +} + +// ----------------- SCHEMA BUILDER DEFINITION +typedef struct { + int tCols; + int nCols; + int tlen; + uint16_t flen; + uint16_t vlen; + int version; + STColumn *columns; +} STSchemaBuilder; + +int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); +void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); +int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes); +STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_SCHEMA_H_*/ \ No newline at end of file diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h new file mode 100644 index 0000000000000000000000000000000000000000..082dd4bcdd545997ed17da6db467eeec9a502893 --- /dev/null +++ b/include/libs/parser/parser.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_PARSER_H_ +#define _TD_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_PARSER_H_*/ \ No newline at end of file diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h new file mode 100644 index 0000000000000000000000000000000000000000..205d88970f8ef87e54300dd0a5ab3500f28ba0d4 --- /dev/null +++ b/include/libs/scheduler/scheduler.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_SCHEDULER_H_ +#define _TD_SCHEDULER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_SCHEDULER_H_*/ \ No newline at end of file diff --git a/include/util/tlog.h b/include/util/tlog.h new file mode 100644 index 0000000000000000000000000000000000000000..50bc45e7dd5b7d9aa5bba75d270718175d9e328f --- /dev/null +++ b/include/util/tlog.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef TDENGINE_TLOG_H +#define TDENGINE_TLOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define DEBUG_FATAL 1U +#define DEBUG_ERROR DEBUG_FATAL +#define DEBUG_WARN 2U +#define DEBUG_INFO DEBUG_WARN +#define DEBUG_DEBUG 4U +#define DEBUG_TRACE 8U +#define DEBUG_DUMP 16U + +#define DEBUG_SCREEN 64U +#define DEBUG_FILE 128U + +int32_t taosInitLog(char *logName, int32_t numOfLogLines, int32_t maxFiles); +void taosCloseLog(); +void taosResetLog(); + +void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 3, 4))) +#endif + ; + +void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 3, 4))) +#endif + ; + +void taosDumpData(unsigned char *msg, int32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index 59a65fbfbaad609530aff0ef0e41d584f85fceff..c19a9da7d81d36918bbb11f4f12e3df5e21caa5f 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -2,4 +2,6 @@ add_subdirectory(asvc) add_subdirectory(raft) add_subdirectory(tkv) add_subdirectory(index) -add_subdirectory(wal) \ No newline at end of file +add_subdirectory(wal) +add_subdirectory(parser) +add_subdirectory(scheduler) \ No newline at end of file diff --git a/source/libs/parser/CMakeLists.txt b/source/libs/parser/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h new file mode 100644 index 0000000000000000000000000000000000000000..2c76f1bb96bd64e8288d42095e195eb796441892 --- /dev/null +++ b/source/libs/parser/inc/parserInt.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_PARSER_INT_H_ +#define _TD_PARSER_INT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_PARSER_INT_H_*/ \ No newline at end of file diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c new file mode 100644 index 0000000000000000000000000000000000000000..6dea4a4e57392be988126c579648f39a8270b9bf --- /dev/null +++ b/source/libs/parser/src/parser.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ \ No newline at end of file diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/source/libs/scheduler/CMakeLists.txt b/source/libs/scheduler/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h new file mode 100644 index 0000000000000000000000000000000000000000..3e2cf2d37f9a24d0a2a98f612277c00d885fd4fa --- /dev/null +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_SCHEDULER_INT_H_ +#define _TD_SCHEDULER_INT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_SCHEDULER_INT_H_*/ \ No newline at end of file diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c new file mode 100644 index 0000000000000000000000000000000000000000..6dea4a4e57392be988126c579648f39a8270b9bf --- /dev/null +++ b/source/libs/scheduler/src/scheduler.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ \ No newline at end of file diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index a01c3775397e25849d9e8ff70409db7ac0af90ba..cf2b90fd9e6ff537d3f2fd2b826db8ead4c5be0c 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -51,78 +51,6 @@ extern "C" { memcpy(varDataVal(x), (str), (_size)); \ } while (0); -// ----------------- TSDB COLUMN DEFINITION -typedef struct { - int8_t type; // Column type - int16_t colId; // column ID - int16_t bytes; // column bytes (restore to int16_t in case of misuse) - uint16_t offset; // point offset in SDataRow after the header part. -} STColumn; - -#define colType(col) ((col)->type) -#define colColId(col) ((col)->colId) -#define colBytes(col) ((col)->bytes) -#define colOffset(col) ((col)->offset) - -#define colSetType(col, t) (colType(col) = (t)) -#define colSetColId(col, id) (colColId(col) = (id)) -#define colSetBytes(col, b) (colBytes(col) = (b)) -#define colSetOffset(col, o) (colOffset(col) = (o)) - -// ----------------- TSDB SCHEMA DEFINITION -typedef struct { - int version; // version - int numOfCols; // Number of columns appended - int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + (bytes)) - uint16_t flen; // First part length in a SDataRow after the header part - uint16_t vlen; // pure value part length, excluded the overhead (bytes only) - STColumn columns[]; -} STSchema; - -#define schemaNCols(s) ((s)->numOfCols) -#define schemaVersion(s) ((s)->version) -#define schemaTLen(s) ((s)->tlen) -#define schemaFLen(s) ((s)->flen) -#define schemaVLen(s) ((s)->vlen) -#define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) tfree((s)) - -STSchema *tdDupSchema(STSchema *pSchema); -int tdEncodeSchema(void **buf, STSchema *pSchema); -void * tdDecodeSchema(void *buf, STSchema **pRSchema); - -static FORCE_INLINE int comparColId(const void *key1, const void *key2) { - if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { - return 1; - } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { - return -1; - } else { - return 0; - } -} - -static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { - void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId); - if (ptr == NULL) return NULL; - return (STColumn *)ptr; -} - -// ----------------- SCHEMA BUILDER DEFINITION -typedef struct { - int tCols; - int nCols; - int tlen; - uint16_t flen; - uint16_t vlen; - int version; - STColumn *columns; -} STSchemaBuilder; - -int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); -void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); -int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes); -STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); // ----------------- Semantic timestamp key definition typedef uint64_t TKEY;