Skip to content

Commit ac71890

Browse files
committed
feat(server): add/change some log messages
chore(config): add default_conf member chore(database): add returning value to create_cache method
1 parent 8af6717 commit ac71890

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

headers/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdint.h>
2+
#include <stdbool.h>
23

34
#ifndef CONFIG_H
45
#define CONFIG_H
@@ -10,6 +11,7 @@
1011
uint32_t max_log_len;
1112
char data_file[49];
1213
char log_file[49];
14+
bool default_conf;
1315
};
1416

1517
struct Configuration *get_configuration(const char *filename);

headers/database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
off_t pos;
1919
};
2020

21-
void create_cache();
21+
struct BTree *create_cache();
2222
struct BTree *get_cache();
2323
struct KVPair *get_kv_from_cache(const char *key);
2424
void free_cache();

src/database/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
static struct BTree *cache = NULL;
44

5-
void create_cache() {
6-
cache = create_btree(3);
5+
struct BTree *create_cache() {
6+
return (cache = create_btree(3));
77
}
88

99
struct BTree *get_cache() {

src/server/server.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdbool.h>
55
#include <stdlib.h>
66
#include <signal.h>
7+
#include <time.h>
78

89
#include <pthread.h>
910
#include <fcntl.h>
@@ -59,10 +60,10 @@ static void close_server() {
5960
remove_client(client->connfd);
6061
}
6162

62-
write_log(LOG_WARN, "Saving data...");
63+
clock_t start = clock();
6364
save_data();
6465
close_database_fd();
65-
write_log(LOG_INFO, "Saved data and closed database file.");
66+
write_log(LOG_INFO, "Saved data and closed database file in %.2f seconds.", ((float) clock() - start) / CLOCKS_PER_SEC);
6667

6768
deactive_transaction_thread();
6869
usleep(15);
@@ -90,6 +91,14 @@ void start_server(struct Configuration *config) {
9091
conf = config;
9192
initialize_logs(conf);
9293
write_log(LOG_INFO, "Initialized logs and configuration.");
94+
write_log(LOG_INFO, "version=" VERSION ", commit hash=" GIT_HASH);
95+
96+
if (conf->default_conf) {
97+
write_log(LOG_WARN, (
98+
"There is no configuration file, using default configuration. "
99+
"To specify, create .tellyconf file or use `telly config /path/to/file`."
100+
));
101+
}
93102

94103
load_commands();
95104
write_log(LOG_INFO, "Initialized commands.");
@@ -144,12 +153,12 @@ void start_server(struct Configuration *config) {
144153
return;
145154
}
146155

147-
create_cache();
156+
struct BTree *cache = create_cache();
148157
open_database_fd(conf->data_file);
149158
write_log(LOG_INFO, "Created cache and opened database file.");
150159

151160
get_all_keys();
152-
write_log(LOG_INFO, "Read database file to create keyspace.");
161+
write_log(LOG_INFO, "Read database file to create keyspace. Loaded key count: %d", cache->size);
153162

154163
nfds = 1;
155164
fds = malloc(sizeof(struct pollfd));

src/utils/config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ static struct Configuration default_conf = {
1010
.allowed_log_levels = LOG_INFO | LOG_ERR | LOG_WARN,
1111
.max_log_len = 8192,
1212
.data_file = ".tellydb",
13-
.log_file = ".tellylog"
13+
.log_file = ".tellylog",
14+
.default_conf = true
1415
};
1516

1617
static void pass_line(FILE *file, char c) {

0 commit comments

Comments
 (0)