Skip to content

Commit 057e0b9

Browse files
committed
Initial push for refactor new CrossDB
1 parent 75ce6bc commit 057e0b9

Some content is hidden

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

67 files changed

+14454
-1232
lines changed

CHANGELOG.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Change Log
22

3-
## 0.5.0 <small>(2023-06-26)</small> {#0.5.0}
3+
## 0.6.0 <small>(2024-08-15)</small>
4+
5+
- **Initial refactor release**
6+
7+
- This project was redesigned and rewritten from scratch
8+
- Standard RDBMS model
9+
- New APIs which can support more languages
10+
11+
12+
## 0.5.0 <small>(2023-06-26)</small>
413

514
Features
615

@@ -12,7 +21,7 @@ Features
1221
Bug Fixes
1322

1423

15-
## 0.4.0 <small>(2023-06-20)</small> {#0.4.0}
24+
## 0.4.0 <small>(2023-06-20)</small>
1625

1726
Features
1827

@@ -23,7 +32,7 @@ Features
2332
Bug Fixes
2433

2534

26-
## 0.3.0 <small>(2023-06-13)</small> {#0.3.0}
35+
## 0.3.0 <small>(2023-06-13)</small>
2736

2837
Features
2938

@@ -35,7 +44,7 @@ Bug Fixes
3544
- `cross_dbTblCreate` flags `CROSS_DB_RBTREE` doesn't create Primary Key Index type correctly
3645

3746

38-
## 0.2.0 <small>(2023-06-07)</small> {#0.2.0}
47+
## 0.2.0 <small>(2023-06-07)</small>
3948

4049
Features
4150

@@ -45,7 +54,7 @@ Features
4554
Bug Fixes
4655

4756

48-
## 0.1.0 <small>(2023-06-03)</small> {#0.1.0}
57+
## 0.1.0 <small>(2023-06-03)</small>
4958

5059
- **Initial release**
5160

LICENSE

Lines changed: 674 additions & 201 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
help:
2+
@echo "make build Build crossdb library and tool"
3+
@echo "make debug Build crossdb library and tool with debug"
4+
@echo "make run Run crossdb tool"
5+
@echo "make clean Clean build result"
6+
@echo "make install Install crossdb(lib&tool&header) to Linux & FreeBSD"
7+
@echo "make uninstall Uninstall crossdb from Linux & FreeBSD"
8+
@echo "make installmacos Install crossdb(lib&tool&header) to MacOS"
9+
@echo "make uninstallmacos Uninstall crossdb from MacOS"
10+
@echo "make example Build and run example (need to install crossdb first)"
11+
@echo "make bench Build and run bench test (need to install crossdb first)"
12+
13+
.PHONY: build
14+
build:
15+
$(CC) -o build/libcrossdb.so -fPIC -shared -lpthread -O2 src/crossdb.c
16+
$(CC) -o build/crossdb src/main.c -lpthread -O2
17+
cp src/crossdb.h build/
18+
19+
debug:
20+
$(CC) -o build/libcrossdb.so -fPIC -lpthread -shared -g src/crossdb.c
21+
$(CC) -o build/crossdb src/main.c -lpthread -g
22+
cp src/crossdb.h build/
23+
24+
run:
25+
build/crossdb
26+
27+
clean:
28+
rm -rf build/*
29+
make -C examples/c/ clean
30+
make -C bench/c/ clean
31+
32+
wall:
33+
$(CC) -o build/libcrossdb.so -fPIC -shared -lpthread -O2 -Wall src/crossdb.c
34+
$(CC) -o build/crossdb src/main.c -lpthread -O2 -Wall
35+
cp src/crossdb.h build/
36+
37+
gdb:
38+
$(CC) -o build/crossdb src/main.c -lpthread -g
39+
gdb build/crossdb
40+
41+
install:
42+
install -c build/libcrossdb.so /usr/lib/
43+
install -c build/crossdb.h /usr/include/
44+
install -c build/crossdb /usr/bin/
45+
46+
uninstall:
47+
rm -rf /usr/lib/libcrossdb.so
48+
rm -rf /usr/include/crossdb.h
49+
rm -rf /usr/bin/crossdb
50+
51+
installmacos:
52+
$(CC) -o build/libcrossdb.so -dynamiclib -lpthread -O2 src/crossdb.c
53+
install -c build/libcrossdb.so /usr/local/lib/
54+
install -c build/crossdb.h /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
55+
install -c build/crossdb /usr/local/bin/
56+
57+
uninstallmacos:
58+
rm -rf /usr/local/lib/libcrossdb.so
59+
rm -rf /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/crossdb.h
60+
rm -rf /usr/local/bin/crossdb
61+
62+
example:
63+
make -C examples/c/
64+
65+
.PHONY: bench
66+
bench:
67+
make -C bench/c/

README.md

Lines changed: 47 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -4,189 +4,67 @@
44
</a>
55
</p>
66
<p align="center">
7-
<strong>The Fastest Embedded Database in the world</strong>
7+
<strong>Super High-performance Embedded and Server RDBMS</strong>
88
</p>
99

10-
## [CrossDB vs. SQLite3 Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-sqlite3/)
10+
> **NOTE**
11+
> This project was redesigned and rewritten from scratch.
12+
> It's still in early development stage, so please DO NOT use in your project now.
1113
12-
<a href="https://crossdb.org/blog/benchmark/crossdb-vs-sqlite3/">
13-
<img src="https://crossdb.org/images/benchmark/crossdb-vs-sqlite-ramdisk-large.png">
14-
</a>
14+
# Introduction
1515

16-
## [CrossDB vs. CPP STL Map Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-stlmap/)
16+
**CrossDB** is a super high-performance embedded and server RDBMS.
17+
It's developed for high performance scenarios with main memory can hold whole DB.
1718

18-
<a href="https://crossdb.org/blog/benchmark/crossdb-vs-stlmap/">
19-
<img src="https://crossdb.org/images/benchmark/crossdb-vs-stlmap-large.png">
20-
</a>
19+
## Features
2120

22-
## [CrossDB vs. CPP STL Hashmap Benchmark](https://crossdb.org/blog/benchmark/crossdb-vs-stlhmap/)
21+
- Support Multiple OS Platforms: Linux/Windows/MacOS/FreeBSD etc
22+
- Support Multiple CPU ARCH: X86/ARM/PPC/MIPS etc
23+
- Support OnDisk/In-memory/RamDisk/Hybrid Storage
24+
- Support Standard RDBMS model
25+
- Support MySQL like SQL
26+
- Support Multiple databases
27+
- Support Primary Key and multiple Secondary Indexes
28+
- Support HASH and RBTREE(TBD) Index
29+
- Support Multi-columns Index
30+
- Support Exact Match, Leftmost Match(TBD), Range Match(TBD)
31+
- Support Standard ACID Transaction (begin/commit/rollback)
32+
- Support WAL for OnDisk storage(TBD)
33+
- Support Multiple Threads and Multiple Processes Access
34+
- Support Table level read-write lock
35+
- Support Reader-Writer MVCC
36+
- Support Embedded CrossDB Shell
37+
- Support Multi-Statments APIs
38+
- Support Prepared Statments APIs
39+
- Super High Performance
40+
- Very Simple: Simple header and library file
41+
- Zero Config: no complex config, real out-of-the-box
2342

24-
<a href="https://crossdb.org/blog/benchmark/crossdb-vs-stlhmap/">
25-
<img src="https://crossdb.org/images/benchmark/crossdb-vs-stlhmap-large.png">
26-
</a>
43+
## Use Cases
2744

28-
## CrossDB CLI
45+
- You can use CrossDB In-Memory DB to manage Process Runtime Data to replace STL or hand-wrting data structures.
46+
- You can use CrossDB RamDisk DB to support Process Restartability, In-Service Software Upgrade(ISSU) easily.
47+
- You can use CrossDB OnDisk DB to store data on Disk/Flash/SDD.
48+
- You can use CrossDB to work as a super fast cache DB.
2949

30-
![img](https://crossdb.org/images/crossdb-cli.gif)
50+
## Build and Install
3151

32-
## CrossDB Model
52+
make
53+
make install
3354

34-
![img](https://crossdb.org/images/crossdb-model.png)
55+
## Contribution
56+
In order to keep CrossDB quality and high-performance, this project does not
57+
accept patches.
3558

36-
## Learn CrossDB in 5 Minutes
59+
If you would like to suggest a change and you include a patch as a proof-of-
60+
concept, that would be great.
3761

38-
### 🛶 Define Schema
62+
However, please do not be offended if we rewrite your patch from scratch.
3963

40-
``` c linenums="1"
41-
typedef struct {
42-
uint32_t prefix;
43-
uint8_t mask;
44-
uint32_t nexthop;
45-
uint8_t metric;
46-
char intf[16];
47-
uint32_t birth;
48-
uint32_t flags;
49-
} route_t;
64+
Following contributions are welcome:
5065

51-
#undef CROSS_STRUCT_NAME
52-
#define CROSS_STRUCT_NAME route_t
53-
cross_field_t route_schema[] = {
54-
CROSS_FIELD (prefix, UINT, IPv4, 0),
55-
CROSS_FIELD (mask, UINT, DFT, 0),
56-
CROSS_FIELD (nexthop, UINT, IPv4, 0),
57-
CROSS_FIELD (metric, UINT, DFT, 0),
58-
CROSS_FIELD (intf, CHAR, DFT, 0),
59-
CROSS_FIELD (birth, UINT, TS, 0),
60-
CROSS_FIELD (flags, UINT, HEX, 0),
61-
CROSS_END (route_t)
62-
};
63-
```
64-
65-
### ⚙️ Create DB
66-
67-
``` c linenums="1"
68-
#define CHECK(ret,str) if (ret < 0) { printf (str": %s\n", cross_errMsg(ret)); return -1; }
69-
70-
cross_db_h hDb;
71-
cross_tbl_h hRtTbl;
72-
cross_ret ret;
73-
route_t route;
74-
cross_rowid count;
75-
76-
// Create database
77-
ret = cross_dbCreate (&hDb, "db_data/example", 0);
78-
CHECK (ret, "Failed to create db: example");
79-
80-
// Create table: route (Primary Key: prefix,mask)
81-
ret = cross_dbTblCreate (hDb, &hRtTbl, "route", route_schema, "prefix,mask", 0);
82-
CHECK (ret, "Failed to create table: route table");
83-
84-
// Create index on nexthop: idx_nexthop
85-
ret = cross_dbIdxCreate (hRtTbl, "idx_nexthop", "nexthop", 0);
86-
CHECK (ret, "Failed to create index: idx_nexthop");
87-
```
88-
89-
### ⚜️ Insert Rows
90-
91-
``` c linenums="1"
92-
#define IP4ADDR(a,b,c,d) ((a)<<24|(b)<<16|(c)<<8|(d))
93-
94-
// Insert route 192.168.1.0/24->192.168.1.254
95-
route.prefix = IP4ADDR(192,168,1,0);
96-
route.mask = 24;
97-
route.nexthop = IP4ADDR(192,168,1,254);
98-
route.metric = 1;
99-
route.flags = 0;
100-
strcpy (route.intf, "eth1");
101-
route.birth = time (NULL);
102-
ret = cross_dbInsertRow (hRtTbl, &route, 0);
103-
CHECK (ret, "Failed to insert route 192.168.1.0/24");
104-
```
105-
106-
### 🚀 Query Rows
107-
108-
``` c linenums="1"
109-
#define IP4STR(ip) ip>>24,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff
110-
111-
// Get single route 192.168.1.0/24 by Primary Key
112-
route.prefix = IP4ADDR(192,168,1,0);
113-
route.mask = 24;
114-
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0);
115-
CHECK (ret, "Failed to get route 192.168.1.0/24 by Primary Key");
116-
printf ("Get single route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
117-
IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);
118-
119-
// Get one row where nexthop=192.168.1.254
120-
route.nexthop = IP4ADDR(192,168,1,254);
121-
ret = cross_dbGetOneRow (hRtTbl, "nexthop", &route, &route, 0);
122-
CHECK (ret, "Failed to get one route where nexthop=192.168.1.254");
123-
printf ("Get one route where nexthop=192.168.1.254: "
124-
"%d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
125-
IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);
126-
```
127-
128-
## 🔫 Update Rows
129-
130-
``` c linenums="1"
131-
// Update single route 192.168.1.0/24 by Primary Key: set flags 0->1 metric 1->3
132-
route.prefix = IP4ADDR(192,168,1,0);
133-
route.mask = 24;
134-
route.metric = 3;
135-
route.flags = 1;
136-
ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags,metric", &route, 0);
137-
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");
138-
139-
// Update routes where nexthop=192.168.1.254: set flags 0->3
140-
route.nexthop = IP4ADDR(192,168,1,254);
141-
route.flags = 3;
142-
count = cross_dbUpdateRows (hRtTbl, "nexthop", &route, "flags", &route, 0);
143-
printf ("Update %d routes where nexthop=10.1.2.254\n", count);
144-
```
145-
146-
## 🎡 Cursor Query
147-
148-
``` c linenums="1"
149-
// Use cursor to get routes where nexthop=192.168.1.254
150-
cross_cursor_h hCursor;
151-
route.nexthop = IP4ADDR(192,168,1,254);
152-
count = cross_dbQueryRows (hRtTbl, &hCursor, "nexthop", &route, 0);
153-
printf ("Query %d routes where nexthop=192.168.1.254\n", count);
154-
while (CROSS_OK == cross_cursorGetNextRow (hCursor, &route, 0)) {
155-
printf (" route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
156-
IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);
157-
}
158-
cross_cursorClose (hCursor, 0);
159-
```
160-
161-
## ✂️ Delete Rows
162-
163-
``` c linenums="1"
164-
// Delete single route 192.168.1.0/24 by Primary Key
165-
route.prefix = IP4ADDR(192,168,1,0);
166-
route.mask = 24;
167-
ret = cross_dbDelRowByPK (hRtTbl, &route, 0);
168-
CHECK (ret, "Failed to delete route 192.168.1.0/24 by Primary Key");
169-
170-
// Delete routes where nexthop=192.168.1.254
171-
route.nexthop = IP4ADDR(192,168,1,254);
172-
count = cross_dbDeleteRows (hRtTbl, "nexthop", &route, 0);
173-
printf ("Delete %d routes where nexthop=192.168.1.254\n", count);
174-
```
175-
176-
## 🌄 Transaction
177-
178-
``` c linenums="1"
179-
ret = cross_dbTransBegin (hDb, 0);
180-
CHECK (ret, "Failed to begin transaction");
181-
// Update single route 192.168.1.0/24 by Primary Key: set flags 0->5
182-
route.prefix = IP4ADDR(192,168,1,0);
183-
route.mask = 24;
184-
route.flags = 5;
185-
ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags", &route, 0);
186-
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");
187-
ret = cross_dbTransCommit (hDb, 0);
188-
CHECK (ret, "Failed to commit transaction");
189-
```
66+
- Language bindings: `Python`, `Java`, `Go`, `CSharp`, `Javascript`, `PHP`, etc
67+
- Test and report bugs
19068

19169
## Want to Lean More?
192-
https://crossdb.org
70+
https://crossdb.org

bench/c/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all:
2+
$(CC) bench.c -O2 -lcrossdb -lpthread
3+
./a.out
4+
5+
fast:
6+
$(CC) bench.c ../../src/crossdb.c -O3 -march=native
7+
./a.out
8+
9+
clean:
10+
rm -f a.out

0 commit comments

Comments
 (0)