tsdbSma.h 2.5 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 23
typedef struct SSmaStat SSmaStat;
typedef struct SSmaEnv  SSmaEnv;
typedef struct SSmaEnvs SSmaEnvs;
C
Cary Xu 已提交
24 25

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

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

C
Cary Xu 已提交
40 41 42 43 44 45 46
struct SSmaEnvs {
  int16_t  nTSma;
  int16_t  nRSma;
  SSmaEnv *pTSmaEnv;
  SSmaEnv *pRSmaEnv;
};

C
Cary Xu 已提交
47 48
void  tsdbDestroySmaEnv(SSmaEnv *pSmaEnv);
void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv);
C
Cary Xu 已提交
49
#if 0
50
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
C
Cary Xu 已提交
51
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
C
Cary Xu 已提交
52
#endif
C
Cary Xu 已提交
53

C
Cary Xu 已提交
54
// internal func
C
Cary Xu 已提交
55
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
C
Cary Xu 已提交
56 57
  int32_t len = 0;
  len += taosEncodeFixedI64(pData, tsKey);
C
Cary Xu 已提交
58
  len += taosEncodeFixedI64(pData, groupId);
C
Cary Xu 已提交
59 60 61
  return len;
}

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

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

C
Cary Xu 已提交
80
static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
wafwerar's avatar
wafwerar 已提交
81
  int code = taosThreadRwlockUnlock(&(pEnv->lock));
C
Cary Xu 已提交
82 83 84 85 86 87 88
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

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