patch 4.0
This commit is contained in:
		| @ -16,120 +16,46 @@ | ||||
| #include "share/ob_define.h" | ||||
| #include "sql/ob_sql_define.h" | ||||
| #include "lib/utility/ob_unify_serialize.h" | ||||
| #include "storage/transaction/ob_trans_define.h" | ||||
| namespace oceanbase { | ||||
| namespace sql { | ||||
|  | ||||
| namespace oceanbase | ||||
| { | ||||
| namespace sql | ||||
| { | ||||
| class ObSQLSessionInfo; | ||||
| class TransResult { | ||||
|   OB_UNIS_VERSION(1); | ||||
|  | ||||
| class ObSqlTransUtil | ||||
| { | ||||
| public: | ||||
|   TransResult() : is_incomplete_(false), lock_(), max_sql_no_(0), trans_desc_(NULL) | ||||
|   {} | ||||
|  | ||||
|   void reset(); | ||||
|   const common::ObPartitionArray& get_total_partitions() | ||||
|   { | ||||
|     return total_partitions_; | ||||
|   } | ||||
|   const common::ObPartitionArray& get_response_partitions() | ||||
|   { | ||||
|     return response_partitions_; | ||||
|   } | ||||
|   const transaction::ObPartitionEpochArray& get_part_epoch_list() | ||||
|   { | ||||
|     return part_epoch_list_; | ||||
|   } | ||||
|   int merge_result(const TransResult& other); | ||||
|   int merge_total_partitions(const common::ObPartitionArray& partitions); | ||||
|   int merge_response_partitions(const common::ObPartitionArray& partitions); | ||||
|   int merge_part_epoch_list(const transaction::ObPartitionEpochArray& part_epoch_list); | ||||
|   void set_incomplete() | ||||
|   { | ||||
|     is_incomplete_ = true; | ||||
|   } | ||||
|   bool is_incomplete() const | ||||
|   { | ||||
|     return is_incomplete_; | ||||
|   } | ||||
|   int set_max_sql_no(int64_t sql_no); | ||||
|   int64_t get_max_sql_no() const | ||||
|   { | ||||
|     return max_sql_no_; | ||||
|   } | ||||
|   void set_trans_desc(transaction::ObTransDesc* trans_desc) | ||||
|   { | ||||
|     trans_desc_ = trans_desc; | ||||
|   } | ||||
|   int assign(const TransResult& other); | ||||
|   void clear_stmt_result(); | ||||
|   TO_STRING_KV(K_(total_partitions), K_(part_epoch_list), K_(response_partitions), K_(max_sql_no)); | ||||
|  | ||||
| private: | ||||
|   // collect all partitions for foreign key. | ||||
|   common::ObPartitionArray total_partitions_; | ||||
|   // discard_partitions_ indicates that the transaction in the partition is enabled, | ||||
|   // but the data of partition is not read or written | ||||
|   // record the partition info of the task that was actually executed | ||||
|   // response_partitions_ indicates that the partition must be read or written | ||||
|   // response_partitions_ + discard_partitions_ record the partition info of the task that | ||||
|   // has been start_participants | ||||
|   common::ObPartitionArray response_partitions_; | ||||
|   // part_epoch_list_ record the epoch id of response_partitions_ | ||||
|   // when start_participants executed in the leader replica | ||||
|   transaction::ObPartitionEpochArray part_epoch_list_; | ||||
|   // indicate the partitions array is complete or not. | ||||
|   bool is_incomplete_; | ||||
|   common::ObSpinLock lock_; | ||||
|  | ||||
|   // The transaction layer requires max_sql_no to increase monotonically, | ||||
|   // so it is transmitted across nodes with the help of the sql layer TransResult mechanism. | ||||
|   // But the transaction layer needs to pass from the remote TransDesc object to the local TransDesc object, | ||||
|   // and the existing mechanism of sql can only be from | ||||
|   // The remote TransResult object is passed to the local TransResult object, | ||||
|   // so here is a new TransDesc object | ||||
|   // Pointer to facilitate access to the TransDesc object during transmission. | ||||
|   // ps: This pointer is not set for all TransResult objects, | ||||
|   // such as the two objects of the scheduling thread | ||||
|   // Not in the same session object, it is not convenient to set. | ||||
|   int64_t max_sql_no_; | ||||
|   transaction::ObTransDesc* trans_desc_; | ||||
| }; | ||||
|  | ||||
| class ObSqlTransUtil { | ||||
| public: | ||||
|   /* Determine whether a statement should start a transaction remotely */ | ||||
|   /* 判断一个语句是否应该在远程开启事务 */ | ||||
|   static bool is_remote_trans(bool ac, bool in_trans, ObPhyPlanType ptype) | ||||
|   { | ||||
|     return true == ac && false == in_trans && OB_PHY_PLAN_REMOTE == ptype; | ||||
|   } | ||||
|  | ||||
|   /* Determine whether the transaction can be automatically opened */ | ||||
|   /* 判断是否能够自动开启事务 */ | ||||
|   static bool plan_can_start_trans(bool ac, bool in_trans) | ||||
|   { | ||||
|     UNUSED(ac); | ||||
|     return false == in_trans; | ||||
|   } | ||||
|  | ||||
|   /* Determine whether the current transaction can be automatically ended */ | ||||
|   static bool plan_can_end_trans(bool ac, bool in_trans) | ||||
|   /* 判断是否能够自动结束当前事务 */ | ||||
|   static bool plan_can_end_trans(bool ac, bool explicit_start_trans) | ||||
|   { | ||||
|     return false == in_trans && true == ac; | ||||
|     return false == explicit_start_trans && true == ac; | ||||
|   } | ||||
|  | ||||
|   /* Determine whether cmd can automatically end the previous transaction */ | ||||
|   /* 判断cmd是否能够自动结束上一个事务 */ | ||||
|   static bool cmd_need_new_trans(bool ac, bool in_trans) | ||||
|   { | ||||
|     UNUSED(ac); | ||||
|     return true == in_trans; | ||||
|   } | ||||
|  | ||||
| private: | ||||
|   ObSqlTransUtil(){}; | ||||
|   ~ObSqlTransUtil(){}; | ||||
|   ObSqlTransUtil() {}; | ||||
|   ~ObSqlTransUtil() {}; | ||||
|   DISALLOW_COPY_AND_ASSIGN(ObSqlTransUtil); | ||||
| }; | ||||
| }  // namespace sql | ||||
| }  // namespace oceanbase | ||||
| } | ||||
| } | ||||
| #endif /* OCEANBASE_SQL_TRANS_UTIL_ */ | ||||
| //// end of header file | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 wangzelin.wzl
					wangzelin.wzl