int trans_begin(Sink* sink) { Result *result; int ret; if(!sink) return -1; result = sink_exec(sink, "begin"); if(!result) return -1; if(result_state(sink, result) == RES_COMMAND_OK) { ret = 0; } else { ret = -1; } result_clean(sink, result); return ret; }
TicTacToeState TicTacToeState::result(position p) { // Copy the information copy_board_and_state(temp_board, game_board, temp_state, state); // Increase temp_state increase_state_array(p.row, p.col, temp_state); // Set p2_or p1 symbol on the board if (player == p2_symbol) temp_board[p.row][p.col] = p2_symbol; else temp_board[p.row][p.col] = p1_symbol; // Construct a new object for return TicTacToeState result_state(board_rows, board_cols, p1_symbol, p2_symbol, turn_of_computer, play_with_computer, mode, temp_board, temp_state, p.row, p.col, turn_count + 1); return result_state; }
/** * get PlanContext and child physical plan from child , * consider PlanContext's partitioner's location and collector, * decide whether add expander and exchange operator in physical plan. * * choose one of three top physical operators depend on fashion_, * return complete physical plan */ PhysicalOperatorBase* LogicalQueryPlanRoot::GetPhysicalPlan( const unsigned& block_size) { PlanContext child_plan_context = GetPlanContext(); /////////// LogicalLimit* limit = NULL; PhysicalOperatorBase* child_iterator = NULL; if (child_->get_operator_type() == OperatorType::kLogicalLimit) { limit = reinterpret_cast<LogicalLimit*>(child_); child_iterator = limit->child_->GetPhysicalPlan(block_size); } else { child_iterator = child_->GetPhysicalPlan(block_size); } ///////////// NodeTracker* node_tracker = NodeTracker::GetInstance(); bool is_exchange_need = false; /** * If the number of partitions in the child PlanContext is 1 and the the * location is right in the collector, * then exchange is not necessary. */ if (!(1 == child_plan_context.plan_partitioner_.GetNumberOfPartitions() && child_plan_context.plan_partitioner_.get_partition_list()[0] .get_location() == collecter_node)) { is_exchange_need = true; // add BlockStreamExpander iterator into physical plan Expander::State expander_state_lower; expander_state_lower.block_count_in_buffer_ = 10; expander_state_lower.block_size_ = block_size; expander_state_lower.init_thread_count_ = Config::initial_degree_of_parallelism; expander_state_lower.child_ = child_iterator; expander_state_lower.schema_ = GetSchema(child_plan_context.attribute_list_); PhysicalOperatorBase* expander_lower = new Expander(expander_state_lower); // add ExchangeEpoll iterator into physical plan ExchangeMerger::State state; state.block_size_ = block_size; state.child_ = expander_lower; // child_iterator; state.exchange_id_ = IDsGenerator::getInstance()->generateUniqueExchangeID(); state.schema_ = GetSchema(child_plan_context.attribute_list_); state.upper_id_list_.push_back(collecter_node); state.partition_schema_ = partition_schema::set_hash_partition(0); std::vector<NodeID> lower_id_list = GetInvolvedNodeID(child_plan_context.plan_partitioner_); state.lower_id_list_ = lower_id_list; child_iterator = new ExchangeMerger(state); } Expander::State expander_state; expander_state.block_count_in_buffer_ = 10; expander_state.block_size_ = block_size; if (is_exchange_need) // if data exchange is used, only one expanded thread is enough. expander_state.init_thread_count_ = 1; else expander_state.init_thread_count_ = Config::initial_degree_of_parallelism; expander_state.child_ = child_iterator; expander_state.schema_ = GetSchema(child_plan_context.attribute_list_); PhysicalOperatorBase* expander = new Expander(expander_state); if (child_->get_operator_type() == OperatorType::kLogicalLimit) { expander = limit->GetPhysicalPlan(block_size, expander); } PhysicalOperatorBase* ret; switch (style_) { case kPrint: { ResultPrinter::State print_state( GetSchema(child_plan_context.attribute_list_), expander, block_size, GetAttributeName(child_plan_context)); ret = new ResultPrinter(print_state); break; } case kPerformance: { PerformanceMonitor::State performance_state( GetSchema(child_plan_context.attribute_list_), expander, block_size); ret = new PerformanceMonitor(performance_state); break; } case kResultCollector: { std::vector<std::string> column_header; GetColumnHeader(column_header, child_plan_context.attribute_list_); physical_operator::ResultCollector::State result_state( GetSchema(child_plan_context.attribute_list_), expander, block_size, column_header); ret = new physical_operator::ResultCollector(result_state); break; } } return ret; }