From 560a74daf6f6a0a094d16412084982e4dc85cbf7 Mon Sep 17 00:00:00 2001 From: Per Cederqvist Date: Sun, 18 Apr 2010 21:58:28 +0200 Subject: [PATCH] patch refactor-cached_get_text.patch --- .topdeps | 2 +- .topmsg | 2 +- src/server/dbck-cache.c | 28 ++++++++++++++++++---------- src/server/simple-cache.c | 4 ++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.topdeps b/.topdeps index 85babb7a..27e38415 100644 --- a/.topdeps +++ b/.topdeps @@ -1 +1 @@ -add-text_store +introduce-generation_position diff --git a/.topmsg b/.topmsg index 182bd8e7..8d85930f 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 3de2d242..3bbeefef 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 7c51c205..c8cbed34 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; } -- GitLab