2021-12-15 06:48:47 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-26 11:04:26 +00:00
|
|
|
#include "tsdb.h"
|
2021-12-15 06:48:47 +00:00
|
|
|
|
2022-09-06 09:41:06 +00:00
|
|
|
int32_t tRowInfoCmprFn(const void *p1, const void *p2) {
|
2022-08-26 11:07:51 +00:00
|
|
|
SRowInfo *pInfo1 = (SRowInfo *)p1;
|
|
|
|
|
SRowInfo *pInfo2 = (SRowInfo *)p2;
|
|
|
|
|
|
|
|
|
|
if (pInfo1->suid < pInfo2->suid) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (pInfo1->suid > pInfo2->suid) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pInfo1->uid < pInfo2->uid) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (pInfo1->uid > pInfo2->uid) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-11 06:18:04 +00:00
|
|
|
return tsdbRowCompare(&pInfo1->row, &pInfo2->row);
|
2022-08-26 11:07:51 +00:00
|
|
|
}
|
2022-01-08 04:39:12 +00:00
|
|
|
|
2022-06-07 08:49:25 +00:00
|
|
|
int32_t tsdbBegin(STsdb *pTsdb) {
|
2022-06-10 06:48:21 +00:00
|
|
|
int32_t code = 0;
|
2022-09-23 02:40:54 +00:00
|
|
|
int32_t lino = 0;
|
2022-06-01 10:34:17 +00:00
|
|
|
|
2022-06-25 12:46:16 +00:00
|
|
|
if (!pTsdb) return code;
|
|
|
|
|
|
2022-07-19 06:19:01 +00:00
|
|
|
SMemTable *pMemTable;
|
2024-07-17 14:09:09 +00:00
|
|
|
TAOS_CHECK_GOTO(tsdbMemTableCreate(pTsdb, &pMemTable), &lino, _exit);
|
2022-06-01 10:34:17 +00:00
|
|
|
|
2022-07-19 06:19:01 +00:00
|
|
|
// lock
|
2023-10-27 09:48:19 +00:00
|
|
|
if ((code = taosThreadMutexLock(&pTsdb->mutex))) {
|
2024-07-17 14:09:09 +00:00
|
|
|
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(code), &lino, _exit);
|
2022-07-19 06:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pTsdb->mem = pMemTable;
|
|
|
|
|
|
|
|
|
|
// unlock
|
2023-10-27 09:48:19 +00:00
|
|
|
if ((code = taosThreadMutexUnlock(&pTsdb->mutex))) {
|
2024-07-17 14:09:09 +00:00
|
|
|
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(code), &lino, _exit);
|
2022-07-19 06:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-23 02:40:54 +00:00
|
|
|
_exit:
|
|
|
|
|
if (code) {
|
2024-07-17 14:09:09 +00:00
|
|
|
tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pTsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
2022-09-23 02:40:54 +00:00
|
|
|
}
|
2022-06-10 06:48:21 +00:00
|
|
|
return code;
|
2022-06-01 10:34:17 +00:00
|
|
|
}
|