| 48 |
#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) |
| 49 |
#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) |
| 50 |
|
|
| 51 |
#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 |
| 52 |
|
|
| 53 |
#define SID_STR_LEN 5 // 32-bit + NULL |
#define SID_STR_LEN 5 // 32-bit + NULL |
| 54 |
|
|
| 108 |
return -1; |
return -1; |
| 109 |
} |
} |
| 110 |
|
|
| 111 |
if (block_count > ARTICLE_BLOCK_PER_POOL) |
if (block_count <= 0 || block_count > ARTICLE_BLOCK_PER_POOL) |
| 112 |
{ |
{ |
| 113 |
log_error("article_block_count exceed limit %d\n", ARTICLE_BLOCK_PER_POOL); |
log_error("article_block_count exceed limit %d\n", ARTICLE_BLOCK_PER_POOL); |
| 114 |
return -2; |
return -2; |
| 399 |
} |
} |
| 400 |
} |
} |
| 401 |
|
|
| 402 |
return (p_block->articles + left); |
if (aid != p_block->articles[left].aid) // not found |
| 403 |
|
{ |
| 404 |
|
return NULL; |
| 405 |
|
} |
| 406 |
|
|
| 407 |
|
return (p_block->articles + left); // found |
| 408 |
} |
} |
| 409 |
|
|
| 410 |
ARTICLE *article_block_find_by_index(int index) |
ARTICLE *article_block_find_by_index(int index) |
| 610 |
p_sid_str[i] = '\0'; |
p_sid_str[i] = '\0'; |
| 611 |
} |
} |
| 612 |
|
|
| 613 |
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) |
| 614 |
{ |
{ |
| 615 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 616 |
char sid_str[SID_STR_LEN]; |
char sid_str[SID_STR_LEN]; |
| 633 |
|
|
| 634 |
p_section->sid = sid; |
p_section->sid = sid; |
| 635 |
|
|
| 636 |
strncpy(p_section->sname, sname, sizeof(p_section->sname - 1)); |
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
| 637 |
p_section->sname[sizeof(p_section->sname - 1)] = '\0'; |
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 638 |
|
|
| 639 |
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle - 1)); |
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1); |
| 640 |
p_section->stitle[sizeof(p_section->stitle - 1)] = '\0'; |
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 641 |
|
|
| 642 |
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); |
| 643 |
p_section->master_name[sizeof(p_section->master_name - 1)] = '\0'; |
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
| 644 |
|
|
| 645 |
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) |
| 646 |
{ |
{ |
| 1143 |
return last_aid; |
return last_aid; |
| 1144 |
} |
} |
| 1145 |
|
|
| 1146 |
|
int article_block_article_count(void) |
| 1147 |
|
{ |
| 1148 |
|
int ret; |
| 1149 |
|
|
| 1150 |
|
if (p_article_block_pool == NULL || p_article_block_pool->block_count <= 0) |
| 1151 |
|
{ |
| 1152 |
|
return -1; |
| 1153 |
|
} |
| 1154 |
|
|
| 1155 |
|
ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK + |
| 1156 |
|
p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count; |
| 1157 |
|
|
| 1158 |
|
return ret; |
| 1159 |
|
} |
| 1160 |
|
|
| 1161 |
int article_count_of_topic(int32_t aid) |
int article_count_of_topic(int32_t aid) |
| 1162 |
{ |
{ |
| 1163 |
ARTICLE *p_article; |
ARTICLE *p_article; |
| 1198 |
int32_t first_inserted_aid_dest; |
int32_t first_inserted_aid_dest; |
| 1199 |
int move_counter; |
int move_counter; |
| 1200 |
|
|
| 1201 |
if (p_section_dest == NULL) |
if (p_section_src == NULL || p_section_dest == NULL) |
| 1202 |
{ |
{ |
| 1203 |
log_error("section_list_move_topic() NULL pointer error\n"); |
log_error("section_list_move_topic() NULL pointer error\n"); |
| 1204 |
return -1; |
return -1; |
| 1205 |
} |
} |
| 1206 |
|
|
| 1207 |
|
if (p_section_src->sid == p_section_dest->sid) |
| 1208 |
|
{ |
| 1209 |
|
log_error("section_list_move_topic() src and dest section are the same\n"); |
| 1210 |
|
return -1; |
| 1211 |
|
} |
| 1212 |
|
|
| 1213 |
if ((p_article = article_block_find_by_aid(aid)) == NULL) |
if ((p_article = article_block_find_by_aid(aid)) == NULL) |
| 1214 |
{ |
{ |
| 1215 |
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); |
| 1216 |
return -2; |
return -2; |
| 1217 |
} |
} |
| 1218 |
|
|
| 1253 |
{ |
{ |
| 1254 |
if (p_section_src->sid != p_article->sid) |
if (p_section_src->sid != p_article->sid) |
| 1255 |
{ |
{ |
| 1256 |
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", |
| 1257 |
p_section_src->sid, p_article->aid, p_article->sid); |
p_section_src->sid, p_article->aid, p_article->sid); |
| 1258 |
return -2; |
p_article = p_article->p_topic_next; |
| 1259 |
|
continue; |
| 1260 |
} |
} |
| 1261 |
|
|
| 1262 |
// Remove from bi-directional article list of src section |
// Remove from bi-directional article list of src section |
| 1282 |
|
|
| 1283 |
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) |
| 1284 |
{ |
{ |
| 1285 |
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); |
| 1286 |
return -4; |
p_article = p_article->p_topic_next; |
| 1287 |
|
continue; |
| 1288 |
} |
} |
| 1289 |
|
|
| 1290 |
// Insert into bi-directional article list of dest section |
// Insert into bi-directional article list of dest section |
| 1362 |
|
|
| 1363 |
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) |
| 1364 |
{ |
{ |
| 1365 |
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", |
| 1366 |
p_section_dest->article_count - dest_article_count_old, move_article_count); |
p_section_dest->article_count - dest_article_count_old, move_article_count); |
| 1367 |
} |
} |
| 1368 |
|
|