snode.c 3.4 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/>.
 */

L
Liu Jicong 已提交
16
#include "executor.h"
S
Shengliang Guan 已提交
17
#include "sndInt.h"
L
Liu Jicong 已提交
18
#include "tuuid.h"
H
refact  
Hongze Cheng 已提交
19

S
Shengliang Guan 已提交
20
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
S
Shengliang Guan 已提交
21
  SSnode *pSnode = calloc(1, sizeof(SSnode));
L
Liu Jicong 已提交
22 23 24
  if (pSnode == NULL) {
    return NULL;
  }
S
Shengliang Guan 已提交
25
  pSnode->msgCb = pOption->msgCb;
L
Liu Jicong 已提交
26 27 28 29 30
  pSnode->pMeta = sndMetaNew();
  if (pSnode->pMeta == NULL) {
    free(pSnode);
    return NULL;
  }
S
Shengliang Guan 已提交
31
  return pSnode;
H
refact  
Hongze Cheng 已提交
32 33
}

L
Liu Jicong 已提交
34 35 36 37
void sndClose(SSnode *pSnode) {
  sndMetaDelete(pSnode->pMeta);
  free(pSnode);
}
S
Shengliang Guan 已提交
38 39 40

int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; }

L
Liu Jicong 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
SStreamMeta *sndMetaNew() {
  SStreamMeta *pMeta = calloc(1, sizeof(SStreamMeta));
  if (pMeta == NULL) {
    return NULL;
  }
  pMeta->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
  if (pMeta->pHash == NULL) {
    free(pMeta);
    return NULL;
  }
  return pMeta;
}

void sndMetaDelete(SStreamMeta *pMeta) {
  taosHashCleanup(pMeta->pHash);
  free(pMeta);
}

int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) {
L
Liu Jicong 已提交
60 61
  for (int i = 0; i < pTask->exec.numOfRunners; i++) {
    pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL);
L
Liu Jicong 已提交
62
  }
L
Liu Jicong 已提交
63 64 65
  return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *));
}

L
Liu Jicong 已提交
66 67 68 69
SStreamTask *sndMetaGetTask(SStreamMeta *pMeta, int32_t taskId) {
  return taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t));
}

L
Liu Jicong 已提交
70 71 72
int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) {
  SStreamTask *pTask = taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t));
  if (pTask == NULL) {
L
Liu Jicong 已提交
73 74
    return -1;
  }
L
Liu Jicong 已提交
75
  free(pTask->exec.qmsg);
L
Liu Jicong 已提交
76 77 78
  // TODO:free executor
  free(pTask);
  return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t));
L
Liu Jicong 已提交
79 80
}

L
Liu Jicong 已提交
81
static int32_t sndProcessTaskExecReq(SSnode *pSnode, SRpcMsg *pMsg) {
L
Liu Jicong 已提交
82 83 84 85 86 87
  /*SStreamExecMsgHead *pHead = pMsg->pCont;*/
  /*int32_t             taskId = pHead->streamTaskId;*/
  /*SStreamTask *pTask = sndMetaGetTask(pSnode->pMeta, taskId);*/
  /*if (pTask == NULL) {*/
  /*return -1;*/
  /*}*/
L
Liu Jicong 已提交
88 89 90
  return 0;
}

S
shm  
Shengliang Guan 已提交
91
void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
L
Liu Jicong 已提交
92
  // stream deploy
L
Liu Jicong 已提交
93 94
  // stream stop/resume
  // operator exec
L
Liu Jicong 已提交
95 96 97 98
  if (pMsg->msgType == TDMT_SND_TASK_DEPLOY) {
    void        *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
    SStreamTask *pTask = malloc(sizeof(SStreamTask));
    if (pTask == NULL) {
S
shm  
Shengliang Guan 已提交
99
      ASSERT(0);
L
Liu Jicong 已提交
100
      return;
L
Liu Jicong 已提交
101 102 103 104 105 106 107
    }
    SCoder decoder;
    tCoderInit(&decoder, TD_LITTLE_ENDIAN, msg, pMsg->contLen - sizeof(SMsgHead), TD_DECODER);
    tDecodeSStreamTask(&decoder, pTask);
    tCoderClear(&decoder);

    sndMetaDeployTask(pSnode->pMeta, pTask);
L
Liu Jicong 已提交
108 109
  } else if (pMsg->msgType == TDMT_SND_TASK_EXEC) {
    sndProcessTaskExecReq(pSnode, pMsg);
L
Liu Jicong 已提交
110
  } else {
L
Liu Jicong 已提交
111
    ASSERT(0);
L
Liu Jicong 已提交
112
  }
L
Liu Jicong 已提交
113 114
}

S
shm  
Shengliang Guan 已提交
115
void sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) {
L
Liu Jicong 已提交
116
  // operator exec
L
Liu Jicong 已提交
117 118 119 120 121
  if (pMsg->msgType == TDMT_SND_TASK_EXEC) {
    sndProcessTaskExecReq(pSnode, pMsg);
  } else {
    ASSERT(0);
  }
L
Liu Jicong 已提交
122
}