vnodeCommit.c 1.6 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/>.
 */

H
Hongze Cheng 已提交
16
#include "vnodeInt.h"
H
refact  
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18 19 20 21
static int  vnodeStartCommit(SVnode *pVnode);
static int  vnodeEndCommit(SVnode *pVnode);
static int  vnodeCommit(void *arg);
static void vnodeWaitCommit(SVnode *pVnode);
H
refact  
Hongze Cheng 已提交
22 23

int vnodeAsyncCommit(SVnode *pVnode) {
H
Hongze Cheng 已提交
24 25
  vnodeWaitCommit(pVnode);

H
Hongze Cheng 已提交
26
  vnodeBufPoolSwitch(pVnode);
H
more  
Hongze Cheng 已提交
27 28
  tsdbPrepareCommit(pVnode->pTsdb);

H
Hongze Cheng 已提交
29 30
  vnodeScheduleTask(vnodeCommit, pVnode);

H
Hongze Cheng 已提交
31 32
  return 0;
}
H
refact  
Hongze Cheng 已提交
33

H
Hongze Cheng 已提交
34 35 36
int vnodeSyncCommit(SVnode *pVnode) {
  vnodeAsyncCommit(pVnode);
  vnodeWaitCommit(pVnode);
H
Hongze Cheng 已提交
37
  tsem_post(&(pVnode->canCommit));
H
Hongze Cheng 已提交
38 39 40 41
  return 0;
}

static int vnodeCommit(void *arg) {
H
Hongze Cheng 已提交
42
  SVnode *pVnode = (SVnode *)arg;
H
refact  
Hongze Cheng 已提交
43

H
Hongze Cheng 已提交
44
  // metaCommit(pVnode->pMeta);
H
more  
Hongze Cheng 已提交
45
  tqCommit(pVnode->pTq);
H
more  
Hongze Cheng 已提交
46
  tsdbCommit(pVnode->pTsdb);
H
more  
Hongze Cheng 已提交
47

H
Hongze Cheng 已提交
48
  vnodeBufPoolRecycle(pVnode);
H
more  
Hongze Cheng 已提交
49
  tsem_post(&(pVnode->canCommit));
H
refact  
Hongze Cheng 已提交
50 51 52 53 54 55 56 57 58 59 60
  return 0;
}

static int vnodeStartCommit(SVnode *pVnode) {
  // TODO
  return 0;
}

static int vnodeEndCommit(SVnode *pVnode) {
  // TODO
  return 0;
H
Hongze Cheng 已提交
61 62 63
}

static FORCE_INLINE void vnodeWaitCommit(SVnode *pVnode) { tsem_wait(&pVnode->canCommit); }