Skip to content

Commit f2dbae2

Browse files
committed
chore: optimize CI pipeline and add automated formatting
Summary: - Switched to Ninja build system for speed. - Implemented build matrix for Clang and GCC. - Enabled ccache for faster compilation. - Added automated clang-format style check. - Restyled entire codebase using Google C++ style.
1 parent fed64db commit f2dbae2

45 files changed

Lines changed: 2296 additions & 1877 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
IndentWidth: 4
5+
ColumnLimit: 100
6+
AllowShortFunctionsOnASingleLine: Inline
7+
KeepEmptyLinesAtTheStartOfBlocks: false
8+
...

.github/workflows/ci.yml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,55 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
style-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Run clang-format check
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install -y clang-format
18+
find src include tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format --dry-run --Werror
19+
1020
build-and-test:
21+
needs: style-check
1122
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
compiler: [clang++, g++]
1226

1327
steps:
1428
- uses: actions/checkout@v3
1529

1630
- name: Install dependencies
1731
run: |
1832
sudo apt-get update
19-
sudo apt-get install -y cmake clang clang-tidy llvm
33+
sudo apt-get install -y cmake clang clang-tidy llvm ninja-build ccache
34+
35+
- name: Cache ccache
36+
uses: actions/cache@v3
37+
with:
38+
path: ~/.ccache
39+
key: ${{ runner.os }}-${{ matrix.compiler }}-ccache-${{ github.sha }}
40+
restore-keys: |
41+
${{ runner.os }}-${{ matrix.compiler }}-ccache-
2042
2143
- name: Configure CMake
2244
run: |
2345
mkdir build
2446
cd build
25-
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DBUILD_TESTS=ON -DBUILD_COVERAGE=OFF
47+
export CCACHE_DIR=~/.ccache
48+
cmake .. -G Ninja \
49+
-DCMAKE_CXX_COMPILER=${{ matrix.compiler }} \
50+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
51+
-DBUILD_TESTS=ON \
52+
-DBUILD_COVERAGE=OFF
2653
27-
- name: Build with Clang-Tidy
54+
- name: Build
2855
run: |
2956
cd build
30-
make -j$(nproc) sqlEngineCore
31-
make -j$(nproc)
57+
ninja sqlEngineCore
58+
ninja
3259
3360
- name: Run Tests
3461
run: |
@@ -39,7 +66,3 @@ jobs:
3966
./transaction_manager_tests
4067
./statement_tests
4168
./recovery_tests
42-
43-
- name: Check memory safety (ASan)
44-
run: |
45-
echo "ASan is enabled via CMAKE_CXX_FLAGS in CMakeLists.txt and verified during 'Run Tests' step."

include/catalog/catalog.hpp

Lines changed: 45 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
#include <cstdint>
1010
#include <cstring>
11-
#include <string>
12-
#include <vector>
13-
#include <unordered_map>
11+
#include <fstream>
12+
#include <iostream>
1413
#include <memory>
1514
#include <optional>
15+
#include <string>
16+
#include <unordered_map>
1617
#include <variant>
17-
#include <fstream>
18-
#include <iostream>
18+
#include <vector>
19+
1920
#include "common/value.hpp"
2021

2122
namespace cloudsql {
@@ -27,7 +28,7 @@ using oid_t = uint32_t;
2728
* @brief Column information structure (C++ class)
2829
*/
2930
class ColumnInfo {
30-
public:
31+
public:
3132
std::string name;
3233
common::ValueType type;
3334
uint16_t position;
@@ -37,43 +38,34 @@ class ColumnInfo {
3738
std::optional<std::string> default_value;
3839
uint32_t flags;
3940

40-
ColumnInfo()
41-
: type(common::TYPE_NULL)
42-
, position(0)
43-
, max_length(0)
44-
, nullable(true)
45-
, is_primary_key(false)
46-
, flags(0)
47-
{}
41+
ColumnInfo()
42+
: type(common::TYPE_NULL),
43+
position(0),
44+
max_length(0),
45+
nullable(true),
46+
is_primary_key(false),
47+
flags(0) {}
4848

4949
ColumnInfo(std::string name, common::ValueType type, uint16_t pos)
50-
: name(std::move(name))
51-
, type(type)
52-
, position(pos)
53-
, max_length(0)
54-
, nullable(true)
55-
, is_primary_key(false)
56-
, flags(0)
57-
{}
50+
: name(std::move(name)),
51+
type(type),
52+
position(pos),
53+
max_length(0),
54+
nullable(true),
55+
is_primary_key(false),
56+
flags(0) {}
5857
};
5958

6059
/**
6160
* @brief Index type enumeration
6261
*/
63-
enum class IndexType : uint8_t {
64-
BTree = 0,
65-
Hash = 1,
66-
GiST = 2,
67-
SPGiST = 3,
68-
GIN = 3,
69-
BRIN = 4
70-
};
62+
enum class IndexType : uint8_t { BTree = 0, Hash = 1, GiST = 2, SPGiST = 3, GIN = 3, BRIN = 4 };
7163

7264
/**
7365
* @brief Index information structure (C++ class)
7466
*/
7567
class IndexInfo {
76-
public:
68+
public:
7769
oid_t index_id;
7870
std::string name;
7971
oid_t table_id;
@@ -85,20 +77,19 @@ class IndexInfo {
8577
uint32_t flags;
8678

8779
IndexInfo()
88-
: index_id(0)
89-
, table_id(0)
90-
, index_type(IndexType::BTree)
91-
, is_unique(false)
92-
, is_primary(false)
93-
, flags(0)
94-
{}
80+
: index_id(0),
81+
table_id(0),
82+
index_type(IndexType::BTree),
83+
is_unique(false),
84+
is_primary(false),
85+
flags(0) {}
9586
};
9687

9788
/**
9889
* @brief Table information structure (C++ class)
9990
*/
10091
class TableInfo {
101-
public:
92+
public:
10293
oid_t table_id;
10394
std::string name;
10495
std::vector<ColumnInfo> columns;
@@ -109,13 +100,7 @@ class TableInfo {
109100
uint64_t created_at;
110101
uint64_t modified_at;
111102

112-
TableInfo()
113-
: table_id(0)
114-
, num_rows(0)
115-
, flags(0)
116-
, created_at(0)
117-
, modified_at(0)
118-
{}
103+
TableInfo() : table_id(0), num_rows(0), flags(0), created_at(0), modified_at(0) {}
119104

120105
/**
121106
* @brief Get column by name
@@ -142,47 +127,39 @@ class TableInfo {
142127
/**
143128
* @brief Get number of columns
144129
*/
145-
uint16_t num_columns() const {
146-
return static_cast<uint16_t>(columns.size());
147-
}
130+
uint16_t num_columns() const { return static_cast<uint16_t>(columns.size()); }
148131

149132
/**
150133
* @brief Get number of indexes
151134
*/
152-
uint16_t num_indexes() const {
153-
return static_cast<uint16_t>(indexes.size());
154-
}
135+
uint16_t num_indexes() const { return static_cast<uint16_t>(indexes.size()); }
155136
};
156137

157138
/**
158139
* @brief Database information structure (C++ class)
159140
*/
160141
class DatabaseInfo {
161-
public:
142+
public:
162143
oid_t database_id;
163144
std::string name;
164145
uint32_t encoding;
165146
std::string collation;
166147
std::vector<oid_t> table_ids;
167148
uint64_t created_at;
168149

169-
DatabaseInfo()
170-
: database_id(0)
171-
, encoding(0)
172-
, created_at(0)
173-
{}
150+
DatabaseInfo() : database_id(0), encoding(0), created_at(0) {}
174151
};
175152

176153
/**
177154
* @brief System Catalog class
178155
*/
179156
class Catalog {
180-
public:
157+
public:
181158
/**
182159
* @brief Default constructor
183160
*/
184161
Catalog() : next_oid_(1) {}
185-
162+
186163
/**
187164
* @brief Create a new catalog
188165
*/
@@ -202,8 +179,7 @@ class Catalog {
202179
* @brief Create a new table
203180
* @return Table OID or 0 on error
204181
*/
205-
oid_t create_table(const std::string& table_name,
206-
std::vector<ColumnInfo> columns);
182+
oid_t create_table(const std::string& table_name, std::vector<ColumnInfo> columns);
207183

208184
/**
209185
* @brief Drop a table
@@ -230,8 +206,8 @@ class Catalog {
230206
* @return Index OID or 0 on error
231207
*/
232208
oid_t create_index(const std::string& index_name, oid_t table_id,
233-
std::vector<uint16_t> column_positions,
234-
IndexType index_type, bool is_unique);
209+
std::vector<uint16_t> column_positions, IndexType index_type,
210+
bool is_unique);
235211

236212
/**
237213
* @brief Drop an index
@@ -266,16 +242,12 @@ class Catalog {
266242
/**
267243
* @brief Get database info
268244
*/
269-
const DatabaseInfo& get_database() const {
270-
return database_;
271-
}
245+
const DatabaseInfo& get_database() const { return database_; }
272246

273247
/**
274248
* @brief Set database info
275249
*/
276-
void set_database(const DatabaseInfo& db) {
277-
database_ = db;
278-
}
250+
void set_database(const DatabaseInfo& db) { database_ = db; }
279251

280252
/**
281253
* @brief Print catalog contents
@@ -287,7 +259,7 @@ class Catalog {
287259
*/
288260
uint64_t get_version() const { return version_; }
289261

290-
private:
262+
private:
291263
std::unordered_map<oid_t, std::unique_ptr<TableInfo>> tables_;
292264
DatabaseInfo database_;
293265
oid_t next_oid_;
@@ -296,6 +268,6 @@ class Catalog {
296268
static uint64_t get_current_time();
297269
};
298270

299-
} // namespace cloudsql
271+
} // namespace cloudsql
300272

301-
#endif // SQL_ENGINE_CATALOG_CATALOG_HPP
273+
#endif // SQL_ENGINE_CATALOG_CATALOG_HPP

include/common/config.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@
99
#include <cstdint>
1010
#include <string>
1111

12-
namespace cloudsql { namespace config {
12+
namespace cloudsql {
13+
namespace config {
1314

1415
/**
1516
* @brief Run modes for the database engine
1617
*/
17-
enum class RunMode {
18-
Embedded = 0,
19-
Distributed = 1
20-
};
18+
enum class RunMode { Embedded = 0, Distributed = 1 };
2119

2220
/**
2321
* @brief Server configuration structure (C++ wrapper)
2422
*/
2523
class Config {
26-
public:
24+
public:
2725
static constexpr uint16_t DEFAULT_PORT = 5432;
2826
static constexpr const char* DEFAULT_DATA_DIR = "./data";
2927
static constexpr int DEFAULT_MAX_CONNECTIONS = 100;
@@ -71,14 +69,14 @@ class Config {
7169
*/
7270
void print() const;
7371

74-
private:
72+
private:
7573
/**
7674
* @brief Trim whitespace from string
7775
*/
7876
static std::string trim(const std::string& str);
7977
};
8078

81-
} // namespace config
82-
} // namespace cloudsql
79+
} // namespace config
80+
} // namespace cloudsql
8381

84-
#endif // SQL_ENGINE_COMMON_CONFIG_HPP
82+
#endif // SQL_ENGINE_COMMON_CONFIG_HPP

0 commit comments

Comments
 (0)