Skip to content

Commit a8f5fd9

Browse files
authored
clang-format (oceanbase#319)
### What problem were solved in this pull request? Issue Number: ref oceanbase#260 clang-format
1 parent edc55d1 commit a8f5fd9

22 files changed

+302
-371
lines changed

src/observer/event/session_event.cpp

+4-15
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,10 @@ See the Mulan PSL v2 for more details. */
1515
#include "session_event.h"
1616
#include "net/communicator.h"
1717

18-
SessionEvent::SessionEvent(Communicator *comm)
19-
: communicator_(comm),
20-
sql_result_(communicator_->session())
21-
{}
18+
SessionEvent::SessionEvent(Communicator *comm) : communicator_(comm), sql_result_(communicator_->session()) {}
2219

23-
SessionEvent::~SessionEvent()
24-
{
25-
}
20+
SessionEvent::~SessionEvent() {}
2621

27-
Communicator *SessionEvent::get_communicator() const
28-
{
29-
return communicator_;
30-
}
22+
Communicator *SessionEvent::get_communicator() const { return communicator_; }
3123

32-
Session *SessionEvent::session() const
33-
{
34-
return communicator_->session();
35-
}
24+
Session *SessionEvent::session() const { return communicator_->session(); }

src/observer/event/session_event.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,33 @@ See the Mulan PSL v2 for more details. */
1414

1515
#pragma once
1616

17-
#include <string.h>
1817
#include <string>
1918

2019
#include "common/seda/stage_event.h"
21-
#include "sql/executor/sql_result.h"
2220
#include "event/sql_debug.h"
21+
#include "sql/executor/sql_result.h"
2322

2423
class Session;
2524
class Communicator;
2625

2726
/**
2827
* @brief 表示一个SQL请求
29-
*
28+
*
3029
*/
31-
class SessionEvent : public common::StageEvent
30+
class SessionEvent : public common::StageEvent
3231
{
3332
public:
3433
SessionEvent(Communicator *client);
3534
virtual ~SessionEvent();
3635

3736
Communicator *get_communicator() const;
38-
Session *session() const;
37+
Session *session() const;
3938

4039
void set_query(const std::string &query) { query_ = query; }
4140

4241
const std::string &query() const { return query_; }
43-
44-
SqlResult *sql_result() { return &sql_result_; }
45-
46-
SqlDebug &sql_debug() { return sql_debug_; }
42+
SqlResult *sql_result() { return &sql_result_; }
43+
SqlDebug &sql_debug() { return sql_debug_; }
4744

4845
private:
4946
Communicator *communicator_ = nullptr; ///< 与客户端通讯的对象

src/observer/event/sql_debug.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,34 @@ See the Mulan PSL v2 for more details. */
1414

1515
#include <stdarg.h>
1616

17+
#include "event/session_event.h"
1718
#include "event/sql_debug.h"
1819
#include "session/session.h"
19-
#include "event/session_event.h"
2020

2121
using namespace std;
2222

23-
void SqlDebug::add_debug_info(const std::string &debug_info)
24-
{
25-
debug_infos_.push_back(debug_info);
26-
}
23+
void SqlDebug::add_debug_info(const string &debug_info) { debug_infos_.push_back(debug_info); }
2724

28-
void SqlDebug::clear_debug_info()
29-
{
30-
debug_infos_.clear();
31-
}
25+
void SqlDebug::clear_debug_info() { debug_infos_.clear(); }
3226

33-
const list<string> &SqlDebug::get_debug_infos() const
34-
{
35-
return debug_infos_;
36-
}
27+
const list<string> &SqlDebug::get_debug_infos() const { return debug_infos_; }
3728

3829
void sql_debug(const char *fmt, ...)
3930
{
40-
Session *session = Session::current_session();
31+
Session *session = Session::current_session();
4132
if (nullptr == session) {
4233
return;
4334
}
4435

4536
SessionEvent *request = session->current_request();
4637
if (nullptr == request) {
47-
return ;
38+
return;
4839
}
4940

5041
SqlDebug &sql_debug = request->sql_debug();
5142

5243
const int buffer_size = 4096;
53-
char *str = new char[buffer_size];
44+
char *str = new char[buffer_size];
5445

5546
va_list ap;
5647
va_start(ap, fmt);

src/observer/event/sql_debug.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ See the Mulan PSL v2 for more details. */
1919

2020
/**
2121
* @brief SQL调试信息
22-
* @details
22+
* @details
2323
* 希望在运行SQL时,可以直接输出一些调试信息到客户端。
2424
* 当前把调试信息都放在了session上,可以随着SQL语句输出。
2525
* 但是现在还不支持与输出调试信息与行数据同步输出。
2626
*/
2727
class SqlDebug
2828
{
2929
public:
30-
SqlDebug() = default;
30+
SqlDebug() = default;
3131
virtual ~SqlDebug() = default;
3232

3333
void add_debug_info(const std::string &debug_info);

src/observer/event/sql_event.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ See the Mulan PSL v2 for more details. */
1414

1515
#include "event/sql_event.h"
1616

17-
#include <cstddef>
18-
1917
#include "event/session_event.h"
20-
#include "sql/parser/parse_defs.h"
2118
#include "sql/stmt/stmt.h"
2219

23-
SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql)
24-
{}
20+
SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql) {}
2521

2622
SQLStageEvent::~SQLStageEvent() noexcept
2723
{

src/observer/event/sql_event.h

+17-47
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ See the Mulan PSL v2 for more details. */
1414

1515
#pragma once
1616

17-
#include <string>
18-
#include <memory>
1917
#include "common/seda/stage_event.h"
2018
#include "sql/operator/physical_operator.h"
19+
#include <memory>
20+
#include <string>
2121

2222
class SessionEvent;
2323
class Stmt;
@@ -32,53 +32,23 @@ class SQLStageEvent : public common::StageEvent
3232
SQLStageEvent(SessionEvent *event, const std::string &sql);
3333
virtual ~SQLStageEvent() noexcept;
3434

35-
SessionEvent *session_event() const
36-
{
37-
return session_event_;
38-
}
35+
SessionEvent *session_event() const { return session_event_; }
3936

40-
const std::string &sql() const
41-
{
42-
return sql_;
43-
}
44-
const std::unique_ptr<ParsedSqlNode> &sql_node() const
45-
{
46-
return sql_node_;
47-
}
48-
Stmt *stmt() const
49-
{
50-
return stmt_;
51-
}
52-
std::unique_ptr<PhysicalOperator> &physical_operator()
53-
{
54-
return operator_;
55-
}
56-
const std::unique_ptr<PhysicalOperator> &physical_operator() const
57-
{
58-
return operator_;
59-
}
37+
const std::string &sql() const { return sql_; }
38+
const std::unique_ptr<ParsedSqlNode> &sql_node() const { return sql_node_; }
39+
Stmt *stmt() const { return stmt_; }
40+
std::unique_ptr<PhysicalOperator> &physical_operator() { return operator_; }
41+
const std::unique_ptr<PhysicalOperator> &physical_operator() const { return operator_; }
6042

61-
void set_sql(const char *sql)
62-
{
63-
sql_ = sql;
64-
}
65-
void set_sql_node(std::unique_ptr<ParsedSqlNode> sql_node)
66-
{
67-
sql_node_ = std::move(sql_node);
68-
}
69-
void set_stmt(Stmt *stmt)
70-
{
71-
stmt_ = stmt;
72-
}
73-
void set_operator(std::unique_ptr<PhysicalOperator> oper)
74-
{
75-
operator_ = std::move(oper);
76-
}
43+
void set_sql(const char *sql) { sql_ = sql; }
44+
void set_sql_node(std::unique_ptr<ParsedSqlNode> sql_node) { sql_node_ = std::move(sql_node); }
45+
void set_stmt(Stmt *stmt) { stmt_ = stmt; }
46+
void set_operator(std::unique_ptr<PhysicalOperator> oper) { operator_ = std::move(oper); }
7747

7848
private:
79-
SessionEvent *session_event_ = nullptr;
80-
std::string sql_; ///< 处理的SQL语句
81-
std::unique_ptr<ParsedSqlNode> sql_node_; ///< 语法解析后的SQL命令
82-
Stmt *stmt_ = nullptr; ///< Resolver之后生成的数据结构
83-
std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
49+
SessionEvent *session_event_ = nullptr;
50+
std::string sql_; ///< 处理的SQL语句
51+
std::unique_ptr<ParsedSqlNode> sql_node_; ///< 语法解析后的SQL命令
52+
Stmt *stmt_ = nullptr; ///< Resolver之后生成的数据结构
53+
std::unique_ptr<PhysicalOperator> operator_; ///< 生成的执行计划,也可能没有
8454
};

src/observer/event/storage_event.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ See the Mulan PSL v2 for more details. */
1818

1919
class SQLStageEvent;
2020

21-
class StorageEvent : public common::StageEvent {
21+
class StorageEvent : public common::StageEvent
22+
{
2223
public:
23-
StorageEvent(SQLStageEvent *sql_event) : sql_event_(sql_event)
24-
{}
24+
StorageEvent(SQLStageEvent *sql_event) : sql_event_(sql_event) {}
2525

2626
virtual ~StorageEvent();
2727

28-
SQLStageEvent *sql_event() const
29-
{
30-
return sql_event_;
31-
}
28+
SQLStageEvent *sql_event() const { return sql_event_; }
3229

3330
private:
3431
SQLStageEvent *sql_event_;

src/observer/net/buffered_writer.cpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,19 @@ See the Mulan PSL v2 for more details. */
1212
// Created by Wangyunlai on 2023/06/16.
1313
//
1414

15+
#include <algorithm>
1516
#include <sys/errno.h>
1617
#include <unistd.h>
17-
#include <algorithm>
1818

1919
#include "net/buffered_writer.h"
2020

2121
using namespace std;
2222

23-
BufferedWriter::BufferedWriter(int fd)
24-
: fd_(fd), buffer_()
25-
{}
23+
BufferedWriter::BufferedWriter(int fd) : fd_(fd), buffer_() {}
2624

27-
BufferedWriter::BufferedWriter(int fd, int32_t size)
28-
: fd_(fd), buffer_(size)
29-
{}
25+
BufferedWriter::BufferedWriter(int fd, int32_t size) : fd_(fd), buffer_(size) {}
3026

31-
BufferedWriter::~BufferedWriter()
32-
{
33-
close();
34-
}
27+
BufferedWriter::~BufferedWriter() { close(); }
3528

3629
RC BufferedWriter::close()
3730
{
@@ -74,6 +67,7 @@ RC BufferedWriter::writen(const char *data, int32_t size)
7467
int32_t write_size = 0;
7568
while (write_size < size) {
7669
int32_t tmp_write_size = 0;
70+
7771
RC rc = write(data + write_size, size - write_size, tmp_write_size);
7872
if (OB_FAIL(rc)) {
7973
return rc;
@@ -105,11 +99,12 @@ RC BufferedWriter::flush_internal(int32_t size)
10599
}
106100

107101
RC rc = RC::SUCCESS;
102+
108103
int32_t write_size = 0;
109104
while (OB_SUCC(rc) && buffer_.size() > 0 && size > write_size) {
110-
const char *buf = nullptr;
111-
int32_t read_size = 0;
112-
rc = buffer_.buffer(buf, read_size);
105+
const char *buf = nullptr;
106+
int32_t read_size = 0;
107+
rc = buffer_.buffer(buf, read_size);
113108
if (OB_FAIL(rc)) {
114109
return rc;
115110
}

src/observer/net/buffered_writer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BufferedWriter
3838
* @brief 写数据到文件/socket
3939
* @details 缓存满会自动刷新缓存
4040
* @param data 要写入的数据
41-
* @param size 要写入的数据大小
41+
* @param size 要写入的数据大小
4242
* @param write_size 实际写入的数据大小
4343
*/
4444
RC write(const char *data, int32_t size, int32_t &write_size);
@@ -67,6 +67,6 @@ class BufferedWriter
6767
RC flush_internal(int32_t size);
6868

6969
private:
70-
int fd_ = -1;
70+
int fd_ = -1;
7171
RingBuffer buffer_;
7272
};

0 commit comments

Comments
 (0)