tsdbSma.h 2.2 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_

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

struct SSmaEnv {
  pthread_rwlock_t lock;
24
  TDBEnv           dbEnv;
C
Cary Xu 已提交
25 26 27 28 29
  char *           path;
  SSmaStat *       pStat;
};

#define SMA_ENV_LOCK(env)       ((env)->lock)
C
Cary Xu 已提交
30
#define SMA_ENV_ENV(env)        ((env)->dbEnv)
C
Cary Xu 已提交
31 32 33
#define SMA_ENV_PATH(env)       ((env)->path)
#define SMA_ENV_STAT(env)       ((env)->pStat)
#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
34

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

C
Cary Xu 已提交
42
// internal func
C
Cary Xu 已提交
43
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) {
C
Cary Xu 已提交
44
  int32_t len = 0;
C
Cary Xu 已提交
45
  len += taosEncodeFixedI64(pData, tableUid);
C
Cary Xu 已提交
46 47 48 49 50
  len += taosEncodeFixedU16(pData, colId);
  len += taosEncodeFixedI64(pData, tsKey);
  return len;
}

C
Cary Xu 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
  int code = pthread_rwlock_rdlock(&(pEnv->lock));
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
  int code = pthread_rwlock_wrlock(&(pEnv->lock));
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) {
  int code = pthread_rwlock_unlock(&(pEnv->lock));
  if (code != 0) {
    terrno = TAOS_SYSTEM_ERROR(code);
    return -1;
  }
  return 0;
}

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