tsdbSma.h 2.4 KB
Newer Older
C
Cary Xu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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_SMA_H_
#define _TD_TSDB_SMA_H_

C
Cary Xu 已提交
19 20
#define TSDB_SMA_TEST // remove after test finished

C
Cary Xu 已提交
21 22
typedef struct SSmaStat     SSmaStat;
typedef struct SSmaEnv      SSmaEnv;
C
Cary Xu 已提交
23 24

struct SSmaEnv {
wafwerar's avatar
wafwerar 已提交
25
  TdThreadRwlock lock;
C
Cary Xu 已提交
26 27 28 29
  SDiskID        did;
  TDBEnv         dbEnv;  // TODO: If it's better to put it in smaIndex level?
  char          *path;   // relative path
  SSmaStat      *pStat;
C
Cary Xu 已提交
30 31 32
};

#define SMA_ENV_LOCK(env)       ((env)->lock)
33
#define SMA_ENV_DID(env)        ((env)->did)
C
Cary Xu 已提交
34
#define SMA_ENV_ENV(env)        ((env)->dbEnv)
C
Cary Xu 已提交
35 36 37
#define SMA_ENV_PATH(env)       ((env)->path)
#define SMA_ENV_STAT(env)       ((env)->pStat)
#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
38

C
Cary Xu 已提交
39 40
void  tsdbDestroySmaEnv(SSmaEnv *pSmaEnv);
void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv);
C
Cary Xu 已提交
41
#if 0
42
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
C
Cary Xu 已提交
43
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
C
Cary Xu 已提交
44
#endif
C
Cary Xu 已提交
45

C
Cary Xu 已提交
46
// internal func
C
Cary Xu 已提交
47
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
C
Cary Xu 已提交
48 49
  int32_t len = 0;
  len += taosEncodeFixedI64(pData, tsKey);
C
Cary Xu 已提交
50
  len += taosEncodeFixedI64(pData, groupId);
C
Cary Xu 已提交
51 52 53
  return len;
}

C
Cary Xu 已提交
54
static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
wafwerar's avatar
wafwerar 已提交
55
  int code = taosThreadRwlockRdlock(&(pEnv->lock));
C
Cary Xu 已提交
56 57 58 59 60 61 62
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

C
Cary Xu 已提交
63
static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
wafwerar's avatar
wafwerar 已提交
64
  int code = taosThreadRwlockWrlock(&(pEnv->lock));
C
Cary Xu 已提交
65 66 67 68 69 70 71
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

C
Cary Xu 已提交
72
static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
wafwerar's avatar
wafwerar 已提交
73
  int code = taosThreadRwlockUnlock(&(pEnv->lock));
C
Cary Xu 已提交
74 75 76 77 78 79 80
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

C
Cary Xu 已提交
81
#endif /* _TD_TSDB_SMA_H_ */