mirror of
https://github.com/simon987/sist2.git
synced 2025-04-18 17:56:44 +00:00
Fix sidecar files, better error handling in store_write
This commit is contained in:
parent
17fda1e540
commit
0887046b41
@ -4,6 +4,7 @@
|
|||||||
store_t *store_create(const char *path, size_t chunk_size) {
|
store_t *store_create(const char *path, size_t chunk_size) {
|
||||||
store_t *store = malloc(sizeof(struct store_t));
|
store_t *store = malloc(sizeof(struct store_t));
|
||||||
mkdir(path, S_IWUSR | S_IRUSR | S_IXUSR);
|
mkdir(path, S_IWUSR | S_IRUSR | S_IXUSR);
|
||||||
|
strcpy(store->path, path);
|
||||||
|
|
||||||
#if (SIST_FAKE_STORE != 1)
|
#if (SIST_FAKE_STORE != 1)
|
||||||
store->chunk_size = chunk_size;
|
store->chunk_size = chunk_size;
|
||||||
@ -78,27 +79,57 @@ void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t bu
|
|||||||
int put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
int put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
||||||
ScanCtx.stat_tn_size += buf_len;
|
ScanCtx.stat_tn_size += buf_len;
|
||||||
|
|
||||||
|
int db_full = FALSE;
|
||||||
|
int should_abort_transaction = FALSE;
|
||||||
|
|
||||||
if (put_ret == MDB_MAP_FULL) {
|
if (put_ret == MDB_MAP_FULL) {
|
||||||
|
db_full = TRUE;
|
||||||
|
should_abort_transaction = TRUE;
|
||||||
|
} else {
|
||||||
|
int commit_ret = mdb_txn_commit(txn);
|
||||||
|
|
||||||
|
if (commit_ret == MDB_MAP_FULL) {
|
||||||
|
db_full = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db_full) {
|
||||||
|
LOG_INFOF("store.c", "Updating mdb mapsize to %lu bytes", store->size)
|
||||||
|
|
||||||
|
if (should_abort_transaction) {
|
||||||
mdb_txn_abort(txn);
|
mdb_txn_abort(txn);
|
||||||
|
}
|
||||||
|
|
||||||
pthread_rwlock_unlock(&store->lock);
|
pthread_rwlock_unlock(&store->lock);
|
||||||
|
|
||||||
// Cannot resize when there is a opened transaction.
|
// Cannot resize when there is a opened transaction.
|
||||||
// Resize take effect on the next commit.
|
// Resize take effect on the next commit.
|
||||||
pthread_rwlock_wrlock(&store->lock);
|
pthread_rwlock_wrlock(&store->lock);
|
||||||
store->size += store->chunk_size;
|
store->size += store->chunk_size;
|
||||||
mdb_env_set_mapsize(store->env, store->size);
|
int resize_ret = mdb_env_set_mapsize(store->env, store->size);
|
||||||
mdb_txn_begin(store->env, NULL, 0, &txn);
|
if (resize_ret != 0) {
|
||||||
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
|
||||||
|
|
||||||
LOG_INFOF("store.c", "Updated mdb mapsize to %lu bytes", store->size)
|
|
||||||
}
|
|
||||||
|
|
||||||
mdb_txn_commit(txn);
|
|
||||||
pthread_rwlock_unlock(&store->lock);
|
|
||||||
|
|
||||||
if (put_ret != 0) {
|
|
||||||
LOG_ERROR("store.c", mdb_strerror(put_ret))
|
LOG_ERROR("store.c", mdb_strerror(put_ret))
|
||||||
}
|
}
|
||||||
|
mdb_txn_begin(store->env, NULL, 0, &txn);
|
||||||
|
int put_ret_retry = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
||||||
|
|
||||||
|
if (put_ret_retry != 0) {
|
||||||
|
LOG_ERROR("store.c", mdb_strerror(put_ret))
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = mdb_txn_commit(txn);
|
||||||
|
if (ret != 0) {
|
||||||
|
LOG_FATALF("store.c", "FIXME: Could not commit to store %s: %s (%d), %d, %d %d",
|
||||||
|
store->path, mdb_strerror(ret), ret,
|
||||||
|
put_ret, put_ret_retry);
|
||||||
|
}
|
||||||
|
LOG_INFOF("store.c", "Updated mdb mapsize to %lu bytes", store->size)
|
||||||
|
} else if (put_ret != 0) {
|
||||||
|
LOG_ERROR("store.c", mdb_strerror(put_ret))
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_rwlock_unlock(&store->lock);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#define STORE_SIZE_TN 1024 * 1024 * 5
|
#define STORE_SIZE_TN (1024 * 1024 * 5)
|
||||||
#define STORE_SIZE_TAG 1024 * 16
|
#define STORE_SIZE_TAG (1024 * 1024)
|
||||||
#define STORE_SIZE_META STORE_SIZE_TAG
|
#define STORE_SIZE_META STORE_SIZE_TAG
|
||||||
|
|
||||||
typedef struct store_t {
|
typedef struct store_t {
|
||||||
char *path;
|
char path[PATH_MAX];
|
||||||
char *tmp_path;
|
char *tmp_path;
|
||||||
MDB_dbi dbi;
|
MDB_dbi dbi;
|
||||||
MDB_env *env;
|
MDB_env *env;
|
||||||
|
@ -39,7 +39,7 @@ parse_job_t *create_fs_parse_job(const char *filepath, const struct stat *info,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sub_strings[30];
|
int sub_strings[30];
|
||||||
#define EXCLUDED(str) (pcre_exec(ScanCtx.exclude, ScanCtx.exclude_extra, filepath, strlen(filepath), 0, 0, sub_strings, sizeof(sub_strings)) >= 0)
|
#define EXCLUDED(str) (pcre_exec(ScanCtx.exclude, ScanCtx.exclude_extra, str, strlen(str), 0, 0, sub_strings, sizeof(sub_strings)) >= 0)
|
||||||
|
|
||||||
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ void parse(void *arg) {
|
|||||||
IS_ARC(doc->mime) ||
|
IS_ARC(doc->mime) ||
|
||||||
(IS_ARC_FILTER(doc->mime) && should_parse_filtered_file(doc->filepath, doc->ext))
|
(IS_ARC_FILTER(doc->mime) && should_parse_filtered_file(doc->filepath, doc->ext))
|
||||||
)) {
|
)) {
|
||||||
parse_archive(&ScanCtx.arc_ctx, &job->vfile, doc);
|
parse_archive(&ScanCtx.arc_ctx, &job->vfile, doc, ScanCtx.exclude, ScanCtx.exclude_extra);
|
||||||
} else if ((ScanCtx.ooxml_ctx.content_size > 0 || ScanCtx.media_ctx.tn_size > 0) && IS_DOC(doc->mime)) {
|
} else if ((ScanCtx.ooxml_ctx.content_size > 0 || ScanCtx.media_ctx.tn_size > 0) && IS_DOC(doc->mime)) {
|
||||||
parse_ooxml(&ScanCtx.ooxml_ctx, &job->vfile, doc);
|
parse_ooxml(&ScanCtx.ooxml_ctx, &job->vfile, doc);
|
||||||
} else if (is_cbr(&ScanCtx.comic_ctx, doc->mime) || is_cbz(&ScanCtx.comic_ctx, doc->mime)) {
|
} else if (is_cbr(&ScanCtx.comic_ctx, doc->mime) || is_cbz(&ScanCtx.comic_ctx, doc->mime)) {
|
||||||
@ -189,6 +189,8 @@ void parse(void *arg) {
|
|||||||
} else if (doc->mime == MIME_SIST2_SIDECAR) {
|
} else if (doc->mime == MIME_SIST2_SIDECAR) {
|
||||||
parse_sidecar(&job->vfile, doc);
|
parse_sidecar(&job->vfile, doc);
|
||||||
CLOSE_FILE(job->vfile)
|
CLOSE_FILE(job->vfile)
|
||||||
|
free(doc->filepath);
|
||||||
|
free(doc);
|
||||||
return;
|
return;
|
||||||
} else if (is_msdoc(&ScanCtx.msdoc_ctx, doc->mime)) {
|
} else if (is_msdoc(&ScanCtx.msdoc_ctx, doc->mime)) {
|
||||||
parse_msdoc(&ScanCtx.msdoc_ctx, &job->vfile, doc);
|
parse_msdoc(&ScanCtx.msdoc_ctx, &job->vfile, doc);
|
||||||
|
@ -27,7 +27,10 @@ void parse_sidecar(vfile_t *vfile, document_t *doc) {
|
|||||||
MD5((unsigned char *) vfile->filepath + ScanCtx.index.desc.root_len, doc->ext - 1 - ScanCtx.index.desc.root_len,
|
MD5((unsigned char *) vfile->filepath + ScanCtx.index.desc.root_len, doc->ext - 1 - ScanCtx.index.desc.root_len,
|
||||||
path_md5);
|
path_md5);
|
||||||
|
|
||||||
store_write(ScanCtx.index.meta_store, (char *) path_md5, sizeof(path_md5), json_str, strlen(json_str) + 1);
|
char path_md5_str[MD5_STR_LENGTH];
|
||||||
|
buf2hex(path_md5, MD5_DIGEST_LENGTH, path_md5_str);
|
||||||
|
|
||||||
|
store_write(ScanCtx.index.meta_store, path_md5_str, MD5_STR_LENGTH, json_str, strlen(json_str) + 1);
|
||||||
|
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
free(json_str);
|
free(json_str);
|
||||||
|
2
third-party/libscan
vendored
2
third-party/libscan
vendored
@ -1 +1 @@
|
|||||||
Subproject commit da172823745b67662846cf1970a47ebcea8fe50e
|
Subproject commit 3787475ecba7453a2a97ab470103606c2cecabb2
|
Loading…
x
Reference in New Issue
Block a user