vnodeCommit.c 1.8 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
refact  
Hongze Cheng 已提交
16
#include "vnd.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 27
  vnodeBufPoolSwitch(pVnode);
  SVnodeTask *pTask = (SVnodeTask *)malloc(sizeof(*pTask));
H
refact  
Hongze Cheng 已提交
28

H
Hongze Cheng 已提交
29 30
  pTask->execute = vnodeCommit;  // TODO
  pTask->arg = pVnode;           // TODO
H
refact  
Hongze Cheng 已提交
31

H
more  
Hongze Cheng 已提交
32 33 34 35
  tsdbPrepareCommit(pVnode->pTsdb);
  // metaPrepareCommit(pVnode->pMeta);
  // walPreapareCommit(pVnode->pWal);

H
Hongze Cheng 已提交
36 37 38
  vnodeScheduleTask(pTask);
  return 0;
}
H
refact  
Hongze Cheng 已提交
39

H
Hongze Cheng 已提交
40 41 42
int vnodeSyncCommit(SVnode *pVnode) {
  vnodeAsyncCommit(pVnode);
  vnodeWaitCommit(pVnode);
H
Hongze Cheng 已提交
43
  tsem_post(&(pVnode->canCommit));
H
Hongze Cheng 已提交
44 45 46 47
  return 0;
}

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

H
more  
Hongze Cheng 已提交
50 51
  metaCommit(pVnode->pMeta);
  tqCommit(pVnode->pTq);
H
more  
Hongze Cheng 已提交
52
  tsdbCommit(pVnode->pTsdb);
H
more  
Hongze Cheng 已提交
53

H
Hongze Cheng 已提交
54
  vnodeBufPoolRecycle(pVnode);
H
more  
Hongze Cheng 已提交
55
  tsem_post(&(pVnode->canCommit));
H
refact  
Hongze Cheng 已提交
56 57 58 59 60 61 62 63 64 65 66
  return 0;
}

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

static int vnodeEndCommit(SVnode *pVnode) {
  // TODO
  return 0;
H
Hongze Cheng 已提交
67 68 69
}

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