diff --git a/.topdeps b/.topdeps index 85babb7a9612ce6a76157454d9012711c16032db..27e38415e5ef8e7e73f9fc604ada1736f8bd8b36 100644 --- a/.topdeps +++ b/.topdeps @@ -1 +1 @@ -add-text_store +introduce-generation_position diff --git a/.topmsg b/.topmsg index 182bd8e7665ef92b4d51bc701b0a69644a3574ad..8d85930fd283ddad3669f78c51a84e8181390ad1 100644 --- a/.topmsg +++ b/.topmsg @@ -1,3 +1,3 @@ From: Per Cederqvist -Subject: patch introduce-generation_position.patch +Subject: patch refactor-cached_get_text.patch diff --git a/src/server/dbck-cache.c b/src/server/dbck-cache.c index 3de2d242af9cc94a6f1f1916a5c870c0f52eb528..3bbeefef16a9413b6f19999d297f58ea7736aa2f 100644 --- a/src/server/dbck-cache.c +++ b/src/server/dbck-cache.c @@ -56,6 +56,8 @@ #ifdef TIME_SYNC # include #endif +#include +#include #include "ldifftime.h" #include "exp.h" @@ -323,23 +325,29 @@ extern String cached_get_text( Text_no text ) { String the_string; + Text_stat *t_stat; - TEXT_RANGE("cached_get_text\n", text, EMPTY_STRING); TRACE2("cached_get_text %lu\n", text); - if ( text_arr[ text ] == NULL ) + if ( (t_stat = cached_get_text_stat (text)) == NULL ) return EMPTY_STRING; - else if (text_arr[text]->text_store.generation == 0) + else if (t_stat->text_store.generation == 0) { - the_string.string = tmp_alloc( text_arr[text]->no_of_chars ); - the_string.len = text_arr[text]->no_of_chars; - fseek(text_file, text_arr[ text ]->text_store.file_pos, SEEK_SET); + the_string.string = tmp_alloc( t_stat->no_of_chars ); + the_string.len = t_stat->no_of_chars; + if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0) + { + kom_log("Failed to seek to %ld in text mass file: %s.\n", + t_stat->text_store.file_pos, strerror(errno)); + return EMPTY_STRING; + } + if ( fread(the_string.string, sizeof(char), the_string.len, text_file) != (size_t)the_string.len ) { - kom_log("%s read enough characters of text %lu\n", - "WARNING: cached_get_text: couldn't", - (unsigned long)text); + kom_log("WARNING: cached_get_text: premature end on text %lu\n", + text); + return EMPTY_STRING; } return the_string; @@ -347,7 +355,7 @@ cached_get_text( Text_no text ) else { #warning Generation > 0 not yet handled - return EMPTY_STRING; + restart_kom("Only generation 0 is handled.\n"); } } diff --git a/src/server/simple-cache.c b/src/server/simple-cache.c index 7c51c205ab7b6bd2a0cdeaee5819bd3ff8dfe2e2..c8cbed34205550d8cc1a7f1d1f47ce0b472afad8 100644 --- a/src/server/simple-cache.c +++ b/src/server/simple-cache.c @@ -1048,13 +1048,13 @@ cached_get_text( Text_no text ) String the_string; Text_stat *t_stat; + LOGACC(lt_text_mass, text); TRACE2("cached_get_text %lu\n", text); if ( (t_stat = cached_get_text_stat (text)) == NULL ) return EMPTY_STRING; else if (t_stat->text_store.generation == 0) { - LOGACC(lt_text_mass, text); the_string.string = tmp_alloc( t_stat->no_of_chars ); the_string.len = t_stat->no_of_chars; if (fseek(text_file, t_stat->text_store.file_pos, SEEK_SET) != 0) @@ -1068,7 +1068,7 @@ cached_get_text( Text_no text ) != (size_t)the_string.len ) { kom_log("WARNING: cached_get_text: premature end on text %lu\n", - text); + text); return EMPTY_STRING; }