mndDb.c 1.5 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16
#define _DEFAULT_SOURCE
S
Shengliang Guan 已提交
17
#include "mndDb.h"
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
static int32_t mnodeProcessUseMsg(SMnode *pMnode, SMnodeMsg *pMsg);
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21 22 23 24
int32_t mndInitDb(SMnode *pMnode) {
  mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_USE_DB, mnodeProcessUseMsg);
  return 0;
}
S
Shengliang Guan 已提交
25

S
Shengliang Guan 已提交
26
void mndCleanupDb(SMnode *pMnode) {}
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28 29 30 31
SDbObj *mndAcquireDb(SMnode *pMnode, char *db) {
  SSdb *pSdb = pMnode->pSdb;
  return sdbAcquire(pSdb, SDB_DB, db);
}
S
Shengliang Guan 已提交
32

S
Shengliang Guan 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
  SSdb *pSdb = pMnode->pSdb;
  sdbRelease(pSdb, pDb);
}

static int32_t mnodeProcessUseMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
  SUseDbMsg *pUseDbMsg = pMsg->rpcMsg.pCont;

  strncpy(pMsg->db, pUseDbMsg->db, TSDB_FULL_DB_NAME_LEN);

  SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
  if (pDb != NULL) {
    mndReleaseDb(pMnode, pDb);
    return 0;
  } else {
    mError("db:%s, failed to process use db msg since %s", pMsg->db, terrstr());
    return -1;
  }
}