resolve_stage.cpp 3.1 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2021/4/13.
//

#include <string.h>
#include <string>

#include "resolve_stage.h"

#include "common/conf/ini.h"
#include "common/io/io.h"
#include "common/lang/string.h"
#include "common/log/log.h"
#include "common/seda/timer_stage.h"
#include "event/sql_event.h"
W
wangyunlai.wyl 已提交
26 27 28
#include "event/session_event.h"
#include "session/session.h"
#include "sql/stmt/stmt.h"
羽飞's avatar
羽飞 已提交
29 30 31 32

using namespace common;

//! Constructor
33 34
ResolveStage::ResolveStage(const char *tag) : Stage(tag)
{}
羽飞's avatar
羽飞 已提交
35 36

//! Destructor
37 38
ResolveStage::~ResolveStage()
{}
羽飞's avatar
羽飞 已提交
39 40

//! Parse properties, instantiate a stage object
41 42
Stage *ResolveStage::make_stage(const std::string &tag)
{
羽飞's avatar
羽飞 已提交
43 44 45 46 47 48 49 50 51 52
  ResolveStage *stage = new (std::nothrow) ResolveStage(tag.c_str());
  if (stage == nullptr) {
    LOG_ERROR("new ResolveStage failed");
    return nullptr;
  }
  stage->set_properties();
  return stage;
}

//! Set properties for this object set in stage specific properties
53 54
bool ResolveStage::set_properties()
{
羽飞's avatar
羽飞 已提交
55 56 57 58 59 60 61 62 63 64 65 66
  //  std::string stageNameStr(stage_name_);
  //  std::map<std::string, std::string> section = g_properties()->get(
  //    stageNameStr);
  //
  //  std::map<std::string, std::string>::iterator it;
  //
  //  std::string key;

  return true;
}

//! Initialize stage params and validate outputs
67 68
bool ResolveStage::initialize()
{
羽飞's avatar
羽飞 已提交
69 70 71
  LOG_TRACE("Enter");

  std::list<Stage *>::iterator stgp = next_stage_list_.begin();
72
  plan_cache_stage_ = *(stgp++);
羽飞's avatar
羽飞 已提交
73 74 75 76 77 78

  LOG_TRACE("Exit");
  return true;
}

//! Cleanup after disconnection
79 80
void ResolveStage::cleanup()
{
羽飞's avatar
羽飞 已提交
81 82 83 84 85
  LOG_TRACE("Enter");

  LOG_TRACE("Exit");
}

86 87
void ResolveStage::handle_event(StageEvent *event)
{
羽飞's avatar
羽飞 已提交
88 89 90
  LOG_TRACE("Enter\n");

  SQLStageEvent *sql_event = static_cast<SQLStageEvent *>(event);
W
wangyunlai.wyl 已提交
91 92 93 94 95 96 97 98 99 100
  if (nullptr == sql_event) {
    LOG_WARN("failed to get sql stage event");
    return;
  }

  SessionEvent *session_event = sql_event->session_event();

  Db *db = session_event->session()->get_current_db();
  if (nullptr == db) {
    LOG_ERROR("cannot current db");
L
Longda Feng 已提交
101
    return;
W
wangyunlai.wyl 已提交
102 103
  }

104
  Command *cmd = sql_event->command().get();
W
wangyunlai.wyl 已提交
105
  Stmt *stmt = nullptr;
106
  RC rc = Stmt::create_stmt(db, *cmd, stmt);
W
wangyunlai.wyl 已提交
107 108
  if (rc != RC::SUCCESS && rc != RC::UNIMPLENMENT) {
    LOG_WARN("failed to create stmt. rc=%d:%s", rc, strrc(rc));
羽飞's avatar
羽飞 已提交
109 110 111
    SqlResult *sql_result = new SqlResult;
    sql_result->set_return_code(rc);
    session_event->set_sql_result(sql_result);
W
wangyunlai.wyl 已提交
112 113 114 115
    return;
  }

  sql_event->set_stmt(stmt);
羽飞's avatar
羽飞 已提交
116

117
  plan_cache_stage_->handle_event(sql_event);
羽飞's avatar
羽飞 已提交
118 119 120 121 122

  LOG_TRACE("Exit\n");
  return;
}

123 124
void ResolveStage::callback_event(StageEvent *event, CallbackContext *context)
{
羽飞's avatar
羽飞 已提交
125 126 127 128 129
  LOG_TRACE("Enter\n");

  LOG_TRACE("Exit\n");
  return;
}