Compare commits
2 Commits
d2afb98268
...
a2d4b970e7
| Author | SHA1 | Date |
|---|---|---|
|
|
a2d4b970e7 | |
|
|
9c387937ef |
14
Makefile
14
Makefile
|
|
@ -106,10 +106,14 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
|
|||
.PHONY: lint
|
||||
lint:
|
||||
clang-format -n --Werror $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
||||
make -C lsm lint
|
||||
make -C landerctl lint
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
||||
make -C lsm fmt
|
||||
make -C landerctl fmt
|
||||
|
||||
.PHONY: check
|
||||
check:
|
||||
|
|
@ -117,21 +121,21 @@ check:
|
|||
cppcheck \
|
||||
$(addprefix -I,$(INC_DIRS)) \
|
||||
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
||||
--project=compile_commands.json \
|
||||
--error-exitcode=1 \
|
||||
--enable=warning,style \
|
||||
-ithirdparty/* \
|
||||
-itrie/* \
|
||||
--inline-suppr \
|
||||
--check-level=exhaustive \
|
||||
--quiet \
|
||||
-j$(shell nproc)
|
||||
-j$(shell nproc) \
|
||||
$(SRCS)
|
||||
make -C lsm check
|
||||
make -C landerctl check
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
$(MAKE) -C lsm clean
|
||||
|
||||
$(MAKE) -C landerctl clean
|
||||
|
||||
.PHONY: bear
|
||||
bear: clean
|
||||
|
|
|
|||
|
|
@ -98,13 +98,13 @@ check:
|
|||
cppcheck \
|
||||
$(addprefix -I,$(INC_DIRS)) \
|
||||
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
||||
--project=compile_commands.json \
|
||||
--error-exitcode=1 \
|
||||
--enable=warning,style \
|
||||
--inline-suppr \
|
||||
--check-level=exhaustive \
|
||||
--quiet \
|
||||
-j$(shell nproc)
|
||||
-j$(shell nproc) \
|
||||
$(SRCS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
|
|
|||
14
lsm/Makefile
14
lsm/Makefile
|
|
@ -97,6 +97,20 @@ lint:
|
|||
fmt:
|
||||
clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) $(SRCS_EXAMPLE)
|
||||
|
||||
.PHONY: check
|
||||
check:
|
||||
mkdir -p $(BUILD_DIR)/cppcheck
|
||||
cppcheck \
|
||||
$(addprefix -I,$(INC_DIRS)) \
|
||||
--cppcheck-build-dir=$(BUILD_DIR)/cppcheck \
|
||||
--error-exitcode=1 \
|
||||
--enable=warning,style \
|
||||
--inline-suppr \
|
||||
--check-level=exhaustive \
|
||||
--quiet \
|
||||
-j$(shell nproc) \
|
||||
$(SRCS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) {
|
|||
idx_file = fopen(idx_file_path, "wb");
|
||||
|
||||
if (idx_file == NULL) {
|
||||
fclose(db_file);
|
||||
|
||||
return lsm_error_failed_io;
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +57,9 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) {
|
|||
uint64_t num = 0;
|
||||
|
||||
if (fwrite(&num, sizeof(uint64_t), 1, idx_file) == 0) {
|
||||
fclose(db_file);
|
||||
fclose(idx_file);
|
||||
|
||||
return lsm_error_failed_io;
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +70,8 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) {
|
|||
idx_file = fopen(idx_file_path, "r+b");
|
||||
|
||||
if (idx_file == NULL) {
|
||||
fclose(db_file);
|
||||
|
||||
return lsm_error_failed_io;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +80,10 @@ lsm_error lsm_store_load(lsm_store **ptr, lsm_str *data_path) {
|
|||
store->db.f = db_file;
|
||||
store->idx.f = idx_file;
|
||||
|
||||
LSM_RES(lsm_store_load_db(store));
|
||||
LSM_RES2(lsm_store_load_db(store), {
|
||||
fclose(db_file);
|
||||
fclose(idx_file);
|
||||
});
|
||||
|
||||
*ptr = store;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "lsm/store_internal.h"
|
||||
|
||||
static lsm_error lsm_fwrite(uint64_t *sum, FILE *f, uint64_t size,
|
||||
uint64_t count, void *val) {
|
||||
uint64_t count, const void *val) {
|
||||
size_t res = fwrite(val, size, count, f);
|
||||
|
||||
if (res < count) {
|
||||
|
|
@ -15,7 +15,7 @@ static lsm_error lsm_fwrite(uint64_t *sum, FILE *f, uint64_t size,
|
|||
return lsm_error_ok;
|
||||
}
|
||||
|
||||
static lsm_error lsm_write_str(uint64_t *sum, FILE *f, lsm_str *s) {
|
||||
static lsm_error lsm_write_str(uint64_t *sum, FILE *f, const lsm_str *s) {
|
||||
uint64_t len = lsm_str_len(s);
|
||||
|
||||
LSM_RES(lsm_fwrite(sum, f, sizeof(uint64_t), 1, &len));
|
||||
|
|
@ -129,7 +129,7 @@ lsm_error lsm_entry_disk_insert(lsm_entry_handle *handle) {
|
|||
// its entry to zero
|
||||
lsm_error lsm_entry_disk_remove(lsm_entry_handle *handle) {
|
||||
lsm_store *store = handle->store;
|
||||
lsm_entry *entry = handle->wrapper->entry;
|
||||
const lsm_entry *entry = handle->wrapper->entry;
|
||||
|
||||
pthread_mutex_lock(&store->idx.lock);
|
||||
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ void lsm_entry_data_path(char *path, const lsm_entry_handle *handle) {
|
|||
const lsm_str *key = handle->wrapper->entry->key;
|
||||
|
||||
uint8_t levels =
|
||||
key->len <= LSM_STORE_DATA_LEVELS ? key->len : LSM_STORE_DATA_LEVELS;
|
||||
key->len > LSM_STORE_DATA_LEVELS ? LSM_STORE_DATA_LEVELS : key->len;
|
||||
|
||||
memcpy(path, lsm_str_ptr(data_path), data_path->len);
|
||||
path[data_path->len] = '/';
|
||||
|
|
@ -255,6 +255,7 @@ void lsm_entry_data_path(char *path, const lsm_entry_handle *handle) {
|
|||
uint64_t index = data_path->len + 1;
|
||||
|
||||
// Create each directory in the file hierarchy
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
for (uint8_t i = 0; i < levels; i++) {
|
||||
path[index] = lsm_str_char(key, i);
|
||||
path[index + 1] = '/';
|
||||
|
|
@ -279,6 +280,7 @@ lsm_error lsm_entry_data_open_write(lsm_entry_handle *handle) {
|
|||
key->len <= LSM_STORE_DATA_LEVELS ? key->len : LSM_STORE_DATA_LEVELS;
|
||||
|
||||
// Create all required directories in the path
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
for (uint8_t i = 0; i < levels; i++) {
|
||||
path[data_path->len + 2 * (i + 1)] = '\0';
|
||||
|
||||
|
|
|
|||
|
|
@ -9,15 +9,12 @@
|
|||
const char *var = getenv(env_var); \
|
||||
if (var == NULL) { \
|
||||
critical(1, "Missing environment variable %s", env_var); \
|
||||
} \
|
||||
var = strdup(var);
|
||||
}
|
||||
|
||||
#define ENV_OPT(var, env_var, default) \
|
||||
const char *var = getenv(env_var); \
|
||||
if (var == NULL) { \
|
||||
var = strdup(default); \
|
||||
} else { \
|
||||
var = strdup(var); \
|
||||
var = default; \
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue