Skip to content

Commit 24d2b42

Browse files
authored
Update Code and Tests. (#7)
* Update. * Update style. * Update code. * Update * Update. * Update. * Update README.md * Update everything. * update * Update * Update BufferRC * Update code. * Update * Update * Update * Update test client. * Update client test 1. * Update unit tests. * Add tests. * Update. * Update format. * Update.
1 parent 59f5757 commit 24d2b42

Some content is hidden

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

99 files changed

+7558
-2869
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
BasedOnStyle: Google
33
ColumnLimit: '80'
44
AllowShortCaseLabelsOnASingleLine: true
5+
AllowShortFunctionsOnASingleLine: Empty
56
...

.clangd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CompileFlags:
2+
Add: -ferror-limit=0

.github/workflows/aarch64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
install: |
2525
apt-get update && apt-get install -y cmake build-essential ninja-build
2626
run: |
27-
cmake -S . -B build -DI_AM_CI_MACHINE=1 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc.cmake
27+
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc.cmake
2828
cmake --build build --target pawndb -j

.github/workflows/docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
2929
- name: build and run doxygen
3030
run: |
31-
cmake -S . -B build -DI_AM_CI_MACHINE=1 -DCI_MACHINE_DOXYGEN_TASK=1 -G Ninja
32-
cmake --build build --target doxygen
31+
cmake -S . -B build -G Ninja -DPAWNDB_ENABLE_DOXYGEN=ON
32+
cmake --build build --target doxygen
3333
3434
- name: Upload artifact
3535
uses: actions/upload-pages-artifact@v3
@@ -40,7 +40,7 @@ jobs:
4040
needs: build
4141
runs-on: ubuntu-latest
4242
environment:
43-
name: github-pages
43+
name: doxygen-pages
4444
url: ${{ steps.deployment.outputs.page_url }}
4545

4646
steps:

.github/workflows/riscv64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
install: |
2525
apt-get update && apt-get install -y cmake build-essential ninja-build
2626
run: |
27-
cmake -S . -B build -DI_AM_CI_MACHINE=1 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc.cmake
27+
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/gcc.cmake
2828
cmake --build build --target pawndb -j

.github/workflows/standalone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
sudo ./llvm.sh 18
3131
3232
- name: configure
33-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DI_AM_CI_MACHINE=1 -DCI_MACHINE_STANDALONE_TASK=1 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
33+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
3434

3535
- name: build app
3636
run: cmake --build build --target pawndb-app -j

.github/workflows/style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919

2020
- name: install required packages
2121
run: |
22-
sudo apt-get update && sudo apt-get install -y clang-format cmake
22+
sudo apt-get update && sudo apt-get install -y clang-format cmake ninja-build
2323
2424
- name: run clang-format
2525
run: |
26-
cmake -S . -B build -DI_AM_CI_MACHINE=1 -DCI_MACHINE_STYLE_TASK=1
26+
cmake -S . -B build -DPAWNDB_ENABLE_STYLE=ON
2727
cmake --build build --target check-clang-format

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
sudo ./llvm.sh 18
3434
3535
- name: configure
36-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DI_AM_CI_MACHINE=1 -DCI_MACHINE_TEST_TASK=1 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
36+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DPAWNDB_ENABLE_TEST=ON -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
3737

3838
- name: build & run test apps
3939
run: |

CMakeLists.txt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
99
project(
1010
pawndb
1111
VERSION 0.1
12-
LANGUAGES CXX
13-
)
12+
LANGUAGES CXX)
1413

1514
# Set the standard to ISO C++17 without extensions
1615
set(CMAKE_CXX_STANDARD 17)
@@ -26,8 +25,7 @@ add_library(${PROJECT_NAME} "")
2625
# include paths
2726
target_include_directories(
2827
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
29-
$<INSTALL_INTERFACE:include/>
30-
)
28+
$<INSTALL_INTERFACE:include/>)
3129

3230
# Install to system default path minimum
3331
include(cmake/install.cmake)
@@ -38,26 +36,24 @@ if(CCACHE_PROGRAM)
3836
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
3937
endif()
4038

39+
# --- Options ---
40+
option(PAWNDB_ENABLE_DOXYGEN "Build documentation with Doxygen" OFF)
41+
option(PAWNDB_ENABLE_STYLE "Enable style checks" OFF)
42+
option(PAWNDB_ENABLE_TEST "Enable testing targets" OFF)
43+
4144
# --- Include standalone and test ---
42-
if(I_AM_CI_MACHINE)
43-
add_subdirectory("source")
44-
if(CI_MACHINE_STYLE_TASK)
45-
add_subdirectory("style")
46-
endif()
47-
if(CI_MACHINE_DOXYGEN_TASK)
48-
add_subdirectory("docs")
49-
endif()
50-
if(CI_MACHINE_TEST_TASK)
51-
enable_testing()
52-
add_subdirectory("test")
53-
endif()
54-
if(CI_MACHINE_STANDALONE_TASK)
55-
add_subdirectory("standalone")
56-
endif()
57-
else()
58-
add_subdirectory("source")
59-
add_subdirectory("standalone")
45+
enable_testing()
46+
add_subdirectory("source")
47+
add_subdirectory("standalone")
48+
49+
if (PAWNDB_ENABLE_TEST)
6050
add_subdirectory("test")
51+
endif()
52+
53+
if (PAWNDB_ENABLE_DOXYGEN)
6154
add_subdirectory("docs")
55+
endif()
56+
57+
if (PAWNDB_ENABLE_STYLE)
6258
add_subdirectory("style")
6359
endif()

README.md

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
1-
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Library/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
21
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Standalone/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
3-
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Install/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
2+
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Test/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
43
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Style/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
54
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/Aarch64/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
65
[![Actions Status](https://github.com/xiahualiu/PawnDB/workflows/RV64/badge.svg)](https://github.com/xiahualiu/PawnDB/actions)
76

87
# PawnDB
98

10-
PawnDB is an open source embedded DBMS that is designed to be ultra fast and secure. Some of the features of PawnDB:
9+
A lightweight, type-safe in-memory database optimized for OLTP workloads.
1110

12-
#### In memory
11+
## Features
1312

14-
The whole database, including a built-in buffer pool, resides in the static section of the memory. PawnDB **DOES NOT** request any heap memory from the OS, and only uses the internal buffer table to manage temporary buffers. However, this also limits the tuple size; the current PawnDB only supports tuples that are less than 65535 bytes, which is also the maximum UDP packet size on a Linux localhost network interface.
13+
### Memory Management
14+
- Zero heap allocation design
15+
- Static memory allocation
16+
- Built-in buffer pool management
17+
- RAII buffer object with reference counting
18+
- Maximum tuple size: 65535 bytes (UDP packet size limit)
1519

16-
#### Lock Scheme: Strict 2-PL
20+
### Transaction Management
21+
- Strict 2-Phase Locking (2PL)
22+
- Tuple-level shared/exclusive locks
23+
- Support lock promotion
24+
- ACID compliance
25+
- Single record operations
26+
- Deadlock prevention.
1727

18-
PawnDB follows the strict 2-PL rule for transactions. However, there is an exception: a transaction can give up its shared lock on a tuple (only at the shrinking phase), which indicates transaction will only read a snapshot of the resources and does not care about the future values of the resources.
19-
20-
#### Lock Scheme: Tuple-Level Shared/Exclusive Locks
21-
22-
PawnDB is intended to be used as an OLTP (Online Transaction Processing) database, so it is designed with tuple-level shared/exclusive locks.
23-
24-
PawnDB only supports fetching/adding/removing one record at a time; this ensures it is free from the ghost record problem, which can typically be solved by adding a table lock.
25-
26-
#### Strong Type
27-
28-
PawnDB code is type-safe; all the tables and tuples must be defined in the code to use during runtime. The PawnDB code also has **NO** dynamic dispatch code, and **NO** virtual functions.
29-
30-
#### Portable
31-
32-
PawnDB code only uses C++ standard library objects, such as `std::array`, `std::mutex`, and `std::condition_variable`, etc.
33-
34-
There is no 3rd party library used in PawnDB, also making it suitable for commercial projects which require no restrictive copyright terms.
35-
36-
For the socket connection part, it uses the UNIX domain socket which is available on most POSIX systems such as various Linux distributions
37-
38-
#### Simple & Lightweight
39-
40-
PawnDB is designed to be able to run on the most tiny SoCs, including those embedded systems.
41-
42-
The memory footprint of PawnDB is very small, even though it has tuple level locks, the overhead of these locks are as low as ~1 bytes per tuple.
28+
### Type Safety
29+
- Compile-time type checking
30+
- Zero dynamic dispatch
31+
- No virtual functions
32+
- Strong type system
4333

4434
## Language
4535

4636
* PawnDB is written in [ISO C++17](https://isocpp.org/std/the-standard), without compiler extensions.
4737
* PawnDB follows [Google coding style](https://google.github.io/styleguide/).
4838

39+
## License
40+
41+
[MIT License](https://github.com/xiahualiu/PawnDB?tab=MIT-1-ov-file#readme)
42+
4943
## Build the Project
5044

51-
### Requirements
45+
### Prerequisites
46+
47+
Hard requirements:
5248

5349
* `clang` version > 16.0, or `gcc` version > 8.0.
5450
* `cmake` version > 3.20.
55-
* `clang-format` version > 18.0.
56-
* `ninja-build`.
57-
* (optional) `ccache` version > 3.4.2.
51+
* `ninja` build system.
52+
53+
* `doxygen` for generating document html. (Optional)
54+
* `gcovr` for showing test coverage report. (Optional)
55+
* `clang-format` version > 18.0. (Optional)
5856

5957
### Build and run the standalone target
6058

@@ -71,20 +69,30 @@ cmake --build build --target pawndb-app
7169
Use the following commands from the project's root directory to run the test suite.
7270

7371
```bash
74-
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
72+
cmake -S . -B build -DPAWNDB_ENABLE_TEST -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
73+
cmake --build build --target clean-coverage
7574
cmake --build build --target run-all-tests
75+
cmake --build build --target show-test-coverage
76+
7677
```
7778

7879
### Check clang-format
7980

8081
```bash
81-
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
82+
cmake -S . -B build -DPAWNDB_ENABLE_STYLE -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
8283
cmake --build build --target check-clang-format
8384
```
8485

8586
### Apply clang-format
8687

8788
```bash
88-
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
89+
cmake -S . -B build -DPAWNDB_ENABLE_STYLE -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
8990
cmake --build build --target apply-clang-format
9091
```
92+
93+
### Build Docs
94+
95+
```bash
96+
cmake -S . -B build -DPAWNDB_ENABLE_DOXYGEN -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/clang.cmake
97+
cmake --build build --target doxygen
98+
```

0 commit comments

Comments
 (0)