smaUtil.c 5.0 KB
Newer Older
C
Cary Xu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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/>.
 */

#include "sma.h"

18
#define TD_QTASKINFO_FNAME_PREFIX "main.tdb"
C
Cary Xu 已提交
19

K
kailixu 已提交
20
#if 0
K
kailixu 已提交
21 22
void tdRSmaQTaskInfoGetFileName(int32_t vgId, int64_t suid, int8_t level, int64_t version, char *outputName) {
  tdRSmaGetFileName(vgId, NULL, VNODE_RSMA_DIR, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName);
C
Cary Xu 已提交
23
}
K
kailixu 已提交
24
#endif
C
Cary Xu 已提交
25

K
kailixu 已提交
26 27 28
void tdRSmaQTaskInfoGetFullName(int32_t vgId, int64_t suid, int8_t level, int64_t version, const char *path,
                                char *outputName) {
  tdRSmaGetFileName(vgId, path, VNODE_RSMA_DIR, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName);
C
Cary Xu 已提交
29 30
}

K
kailixu 已提交
31
#if 0
K
kailixu 已提交
32 33 34 35
void tdRSmaQTaskInfoGetFullPath(int32_t vgId, int8_t level, const char *path, char *outputName) {
  tdRSmaGetDirName(vgId, path, VNODE_RSMA_DIR, true, outputName);
  int32_t rsmaLen = strlen(outputName);
  snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8, level);
C
Cary Xu 已提交
36
}
K
kailixu 已提交
37
#endif
C
Cary Xu 已提交
38

K
kailixu 已提交
39 40 41
void tdRSmaQTaskInfoGetFullPathEx(int32_t vgId, tb_uid_t suid, int8_t level, const char *path, char *outputName) {
  tdRSmaGetDirName(vgId, path, VNODE_RSMA_DIR, true, outputName);
  int32_t rsmaLen = strlen(outputName);
K
kailixu 已提交
42
  snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8 "%s%" PRIi64, level, TD_DIRSEP, suid);
43 44
}

K
kailixu 已提交
45 46 47 48 49
void tdRSmaGetFileName(int32_t vgId, const char *pdname, const char *dname, const char *fname, int64_t suid,
                       int8_t level, int64_t version, char *outputName) {
  if (level >= 0 && suid > 0) {
    if (version >= 0) {
      if (pdname) {
K
kailixu 已提交
50 51
        snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s.%" PRIi64, pdname,
                 TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname,
K
kailixu 已提交
52 53
                 version);
      } else {
K
kailixu 已提交
54 55
        snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s.%" PRIi64, TD_DIRSEP,
                 vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname, version);
K
kailixu 已提交
56
      }
C
Cary Xu 已提交
57
    } else {
K
kailixu 已提交
58
      if (pdname) {
K
kailixu 已提交
59 60
        snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s", pdname,
                 TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname);
K
kailixu 已提交
61
      } else {
K
kailixu 已提交
62 63
        snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s", TD_DIRSEP, vgId,
                 TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname);
K
kailixu 已提交
64
      }
C
Cary Xu 已提交
65
    }
C
Cary Xu 已提交
66
  } else {
K
kailixu 已提交
67
#if 0
K
kailixu 已提交
68 69 70 71 72 73 74 75
    if (version >= 0) {
      if (pdname) {
        snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%sv%d%s%" PRIi64, pdname, TD_DIRSEP, TD_DIRSEP,
                 vgId, TD_DIRSEP, dname, TD_DIRSEP, vgId, fname, version);
      } else {
        snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%sv%d%s%" PRIi64, TD_DIRSEP, vgId, TD_DIRSEP, dname,
                 TD_DIRSEP, vgId, fname, version);
      }
C
Cary Xu 已提交
76
    } else {
K
kailixu 已提交
77 78 79 80 81 82 83
      if (pdname) {
        snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%sv%d%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId,
                 TD_DIRSEP, dname, TD_DIRSEP, vgId, fname);
      } else {
        snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%sv%d%s", TD_DIRSEP, vgId, TD_DIRSEP, dname,
                 TD_DIRSEP, vgId, fname);
      }
C
Cary Xu 已提交
84
    }
K
kailixu 已提交
85
#endif
C
Cary Xu 已提交
86
  }
C
Cary Xu 已提交
87 88
}

K
kailixu 已提交
89
void tdRSmaGetDirName(int32_t vgId, const char *pdname, const char *dname, bool endWithSep, char *outputName) {
C
Cary Xu 已提交
90
  if (pdname) {
C
Cary Xu 已提交
91 92 93 94 95 96 97
    if (endWithSep) {
      snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP,
               dname, TD_DIRSEP);
    } else {
      snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP,
               dname);
    }
C
Cary Xu 已提交
98
  } else {
K
kailixu 已提交
99
#if 0
C
Cary Xu 已提交
100 101 102 103 104
    if (endWithSep) {
      snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s", TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP);
    } else {
      snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, dname);
    }
K
kailixu 已提交
105
#endif
C
Cary Xu 已提交
106
  }
C
Cary Xu 已提交
107
}
C
Cary Xu 已提交
108

C
Cary Xu 已提交
109
// smaXXXUtil ================
K
kailixu 已提交
110
void *tdAcquireSmaRef(int32_t rsetId, int64_t refId) { return taosAcquireRef(rsetId, refId); }
C
Cary Xu 已提交
111

C
Cary Xu 已提交
112
int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId) {
C
Cary Xu 已提交
113
  if (taosReleaseRef(rsetId, refId) < 0) {
C
Cary Xu 已提交
114
    smaWarn("rsma release ref for rsetId:%d refId:%" PRIi64 " failed since %s", rsetId, refId, terrstr());
C
Cary Xu 已提交
115 116 117 118
    return TSDB_CODE_FAILED;
  }

  return TSDB_CODE_SUCCESS;
C
Cary Xu 已提交
119
}