| 17 |
#include "log.h" |
#include "log.h" |
| 18 |
#include "section_list.h" |
#include "section_list.h" |
| 19 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 20 |
|
#include "user_list.h" |
| 21 |
#include <errno.h> |
#include <errno.h> |
| 22 |
#include <signal.h> |
#include <signal.h> |
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
left = 0; |
left = 0; |
| 346 |
right = p_article_block_pool->block_count; |
right = p_article_block_pool->block_count - 1; |
| 347 |
|
|
| 348 |
// aid in the range [ head aid of blocks[left], tail aid of blocks[right - 1] ] |
// aid in the range [ head aid of blocks[left], tail aid of blocks[right] ] |
| 349 |
while (left < right - 1) |
while (left < right) |
| 350 |
{ |
{ |
| 351 |
// get block offset no less than mid value of left and right block offsets |
// get block offset no less than mid value of left and right block offsets |
| 352 |
mid = (left + right) / 2 + (right - left) % 2; |
mid = (left + right) / 2 + (left + right) % 2; |
|
|
|
|
if (mid >= p_article_block_pool->block_count) |
|
|
{ |
|
|
log_error("block(mid = %d) is out of boundary\n", mid); |
|
|
return NULL; |
|
|
} |
|
| 353 |
|
|
| 354 |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
| 355 |
{ |
{ |
| 356 |
right = mid; |
right = mid - 1; |
| 357 |
} |
} |
| 358 |
else |
else // if (aid >= p_article_block_pool->p_block[mid]->articles[0].aid) |
| 359 |
{ |
{ |
| 360 |
left = mid; |
left = mid; |
| 361 |
} |
} |
| 644 |
return p_section; |
return p_section; |
| 645 |
} |
} |
| 646 |
|
|
| 647 |
|
int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list) |
| 648 |
|
{ |
| 649 |
|
int64_t index; |
| 650 |
|
|
| 651 |
|
if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL) |
| 652 |
|
{ |
| 653 |
|
log_error("NULL pointer error\n"); |
| 654 |
|
return -1; |
| 655 |
|
} |
| 656 |
|
|
| 657 |
|
index = get_section_index(p_section); |
| 658 |
|
|
| 659 |
|
strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1); |
| 660 |
|
p_section->sname[sizeof(p_section->sname) - 1] = '\0'; |
| 661 |
|
|
| 662 |
|
strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1); |
| 663 |
|
p_section->stitle[sizeof(p_section->stitle) - 1] = '\0'; |
| 664 |
|
|
| 665 |
|
strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1); |
| 666 |
|
p_section->master_list[sizeof(p_section->master_list) - 1] = '\0'; |
| 667 |
|
|
| 668 |
|
if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0) |
| 669 |
|
{ |
| 670 |
|
log_error("trie_dict_set(section, %s, %d) error\n", sname, index); |
| 671 |
|
return -2; |
| 672 |
|
} |
| 673 |
|
|
| 674 |
|
return 0; |
| 675 |
|
} |
| 676 |
|
|
| 677 |
void section_list_reset_articles(SECTION_LIST *p_section) |
void section_list_reset_articles(SECTION_LIST *p_section) |
| 678 |
{ |
{ |
| 679 |
p_section->article_count = 0; |
p_section->article_count = 0; |
| 920 |
{ |
{ |
| 921 |
p_section->visible_article_count--; |
p_section->visible_article_count--; |
| 922 |
|
|
| 923 |
|
if (user_article_cnt_inc(p_article->uid, -1) < 0) |
| 924 |
|
{ |
| 925 |
|
log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid); |
| 926 |
|
} |
| 927 |
|
|
| 928 |
if (p_article->tid == 0) |
if (p_article->tid == 0) |
| 929 |
{ |
{ |
| 930 |
p_section->visible_topic_count--; |
p_section->visible_topic_count--; |
| 943 |
p_reply->visible = 0; |
p_reply->visible = 0; |
| 944 |
p_section->visible_article_count--; |
p_section->visible_article_count--; |
| 945 |
affected_count++; |
affected_count++; |
| 946 |
|
|
| 947 |
|
if (user_article_cnt_inc(p_reply->uid, -1) < 0) |
| 948 |
|
{ |
| 949 |
|
log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid); |
| 950 |
|
} |
| 951 |
} |
} |
| 952 |
} |
} |
| 953 |
} |
} |
| 960 |
{ |
{ |
| 961 |
p_section->visible_topic_count++; |
p_section->visible_topic_count++; |
| 962 |
} |
} |
| 963 |
|
|
| 964 |
|
if (user_article_cnt_inc(p_article->uid, 1) < 0) |
| 965 |
|
{ |
| 966 |
|
log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid); |
| 967 |
|
} |
| 968 |
} |
} |
| 969 |
|
|
| 970 |
p_article->visible = visible; |
p_article->visible = visible; |
| 1114 |
} |
} |
| 1115 |
|
|
| 1116 |
left = 0; |
left = 0; |
| 1117 |
right = p_section->page_count; |
right = p_section->page_count - 1; |
| 1118 |
|
|
| 1119 |
// aid in the range [ head aid of pages[left], tail aid of pages[right - 1] ] |
// aid in the range [ head aid of pages[left], tail aid of pages[right] ] |
| 1120 |
while (left < right - 1) |
while (left < right) |
| 1121 |
{ |
{ |
| 1122 |
// get page id no less than mid value of left page id and right page id |
// get page id no less than mid value of left page id and right page id |
| 1123 |
mid = (left + right) / 2 + (right - left) % 2; |
mid = (left + right) / 2 + (left + right) % 2; |
|
|
|
|
if (mid >= p_section->page_count) |
|
|
{ |
|
|
log_error("page id (mid = %d) is out of boundary\n", mid); |
|
|
return NULL; |
|
|
} |
|
| 1124 |
|
|
| 1125 |
if (aid < p_section->p_page_first_article[mid]->aid) |
if (aid < p_section->p_page_first_article[mid]->aid) |
| 1126 |
{ |
{ |
| 1127 |
right = mid; |
right = mid - 1; |
| 1128 |
} |
} |
| 1129 |
else |
else // if (aid < p_section->p_page_first_article[mid]->aid) |
| 1130 |
{ |
{ |
| 1131 |
left = mid; |
left = mid; |
| 1132 |
} |
} |
| 1719 |
timer++; |
timer++; |
| 1720 |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1721 |
{ |
{ |
| 1722 |
log_error("section_list_try_rd_lock() tried %d times on section %d\n", sid, timer); |
log_error("section_list_try_rd_lock() tried %d times on section %d\n", timer, sid); |
| 1723 |
} |
} |
| 1724 |
} |
} |
| 1725 |
else // failed |
else // failed |
| 1750 |
timer++; |
timer++; |
| 1751 |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1752 |
{ |
{ |
| 1753 |
log_error("section_list_try_rw_lock() tried %d times on section %d\n", sid, timer); |
log_error("section_list_try_rw_lock() tried %d times on section %d\n", timer, sid); |
| 1754 |
} |
} |
| 1755 |
} |
} |
| 1756 |
else // failed |
else // failed |