Skip to content

Commit 2e2e048

Browse files
committed
bug fixes and modern CI
1 parent d84a54e commit 2e2e048

14 files changed

Lines changed: 123 additions & 62 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: build and test
2+
3+
on: [push]
4+
5+
6+
jobs:
7+
build-and-test:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
release: ["Release", "Debug"]
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Build
17+
run: |
18+
make all CONFIG=${{ matrix.release }}
19+
- name: Main tests
20+
run: |
21+
PWD=$(pwd)
22+
./tests/${{ matrix.release }}/tests $PWD/src/server/${{ matrix.release }}/scache $PWD/testcases/
23+
- name: valgrind test
24+
run: |
25+
PWD=$(pwd)
26+
sudo apt-get install valgrind
27+
valgrind ./tests/${{ matrix.release }}/tests $PWD/src/server/${{ matrix.release }}/scache $PWD/testcases/
28+
- name: Spam test
29+
run: |
30+
echo "todo"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*.user
77
*.sln.docstates
88

9+
.vscode/
10+
911
# Build results
1012

1113
CodeDB/

src/core/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BLOCK_LENGTH 4096
33
#define BLOCK_MAX_LOAD 8192
44
#define MAX_PATH 512
5+
#define SHORT_PATH 400
56
#define NUM_EVENTS 32
67

78
#define CONNECTION_HASH_ENTRIES 1024

src/core/connection.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ static void* connection_handle_accept(void *arg)
425425
}
426426

427427
close(epfd);
428+
429+
return NULL;
428430
}
429431

430432
void connection_event_loop(void (*connection_handler)(cache_connection* connection)) {
@@ -500,7 +502,7 @@ void connection_event_loop(void (*connection_handler)(cache_connection* connecti
500502
ev.data.fd = client_sock;
501503
res = epoll_ctl(epfd, EPOLL_CTL_ADD, client_sock, &ev);
502504
if (res != 0) {
503-
PWARN("epoll_ctl() failed to add %s.", client_sock);
505+
PWARN("epoll_ctl() failed to add %d.", client_sock);
504506
}
505507
}
506508
}
@@ -555,9 +557,9 @@ void connection_event_loop(void (*connection_handler)(cache_connection* connecti
555557
close(fd);
556558
}
557559
}
558-
else
560+
else if(fd == efd)
559561
{
560-
WARN("Unknown connection %d\n", fd);
562+
WARN("Unknown connection %d (in=%d, out=%d, hup=%d)\n", fd, events[n].events & EPOLLIN ? 1 : 0, events[n].events & EPOLLOUT ? 1 : 0, events[n].events & EPOLLHUP ? 1 : 0);
561563
if(fd) assert(fd);
562564
assert(fd != 0 || (settings.daemon_mode && fd >= 0));
563565

src/core/connection.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ void connection_event_loop(void(*connection_handler)(cache_connection* connectio
1212
void connection_setup(struct scache_bind* binds, uint32_t num_binds);
1313
void connection_cleanup();
1414

15-
#define CONNECTION_HASH_KEY(x) x%CONNECTION_HASH_ENTRIES
15+
#define _DEBUG_CONNECTION_HANDLER
16+
#ifdef DEBUG_CONNECTION_HANDLER
17+
#define CONNECTION_HANDLER(con, value) printf("Setting connection handler to " #value "\n"); (con)->handler = (value)
18+
#else
19+
#define CONNECTION_HANDLER(con, value) (con)->handler = (value)
20+
#endif
21+
22+
#define CONNECTION_HASH_KEY(x) (x)%CONNECTION_HASH_ENTRIES
1623

1724
#endif // !defined(CONNECTION_H_INCLUDED_0986159D_B42F_44F7_AC22_75D7DDA2994D)

src/core/db.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static bool db_load_from_save(){
623623
db_block_free(u1);
624624
break;
625625
case 't':
626-
if(sscanf(bp, "t:%s", &buffer2) != 1){
626+
if(sscanf(bp, "t:%s", buffer2) != 1){
627627
WARN("Table parsing error\n");
628628
continue;
629629
}
@@ -640,7 +640,7 @@ static bool db_load_from_save(){
640640
WARN("File entry must be after table\n");
641641
continue;
642642
}
643-
if(sscanf(bp+1, ":%d:%u:%u:%u:%s", &d1, &u2, &u3, &u4, &buffer2) != 5){
643+
if(sscanf(bp+1, ":%d:%u:%u:%u:%s", &d1, &u2, &u3, &u4, buffer2) != 5){
644644
WARN("Entry parsing error\n");
645645
continue;
646646
}
@@ -704,8 +704,8 @@ bool db_open(const char* path) {
704704
bool will_black = false;
705705

706706
//Create paths as char*'s
707-
snprintf(db.path_root, MAX_PATH, "%s/", path);
708-
snprintf(db.path_single, MAX_PATH, "%s/files/", path);
707+
snprintf(db.path_root, SHORT_PATH, "%s/", path);
708+
snprintf(db.path_single, SHORT_PATH, "%s/files/", path);
709709

710710
//Initialize folder structure if it doesnt exist
711711
db_init_folders();
@@ -715,7 +715,7 @@ bool db_open(const char* path) {
715715
db.table_gc = kh_begin(db.tables);
716716

717717
//Load from index if available
718-
snprintf(db.path_blockfile, MAX_PATH, "%s/blockfile.db", path);
718+
snprintf(db.path_blockfile, SHORT_PATH, "%s/blockfile.db", path);
719719

720720
if(!db_load_from_save()){
721721
PWARN("Unable to load index from disk, will blank database");
@@ -736,7 +736,9 @@ bool db_open(const char* path) {
736736
if(will_black){
737737
if(size > (BLOCK_MAX_LOAD * BLOCK_LENGTH)) {
738738
size = BLOCK_MAX_LOAD * BLOCK_LENGTH;
739-
ftruncate(db.fd_blockfile, size);
739+
if(ftruncate(db.fd_blockfile, size) == -1){
740+
PFATAL("Failed to truncate blockfile: %s", db.path_blockfile);
741+
}
740742
db.blocks_exist = (uint32_t)(size / BLOCK_LENGTH);
741743
}
742744
for (off64_t i = 0; i < size; i += BLOCK_LENGTH) {
@@ -782,7 +784,7 @@ void db_target_open(struct cache_target* target, bool write) {
782784
target->fd = db_entry_open(target->entry, 0);
783785
}
784786
if (target->fd <= 0) {
785-
WARN("Unable to open cache file: %d", target->entry);
787+
WARN("Unable to open cache file: %s", target->entry->key);
786788
}
787789
}
788790
else{
@@ -1391,7 +1393,7 @@ static pid_t db_index_flush(bool copyOnWrite){
13911393
if(ce->writing || ce->deleted) continue;
13921394

13931395
//Write entry key to index
1394-
temp = snprintf(buffer, sizeof(buffer), "%s:%d:%u:%u:%u:", ce->block >= 0 ? "b":"e", ce->block, ce->data_length, ce->expires, ce->it);
1396+
temp = snprintf(buffer, sizeof(buffer), "%s:%d:%u:%lu:%u:", ce->block >= 0 ? "b":"e", ce->block, ce->data_length, ce->expires, ce->it);
13951397
if(!full_write(fd, buffer, temp)) goto close_fd;
13961398
if(!full_write(fd, ce->key, ce->key_length)) goto close_fd;
13971399
if(!full_write(fd, "\n", 1)) goto close_fd;

src/core/db.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ struct block_free_node {
1717
/* Details regarding a database */
1818
struct db_details {
1919
//Paths
20-
char path_root[MAX_PATH];
21-
char path_single[MAX_PATH];
22-
char path_blockfile[MAX_PATH];
20+
char path_root[SHORT_PATH];
21+
char path_single[SHORT_PATH];
22+
char path_blockfile[SHORT_PATH];
2323

2424
//Blockfile
2525
int fd_blockfile;

src/core/debug.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
#define PWARN(...) do {} while(0)
2222
#else
2323

24-
#ifdef DEBUG_BUILD
24+
#if defined(DEBUG_BUILD)
25+
#define DEBUG_OUTPUT_ENABLED DEBUG_BUILD
26+
#endif
27+
28+
#ifdef DEBUG_OUTPUT_ENABLED
2529
# define DEBUG(x...) fprintf(stderr, x)
2630
#else
2731
# define DEBUG(x...) do {} while (0)

src/core/http.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ state_action http_read_handle(int epfd, cache_connection* connection) {
7676
do {
7777
run = http_read_handle_state(epfd, connection);
7878
to_end_old = to_end;
79-
to_end = rbuf_read_to_end(&connection->input);
79+
to_end = rbuf_read_remaining(&connection->input);
8080
} while (run == needs_more && to_end != 0 && to_end != to_end_old);
8181

8282
//Handle buffer is full, not being processed
@@ -177,6 +177,6 @@ void http_templates_init() {
177177
}
178178

179179
void http_connection_handler(cache_connection* connection) {
180-
connection->handler = http_handle_method;
180+
CONNECTION_HANDLER(connection, http_handle_method);
181181
connection->state = 0;
182182
}

0 commit comments

Comments
 (0)