TDengine/source/dnode/vnode/tsdb/inc/tsdbFS.h

121 lines
3.6 KiB
C
Raw Normal View History

2021-01-09 06:25:17 +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/>.
*/
#ifndef _TD_TSDB_FS_H_
#define _TD_TSDB_FS_H_
2021-12-20 09:35:01 +00:00
#if 0
2021-01-13 09:09:32 +00:00
#define TSDB_FS_VERSION 0
2021-08-12 03:53:53 +00:00
// ================== TSDB global config
extern bool tsdbForceKeepFile;
2021-01-13 09:09:32 +00:00
// ================== CURRENT file header info
typedef struct {
2021-01-15 07:43:55 +00:00
uint32_t version; // Current file system version (relating to code)
2021-01-14 08:27:54 +00:00
uint32_t len; // Encode content length (including checksum)
2021-01-13 09:09:32 +00:00
} SFSHeader;
// ================== TSDB File System Meta
2021-01-09 06:25:17 +00:00
typedef struct {
2021-01-15 06:26:59 +00:00
uint32_t version; // Commit version from 0 to increase
2021-01-13 09:09:32 +00:00
int64_t totalPoints; // total points
int64_t totalStorage; // Uncompressed total storage
2021-01-09 06:25:17 +00:00
} STsdbFSMeta;
2021-01-13 09:09:32 +00:00
// ==================
2021-01-09 06:25:17 +00:00
typedef struct {
2021-01-13 09:09:32 +00:00
STsdbFSMeta meta; // FS meta
2021-01-14 08:27:54 +00:00
SMFile* pmf; // meta file pointer
2021-01-13 09:09:32 +00:00
SMFile mf; // meta file
SArray* df; // data file array
} SFSStatus;
2021-01-09 06:25:17 +00:00
typedef struct {
pthread_rwlock_t lock;
SFSStatus* cstatus; // current status
SHashObj* metaCache; // meta cache
SHashObj* metaCacheComp; // meta cache for compact
2021-01-13 09:09:32 +00:00
bool intxn;
2021-01-14 08:27:54 +00:00
SFSStatus* nstatus; // new status
2021-01-09 06:25:17 +00:00
} STsdbFS;
2021-01-13 09:09:32 +00:00
#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus)
#define FS_NEW_STATUS(pfs) ((pfs)->nstatus)
#define FS_IN_TXN(pfs) (pfs)->intxn
2021-01-29 07:17:18 +00:00
#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version)
2021-01-15 11:01:20 +00:00
#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version)
2021-01-13 09:09:32 +00:00
2021-01-09 06:25:17 +00:00
typedef struct {
2021-01-14 08:27:54 +00:00
int direction;
2021-01-13 09:09:32 +00:00
uint64_t version; // current FS version
2021-01-14 08:27:54 +00:00
STsdbFS* pfs;
int index; // used to position next fset when version the same
int fid; // used to seek when version is changed
2021-01-09 06:25:17 +00:00
SDFileSet* pSet;
} SFSIter;
2021-01-14 08:27:54 +00:00
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
2021-01-16 09:24:54 +00:00
STsdbFS *tsdbNewFS(STsdbCfg *pCfg);
2021-01-14 10:03:04 +00:00
void * tsdbFreeFS(STsdbFS *pfs);
2021-01-16 09:24:54 +00:00
int tsdbOpenFS(STsdbRepo *pRepo);
void tsdbCloseFS(STsdbRepo *pRepo);
2021-01-16 17:34:21 +00:00
void tsdbStartFSTxn(STsdbRepo *pRepo, int64_t pointsAdd, int64_t storageAdd);
int tsdbEndFSTxn(STsdbRepo *pRepo);
2021-01-15 07:43:55 +00:00
int tsdbEndFSTxnWithError(STsdbFS *pfs);
void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta);
2021-01-14 10:03:04 +00:00
void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile);
int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet);
2021-01-09 06:25:17 +00:00
2021-01-14 15:03:57 +00:00
void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction);
void tsdbFSIterSeek(SFSIter *pIter, int fid);
SDFileSet *tsdbFSIterNext(SFSIter *pIter);
2021-01-21 02:31:58 +00:00
int tsdbLoadMetaCache(STsdbRepo *pRepo, bool recoverMeta);
2021-01-14 15:03:57 +00:00
2021-01-13 09:09:32 +00:00
static FORCE_INLINE int tsdbRLockFS(STsdbFS* pFs) {
2021-01-09 06:25:17 +00:00
int code = pthread_rwlock_rdlock(&(pFs->lock));
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
return 0;
}
2021-01-13 09:09:32 +00:00
static FORCE_INLINE int tsdbWLockFS(STsdbFS* pFs) {
2021-01-09 06:25:17 +00:00
int code = pthread_rwlock_wrlock(&(pFs->lock));
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
return 0;
}
2021-01-13 09:09:32 +00:00
static FORCE_INLINE int tsdbUnLockFS(STsdbFS* pFs) {
2021-01-09 06:25:17 +00:00
int code = pthread_rwlock_unlock(&(pFs->lock));
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
return 0;
}
2021-12-20 09:35:01 +00:00
#endif
2021-08-12 03:53:53 +00:00
#endif /* _TD_TSDB_FS_H_ */