Skip to content

Commit

Permalink
Support server mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwangxp committed Nov 11, 2024
1 parent 153f400 commit e1693bd
Show file tree
Hide file tree
Showing 39 changed files with 1,168 additions and 169 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@
-->

## 0.11.0 <small>(2024-11-11)</small>

**Features**

- Support data types: `BOOL`, `TIMESTAMP`
- Support SQL statements: `CREATE SERVER` `DROP SERVER` `SHOW SERVERS`
- Support APIs: `xdb_connect`
- Support embedded SERVER mode
- Support `xdb-cli` standalone server mode
- Support telnet connection

**Improvements**

**Test**

**Bug Fixes**

- INSERT without column list will set all columns to NULL
- WAL flush with wrong address and range
- Crash when table drop during flush


## 0.10.0 <small>(2024-11-01)</small>

**Features**
Expand All @@ -46,6 +68,7 @@

- Create duplicate database doesn't report error sometimes


## 0.9.0 <small>(2024-10-11)</small>

**Features**
Expand Down Expand Up @@ -75,6 +98,7 @@
- Update transaction crash issue
- SQL syntax error


## 0.8.0 <small>(2024-09-03)</small>

**Features**
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It is designed for high-performance scenarios where the main memory can hold the
- Supports the standard RDBMS model.
- Supports standard SQL and many extensions from MySQL.
- Supports multiple databases.
- Supports embedded and client-server modes (TBD).
- Supports embedded and client-server modes.
- Supports primary keys and multiple secondary indexes.
- Supports HASH and RBTREE (TBD) indexes.
- Supports multi-column indexes.
Expand Down Expand Up @@ -128,3 +128,9 @@ https://crossdb.org/client/api-c/
### Tutorial

https://crossdb.org/get-started/tutorial/

### CrossDB Server

https://crossdb.org/develop/server/

https://crossdb.org/admin/shell/#connect-to-crossdb-server
4 changes: 2 additions & 2 deletions bench/basic/bench-boostmidx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <boost/multi_index/composite_key.hpp>

#define BENCH_DBNAME "Boost"
#define LKUP_COUNT 10000000
#define TEST_NAME(i) i?"Hash":"Order"
int LKUP_COUNT = 10000000;

using namespace std;

Expand Down Expand Up @@ -197,4 +197,4 @@ bool bench_stmt_del_byid (void *pStmt, int id)
bool ok = find_id_hmap.erase(id);
pthread_rwlock_unlock(&stu_tbl_lock);
return ok;
}
}
16 changes: 14 additions & 2 deletions bench/basic/bench-crossdb.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include <crossdb.h>

#define BENCH_DBNAME "CrossDB"
#define LKUP_COUNT 10000000

int LKUP_COUNT = 10000000;

#include "bench.h"

void* bench_open (const char *db)
{
xdb_conn_t* pConn = xdb_open (db);
xdb_conn_t* pConn;
if (!s_bench_svr) {
pConn = xdb_open (db);
} else {
pConn = xdb_connect (NULL, NULL, NULL, NULL, 7777);
xdb_bexec (pConn, "CREATE DATABASE school ENGINE=MEMORY");
xdb_bexec (pConn, "USE school");
LKUP_COUNT = 100000;
}
XDB_CHECK (NULL != pConn, printf ("Can't open connection:\n"); return NULL;);
return pConn;
}
Expand Down Expand Up @@ -44,6 +53,9 @@ bool bench_sql_get_byid (void *pConn, const char *sql, int id, stu_callback call
bool bench_sql_updAge_byid (void *pConn, const char *sql, int id, int age)
{
xdb_res_t *pRes = xdb_bexec (pConn, sql, age, id);
if (pRes->affected_rows != 1) {
printf ("wrong\n");
}
return 1 == pRes->affected_rows;
}

Expand Down
2 changes: 1 addition & 1 deletion bench/basic/bench-sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <sqlite3.h>

#define BENCH_DBNAME "SQLite"
#define LKUP_COUNT 1000000
int LKUP_COUNT = 1000000;

#include "bench.h"

Expand Down
2 changes: 1 addition & 1 deletion bench/basic/bench-stlmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <unordered_map>

#define BENCH_DBNAME "STL"
#define LKUP_COUNT 10000000
#define TEST_NAME(i) i?"HashMap":"Map"
int LKUP_COUNT = 10000000;

using namespace std;

Expand Down
41 changes: 32 additions & 9 deletions bench/basic/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include <sched.h>
#include <pthread.h>

#define SQL_LKUP_COUNT LKUP_COUNT/5
#define UPD_COUNT LKUP_COUNT/10
extern int LKUP_COUNT;
int SQL_LKUP_COUNT;
int UPD_COUNT;

#define BENCH_CHECK(expr, action...) if (!(expr)) { action; }

Expand Down Expand Up @@ -128,13 +129,19 @@ void stu_count_cb (void *pArg, int id, string &name, int age, string &cls, int s

#endif

bool s_bench_svr = false;

#define BENCH_SQL_CREATE "CREATE TABLE student (id INT PRIMARY KEY, name CHAR(16), age INT, class CHAR(16), score INT)"
#define BENCH_SQL_DROP "DROP TABLE IF EXISTS student"
#define BENCH_SQL_INSERT "INSERT INTO student (id,name,age,class,score) VALUES (?,?,?,?,?)"
#define BENCH_SQL_GET_BYID "SELECT * FROM student WHERE id=?"
#define BENCH_SQL_UDPAGE_BYID "UPDATE student SET age=? WHERE id=?"
#define BENCH_SQL_DEL_BYID "DELETE FROM student WHERE id=?"

#define BENCH_SQL_INSERT_NET "INSERT INTO student (id,name,age,class,score) VALUES (%d,'%s',%d,'%s',%d)"
#define BENCH_SQL_GET_BYID_NET "SELECT * FROM student WHERE id=%d"
#define BENCH_SQL_UDPAGE_BYID_NET "UPDATE student SET age=? WHERE id=%d"
#define BENCH_SQL_DEL_BYID_NET "DELETE FROM student WHERE id=%d"

void* bench_open (const char *db);
void bench_close (void *pConn);
Expand Down Expand Up @@ -162,6 +169,10 @@ bool bench_stmt_get_byid (void *pStmt, int id, stu_callback callback, void *pArg
void bench_sql_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pResult)
{
bool ok;
const char *sql_insert = !s_bench_svr ? BENCH_SQL_INSERT : BENCH_SQL_INSERT_NET;
const char *sql_getbyid = !s_bench_svr ? BENCH_SQL_GET_BYID : BENCH_SQL_GET_BYID_NET;
const char *sql_upagebyid = !s_bench_svr ? BENCH_SQL_UDPAGE_BYID : BENCH_SQL_UDPAGE_BYID_NET;
const char *sql_delbyid = !s_bench_svr ? BENCH_SQL_DEL_BYID : BENCH_SQL_DEL_BYID_NET;

bench_sql (pConn, BENCH_SQL_DROP);
bench_sql (pConn, BENCH_SQL_CREATE);
Expand All @@ -171,7 +182,7 @@ void bench_sql_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pRe
bench_print ("------------ INSERT %s ------------\n", qps2str(STU_COUNT));
bench_ts_beg();
for (int i = 0; i < STU_COUNT; ++i) {
ok = bench_sql_insert (pConn, BENCH_SQL_INSERT, STU_BASEID+i, STU_NAME(i), STU_AGE(i), STU_CLASS(i), STU_SCORE(i));
ok = bench_sql_insert (pConn, sql_insert, STU_BASEID+i, STU_NAME(i), STU_AGE(i), STU_CLASS(i), STU_SCORE(i));
BENCH_CHECK (ok, bench_print ("Can't insert student id=%d\n", STU_BASEID+i); return;);
}
pResult->insert_qps += bench_ts_end (STU_COUNT);
Expand All @@ -182,7 +193,7 @@ void bench_sql_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pRe
int count = 0;
bench_ts_beg();
for (int i = 0; i < SQL_LKUP_COUNT; ++i) {
ok = bench_sql_get_byid (pConn, BENCH_SQL_GET_BYID, STU_ID(i), stu_count_cb, &count);
ok = bench_sql_get_byid (pConn, sql_getbyid, STU_ID(i), stu_count_cb, &count);
BENCH_CHECK (ok, bench_print ("Can't get student id=%d\n", STU_ID(i)); return;);
}
qps_sum += bench_ts_end (SQL_LKUP_COUNT);
Expand All @@ -193,15 +204,15 @@ void bench_sql_test (void *pConn, int STU_COUNT, bool bRand, bench_result_t *pRe
bench_print ("------------ %s UPDATE %s ------------\n", ORDER_STR(bRand), qps2str(UPD_COUNT));
bench_ts_beg();
for (int i = 0; i < UPD_COUNT; ++i) {
ok = bench_sql_updAge_byid (pConn, BENCH_SQL_UDPAGE_BYID, STU_ID(i), 10+i%20);
ok = bench_sql_updAge_byid (pConn, sql_upagebyid, STU_ID(i), 10+i%20);
BENCH_CHECK (ok, bench_print ("Can't update student id=%d\n", STU_ID(i)); return;);
}
pResult->update_qps += bench_ts_end (UPD_COUNT);

bench_print ("------------ %s DELETE %s ------------\n", ORDER_STR(bRand), qps2str(STU_COUNT));
bench_ts_beg();
for (int i = 0; i < STU_COUNT; ++i) {
ok = bench_sql_del_byid (pConn, BENCH_SQL_DEL_BYID, STU_ID(i));
ok = bench_sql_del_byid (pConn, sql_delbyid, STU_ID(i));
BENCH_CHECK (ok, bench_print ("Can't delete student id=%d\n", STU_ID(i)); return;);
}
pResult->delete_qps += bench_ts_end (STU_COUNT);
Expand Down Expand Up @@ -297,14 +308,16 @@ int main (int argc, char **argv)
const char *db = ":memory:";

if (argc >= 2) {
while ((ch = getopt(argc, argv, "n:r:c:d:l:qjh")) != -1) {
while ((ch = getopt(argc, argv, "n:r:c:d:l:qjhs")) != -1) {
switch (ch) {
case 'h':
printf ("Usage:\n");
printf (" -h show this help\n");
printf (" -n <row count> default 1000000\n");
printf (" -r <round count> test round, default 1\n");
printf (" -d <dbname> test on-disk db\n");
printf (" -c <cpu core> bind cpu core\n");
printf (" -s test in server db mode\n");
printf (" -q quite mode\n");
return -1;
case 'n':
Expand All @@ -325,6 +338,9 @@ int main (int argc, char **argv)
case 'j':
bCharts = true;
break;
case 's':
s_bench_svr = true;
break;
case 'q':
s_quiet = true;
break;
Expand Down Expand Up @@ -363,6 +379,9 @@ int main (int argc, char **argv)
goto error;
}

SQL_LKUP_COUNT = LKUP_COUNT/5;
UPD_COUNT = LKUP_COUNT/10;

bench_result_t result[4];
memset (&result, 0, sizeof(result));

Expand All @@ -372,12 +391,16 @@ int main (int argc, char **argv)
bench_print ("\n******************** %10s Test *********************\n", "Sequential");

bench_sql_test (pConn, STU_COUNT, false, &result[0]);
bench_stmt_test (pConn, STU_COUNT, false, &result[1]);
if (!s_bench_svr) {
bench_stmt_test (pConn, STU_COUNT, false, &result[1]);
}

bench_print ("\n\n********************* %10s Test *********************\n", "Random");

bench_sql_test (pConn, STU_COUNT, true, &result[2]);
bench_stmt_test (pConn, STU_COUNT, true, &result[3]);
if (!s_bench_svr) {
bench_stmt_test (pConn, STU_COUNT, true, &result[3]);
}
}

for (int i = 0; i < 4; ++i) {
Expand Down
3 changes: 2 additions & 1 deletion examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ int main (int argc, char **argv)
xdb_res_t *pRes;
xdb_row_t *pRow;

xdb_conn_t *pConn = xdb_open (argc > 1 ? argv[1] : ":memory:");
//xdb_conn_t *pConn = xdb_open (argc > 1 ? argv[1] : ":memory:");
xdb_conn_t *pConn = xdb_connect (NULL, NULL, NULL, "memory", 7777);
XDB_CHECK (NULL != pConn, printf ("failed to create DB\n"); return -1;);

// Create Table
Expand Down
10 changes: 4 additions & 6 deletions include/crossdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ typedef enum {
XDB_TYPE_VCHAR = 14, // varied-length string(at most 65535 byte)
XDB_TYPE_VBINARY = 15, // varied-length binary(at most 65535 byte)
XDB_TYPE_BOOL = 16,
// MAC,IPv4,IPv6,CIDR
//XDB_TYPE_DECIMAL = 16, // TBD decimal
//XDB_TYPE_GEOMETRY = 17, // TBD geometry
//XDB_TYPE_JSON = 18, // TBD json string
//XDB_TYPE_DYNAMIC = 20,
XDB_TYPE_MAX = 21
XDB_TYPE_MAX = 32
} xdb_type_t;


Expand Down Expand Up @@ -224,6 +219,9 @@ xdb_res_t*
xdb_vbexec_cb (xdb_conn_t *pConn, xdb_row_callback callback, void *pArg, const char *sql, va_list ap);
#endif

const void *
xdb_poll (xdb_conn_t *pConn, int *pLen, uint32_t timeout);


/**************************************
Result
Expand Down
Loading

0 comments on commit e1693bd

Please sign in to comment.