2023-03-23 09:15:51 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-05-08 02:27:55 +00:00
|
|
|
#include "tsdbDef.h"
|
|
|
|
|
|
2023-03-23 09:15:51 +00:00
|
|
|
#ifndef _TSDB_FILE_H
|
|
|
|
|
#define _TSDB_FILE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-05-15 09:26:00 +00:00
|
|
|
typedef struct STFile STFile;
|
|
|
|
|
typedef struct STFileObj STFileObj;
|
2023-04-23 07:31:23 +00:00
|
|
|
|
2023-03-24 09:57:37 +00:00
|
|
|
typedef enum {
|
2023-05-08 02:53:39 +00:00
|
|
|
TSDB_FTYPE_HEAD = 0, // .head
|
|
|
|
|
TSDB_FTYPE_DATA, // .data
|
|
|
|
|
TSDB_FTYPE_SMA, // .sma
|
|
|
|
|
TSDB_FTYPE_TOMB, // .tomb
|
|
|
|
|
TSDB_FTYPE_STT = TSDB_FTYPE_TOMB + 2, // .stt
|
2023-03-24 09:57:37 +00:00
|
|
|
} tsdb_ftype_t;
|
2023-03-23 09:15:51 +00:00
|
|
|
|
2023-05-22 08:28:31 +00:00
|
|
|
enum {
|
2023-05-23 03:19:24 +00:00
|
|
|
TSDB_FSTATE_LIVE = 1,
|
|
|
|
|
TSDB_FSTATE_DEAD,
|
2023-05-22 08:28:31 +00:00
|
|
|
};
|
|
|
|
|
|
2023-05-08 08:16:45 +00:00
|
|
|
#define TSDB_FTYPE_MIN TSDB_FTYPE_HEAD
|
2023-05-08 02:53:39 +00:00
|
|
|
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
|
|
|
|
|
|
2023-05-16 03:39:53 +00:00
|
|
|
// STFile
|
2023-05-19 05:35:32 +00:00
|
|
|
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
|
|
|
|
|
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
|
2024-09-10 02:05:38 +00:00
|
|
|
void tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]);
|
2024-09-10 10:55:02 +00:00
|
|
|
void tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]);
|
2023-05-23 06:18:23 +00:00
|
|
|
bool tsdbIsSameTFile(const STFile *f1, const STFile *f2);
|
|
|
|
|
bool tsdbIsTFileChanged(const STFile *f1, const STFile *f2);
|
2023-04-23 07:31:23 +00:00
|
|
|
|
2023-05-16 03:39:53 +00:00
|
|
|
// STFileObj
|
2023-05-22 08:28:31 +00:00
|
|
|
int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj);
|
2023-05-19 07:16:01 +00:00
|
|
|
int32_t tsdbTFileObjRef(STFileObj *fobj);
|
|
|
|
|
int32_t tsdbTFileObjUnref(STFileObj *fobj);
|
2023-05-23 03:19:24 +00:00
|
|
|
int32_t tsdbTFileObjRemove(STFileObj *fobj);
|
2024-04-08 02:31:49 +00:00
|
|
|
int32_t tsdbTFileObjRemoveUpdateLC(STFileObj *fobj);
|
2023-05-22 10:39:10 +00:00
|
|
|
int32_t tsdbTFileObjCmpr(const STFileObj **fobj1, const STFileObj **fobj2);
|
2023-05-16 03:39:53 +00:00
|
|
|
|
2023-03-24 09:57:37 +00:00
|
|
|
struct STFile {
|
2023-04-10 06:50:50 +00:00
|
|
|
tsdb_ftype_t type;
|
2023-05-15 09:14:45 +00:00
|
|
|
SDiskID did; // disk id
|
2024-04-08 02:31:49 +00:00
|
|
|
int32_t lcn; // last chunk number
|
2023-05-11 10:16:55 +00:00
|
|
|
int32_t fid; // file id
|
|
|
|
|
int64_t cid; // commit id
|
2023-05-08 08:16:45 +00:00
|
|
|
int64_t size;
|
2023-08-23 10:37:29 +00:00
|
|
|
int64_t minVer;
|
|
|
|
|
int64_t maxVer;
|
2023-04-23 07:31:23 +00:00
|
|
|
union {
|
|
|
|
|
struct {
|
2023-05-16 07:19:13 +00:00
|
|
|
int32_t level;
|
2023-05-27 11:01:52 +00:00
|
|
|
} stt[1];
|
2023-04-23 07:31:23 +00:00
|
|
|
};
|
|
|
|
|
};
|
2023-04-10 06:50:50 +00:00
|
|
|
|
2023-05-15 09:14:45 +00:00
|
|
|
struct STFileObj {
|
2023-05-19 09:56:21 +00:00
|
|
|
TdThreadMutex mutex;
|
2023-05-30 10:06:28 +00:00
|
|
|
STFile f[1];
|
2023-05-19 09:56:21 +00:00
|
|
|
int32_t state;
|
|
|
|
|
int32_t ref;
|
2023-11-09 09:44:24 +00:00
|
|
|
int32_t nlevel;
|
2023-05-19 09:56:21 +00:00
|
|
|
char fname[TSDB_FILENAME_LEN];
|
2023-05-15 09:14:45 +00:00
|
|
|
};
|
|
|
|
|
|
2023-03-23 09:15:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-08-23 10:37:29 +00:00
|
|
|
#endif /*_TSDB_FILE_H*/
|