| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _GNU_SOURCE |
|
|
|
|
| 17 |
#include "section_list.h" |
#include "section_list.h" |
| 18 |
#include "log.h" |
#include "log.h" |
| 19 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 46 |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
| 47 |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
| 48 |
|
|
| 49 |
#define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of move topic |
#define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of moving topic between sections |
| 50 |
|
|
| 51 |
#define SID_STR_LEN 5 // 32-bit + NULL |
#define SID_STR_LEN 5 // 32-bit + NULL |
| 52 |
|
|
| 397 |
} |
} |
| 398 |
} |
} |
| 399 |
|
|
| 400 |
return (p_block->articles + left); |
if (aid != p_block->articles[left].aid) // not found |
| 401 |
|
{ |
| 402 |
|
return NULL; |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
return (p_block->articles + left); // found |
| 406 |
} |
} |
| 407 |
|
|
| 408 |
ARTICLE *article_block_find_by_index(int index) |
ARTICLE *article_block_find_by_index(int index) |
| 608 |
p_sid_str[i] = '\0'; |
p_sid_str[i] = '\0'; |
| 609 |
} |
} |
| 610 |
|
|
| 611 |
SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_name) |
SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_list) |
| 612 |
{ |
{ |
| 613 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 614 |
char sid_str[SID_STR_LEN]; |
char sid_str[SID_STR_LEN]; |
| 631 |
|
|
| 632 |
p_section->sid = sid; |
p_section->sid = sid; |
| 633 |
|
|
| 634 |
strncpy(p_section->sname, sname, sizeof(p_section->sname - 1)); |
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
| 635 |
p_section->sname[sizeof(p_section->sname - 1)] = '\0'; |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 636 |
|
|
| 637 |
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle - 1)); |
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1); |
| 638 |
p_section->stitle[sizeof(p_section->stitle - 1)] = '\0'; |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 639 |
|
|
| 640 |
strncpy(p_section->master_name, master_name, sizeof(p_section->master_name - 1)); |
strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1); |
| 641 |
p_section->master_name[sizeof(p_section->master_name - 1)] = '\0'; |
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
| 642 |
|
|
| 643 |
if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, p_section_list_pool->section_count) != 1) |
if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, p_section_list_pool->section_count) != 1) |
| 644 |
{ |
{ |
| 1196 |
int32_t first_inserted_aid_dest; |
int32_t first_inserted_aid_dest; |
| 1197 |
int move_counter; |
int move_counter; |
| 1198 |
|
|
| 1199 |
if (p_section_dest == NULL) |
if (p_section_src == NULL || p_section_dest == NULL) |
| 1200 |
{ |
{ |
| 1201 |
log_error("section_list_move_topic() NULL pointer error\n"); |
log_error("section_list_move_topic() NULL pointer error\n"); |
| 1202 |
return -1; |
return -1; |
| 1203 |
} |
} |
| 1204 |
|
|
| 1205 |
|
if (p_section_src->sid == p_section_dest->sid) |
| 1206 |
|
{ |
| 1207 |
|
log_error("section_list_move_topic() src and dest section are the same\n"); |
| 1208 |
|
return -1; |
| 1209 |
|
} |
| 1210 |
|
|
| 1211 |
if ((p_article = article_block_find_by_aid(aid)) == NULL) |
if ((p_article = article_block_find_by_aid(aid)) == NULL) |
| 1212 |
{ |
{ |
| 1213 |
log_error("section_list_move_topic() error: article %d not found in block\n", aid); |
log_error("article_block_find_by_aid(aid = %d) error: article not found\n", aid); |
| 1214 |
return -2; |
return -2; |
| 1215 |
} |
} |
| 1216 |
|
|
| 1251 |
{ |
{ |
| 1252 |
if (p_section_src->sid != p_article->sid) |
if (p_section_src->sid != p_article->sid) |
| 1253 |
{ |
{ |
| 1254 |
log_error("section_list_move_topic() error: src section sid %d != article %d sid %d\n", |
log_error("section_list_move_topic() warning: src section sid %d != article %d sid %d\n", |
| 1255 |
p_section_src->sid, p_article->aid, p_article->sid); |
p_section_src->sid, p_article->aid, p_article->sid); |
| 1256 |
return -2; |
p_article = p_article->p_topic_next; |
| 1257 |
|
continue; |
| 1258 |
} |
} |
| 1259 |
|
|
| 1260 |
// Remove from bi-directional article list of src section |
// Remove from bi-directional article list of src section |
| 1280 |
|
|
| 1281 |
if (section_list_find_article_with_offset(p_section_dest, p_article->aid, &page, &offset, &p_next) != NULL) |
if (section_list_find_article_with_offset(p_section_dest, p_article->aid, &page, &offset, &p_next) != NULL) |
| 1282 |
{ |
{ |
| 1283 |
log_error("section_list_move_topic() error: article %d already in section %d\n", p_article->aid, p_section_dest->sid); |
log_error("section_list_move_topic() warning: article %d already in section %d\n", p_article->aid, p_section_dest->sid); |
| 1284 |
return -4; |
p_article = p_article->p_topic_next; |
| 1285 |
|
continue; |
| 1286 |
} |
} |
| 1287 |
|
|
| 1288 |
// Insert into bi-directional article list of dest section |
// Insert into bi-directional article list of dest section |
| 1360 |
|
|
| 1361 |
if (p_section_dest->article_count - dest_article_count_old != move_article_count) |
if (p_section_dest->article_count - dest_article_count_old != move_article_count) |
| 1362 |
{ |
{ |
| 1363 |
log_error("section_list_move_topic() error: count of moved articles %d != %d\n", |
log_error("section_list_move_topic() warning: count of moved articles %d != %d\n", |
| 1364 |
p_section_dest->article_count - dest_article_count_old, move_article_count); |
p_section_dest->article_count - dest_article_count_old, move_article_count); |
| 1365 |
} |
} |
| 1366 |
|
|