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_

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

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

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

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

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

C
Cary Xu 已提交
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 78 79
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 已提交
80
#endif /* _TD_TSDB_SMA_H_ */