Merge lp:~vkolesnikov/pbxt/pbxt-mmap-direct-read-deadlock into lp:pbxt

Proposed by Vladimir Kolesnikov
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-mmap-direct-read-deadlock
Merge into: lp:pbxt
Diff against target: None lines
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-mmap-direct-read-deadlock
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+4112@code.launchpad.net
To post a comment you must log in.
565. By Vladimir Kolesnikov

changed amotic operations code to use XADD

566. By Vladimir Kolesnikov

minor fixes to locking

567. By Vladimir Kolesnikov

removed wrong assertion

Revision history for this message
Paul McCullagh (paul-mccullagh) wrote :
Download full text (3.5 KiB)

Hi Vlad,

This implementation can be optimized a bit.

In particular, we should not always lock and copy the record header
again after every call to tab_visible().

This is only required in the case that we continue to load the record
after the switch (tab_vis) statement.

This saves time in all cases where the tab_visible() call does not
return a valid record.

On Mar 3, 2009, at 8:10 PM, Vladimir Kolesnikov wrote:

> Vladimir Kolesnikov has proposed merging lp:~vkolesnikov/pbxt/pbxt-
> mmap-direct-read-deadlock into lp:pbxt.
>
> Requested reviews:
> PBXT Core (pbxt-core)
> --
> https://code.launchpad.net/~vkolesnikov/pbxt/pbxt-mmap-direct-read-
> deadlock/+merge/4112
> Your team PBXT Core is subscribed to branch lp:pbxt.
> === modified file 'src/table_xt.cc'
> --- src/table_xt.cc 2009-02-27 09:22:44 +0000
> +++ src/table_xt.cc 2009-03-03 19:02:32 +0000
> @@ -4868,6 +4868,8 @@
> xtRecordID new_rec_id;
> xtBool ptr_locked;
> xtRecordID invalid_rec = 0;
> + XTTabRecHeadDRec rec_head;
> + int tab_vis;
>
> next_page:
> if (!ot->ot_on_page) {
> @@ -4900,6 +4902,9 @@
> XT_LOCK_MEMORY_PTR(buff_ptr, ot->ot_rec_file,
> xt_rec_id_to_rec_offset(tab, ot->ot_seq_rec_id), tab-
> >tab_rows.tci_page_size, &ot->ot_thread->st_statistics.st_rec, ot-
> >ot_thread);
> if (!buff_ptr)
> return FAILED;
> + memcpy(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec));
> + XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> + buff_ptr = (xtWord1 *)&rec_head;
> }
>
> /* This is the current record: */
> @@ -4911,20 +4916,29 @@
> ot->ot_seq_offset += rec_size;
>
> retry:
> - switch (tab_visible(ot, (XTTabRecHeadDPtr) buff_ptr, &new_rec_id)) {
> + tab_vis = tab_visible(ot, (XTTabRecHeadDPtr) buff_ptr, &new_rec_id);
> + if (ptr_locked) {
> + XT_LOCK_MEMORY_PTR(buff_ptr, ot->ot_rec_file,
> xt_rec_id_to_rec_offset(tab, ot->ot_seq_rec_id - 1),
> + tab->tab_rows.tci_page_size, &ot->ot_thread-
> >st_statistics.st_rec, ot->ot_thread);
> +
> + if (!buff_ptr)
> + return FAILED;
> +
> + if (memcmp(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec))) {
> + memcpy(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec));
> + XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> + goto retry;
> + }
> +
> + XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> + }
> +
> + switch (tab_vis) {
> case FALSE:
> - if (ptr_locked) {
> - XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> - ptr_locked = FALSE;
> - }
> goto next_record;
> case XT_ERR:
> goto failed;
> case XT_NEW:
> - if (ptr_locked) {
> - XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> - ptr_locked = FALSE;
> - }
> buff_ptr = ot->ot_row_rbuffer;
> if (!xt_tab_get_rec_data(ot, new_rec_id, rec_size, ot-
> >ot_row_rbuffer))
> return XT_ERR;
> @@ -4937,12 +4951,6 @@
> /* Don't re-read for the same record twice: */
> invalid_rec = ot->ot_curr_rec_id;
>
> - /* Unlock the memory map: */
> - if (ptr_locked) {
> - XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
> - ptr_locked = FALSE;
> - }
> -
> /* Undo move to next: */
> ot->ot_seq_rec_id--;
> ot->ot_seq_offset -= rec_size;
> @@ -49...

Read more...

568. By Vladimir Kolesnikov

removed unnecessary checking of record header change after tab_visible

569. By Vladimir Kolesnikov

fixed a bug in the new locking code - when searching for a row lock, lock ranges were not taken into account

570. By Vladimir Kolesnikov

fixed asm atomic operations code for windows

571. By Vladimir Kolesnikov

merge from upstream

572. By Vladimir Kolesnikov

changed linux version of atomic operations to use lock/add instead of xadd

573. By Paul McCullagh

Different logic in the item not found case

574. By Vladimir Kolesnikov

another fix to row-locking

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/table_xt.cc'
--- src/table_xt.cc 2009-02-27 09:22:44 +0000
+++ src/table_xt.cc 2009-03-03 19:02:32 +0000
@@ -4868,6 +4868,8 @@
4868 xtRecordID new_rec_id;4868 xtRecordID new_rec_id;
4869 xtBool ptr_locked;4869 xtBool ptr_locked;
4870 xtRecordID invalid_rec = 0;4870 xtRecordID invalid_rec = 0;
4871 XTTabRecHeadDRec rec_head;
4872 int tab_vis;
48714873
4872 next_page:4874 next_page:
4873 if (!ot->ot_on_page) {4875 if (!ot->ot_on_page) {
@@ -4900,6 +4902,9 @@
4900 XT_LOCK_MEMORY_PTR(buff_ptr, ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, ot->ot_seq_rec_id), tab->tab_rows.tci_page_size, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread);4902 XT_LOCK_MEMORY_PTR(buff_ptr, ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, ot->ot_seq_rec_id), tab->tab_rows.tci_page_size, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread);
4901 if (!buff_ptr)4903 if (!buff_ptr)
4902 return FAILED;4904 return FAILED;
4905 memcpy(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec));
4906 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4907 buff_ptr = (xtWord1 *)&rec_head;
4903 }4908 }
49044909
4905 /* This is the current record: */4910 /* This is the current record: */
@@ -4911,20 +4916,29 @@
4911 ot->ot_seq_offset += rec_size;4916 ot->ot_seq_offset += rec_size;
49124917
4913 retry:4918 retry:
4914 switch (tab_visible(ot, (XTTabRecHeadDPtr) buff_ptr, &new_rec_id)) {4919 tab_vis = tab_visible(ot, (XTTabRecHeadDPtr) buff_ptr, &new_rec_id);
4920 if (ptr_locked) {
4921 XT_LOCK_MEMORY_PTR(buff_ptr, ot->ot_rec_file, xt_rec_id_to_rec_offset(tab, ot->ot_seq_rec_id - 1),
4922 tab->tab_rows.tci_page_size, &ot->ot_thread->st_statistics.st_rec, ot->ot_thread);
4923
4924 if (!buff_ptr)
4925 return FAILED;
4926
4927 if (memcmp(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec))) {
4928 memcpy(&rec_head, buff_ptr, sizeof(XTTabRecHeadDRec));
4929 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4930 goto retry;
4931 }
4932
4933 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4934 }
4935
4936 switch (tab_vis) {
4915 case FALSE:4937 case FALSE:
4916 if (ptr_locked) {
4917 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4918 ptr_locked = FALSE;
4919 }
4920 goto next_record;4938 goto next_record;
4921 case XT_ERR:4939 case XT_ERR:
4922 goto failed;4940 goto failed;
4923 case XT_NEW:4941 case XT_NEW:
4924 if (ptr_locked) {
4925 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4926 ptr_locked = FALSE;
4927 }
4928 buff_ptr = ot->ot_row_rbuffer;4942 buff_ptr = ot->ot_row_rbuffer;
4929 if (!xt_tab_get_rec_data(ot, new_rec_id, rec_size, ot->ot_row_rbuffer))4943 if (!xt_tab_get_rec_data(ot, new_rec_id, rec_size, ot->ot_row_rbuffer))
4930 return XT_ERR;4944 return XT_ERR;
@@ -4937,12 +4951,6 @@
4937 /* Don't re-read for the same record twice: */4951 /* Don't re-read for the same record twice: */
4938 invalid_rec = ot->ot_curr_rec_id;4952 invalid_rec = ot->ot_curr_rec_id;
49394953
4940 /* Unlock the memory map: */
4941 if (ptr_locked) {
4942 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
4943 ptr_locked = FALSE;
4944 }
4945
4946 /* Undo move to next: */4954 /* Undo move to next: */
4947 ot->ot_seq_rec_id--;4955 ot->ot_seq_rec_id--;
4948 ot->ot_seq_offset -= rec_size;4956 ot->ot_seq_offset -= rec_size;
@@ -4992,15 +5000,11 @@
4992 break;5000 break;
4993 }5001 }
4994 }5002 }
4995 if (ptr_locked)
4996 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
49975003
4998 *eof = FALSE;5004 *eof = FALSE;
4999 return OK;5005 return OK;
50005006
5001 failed:5007 failed:
5002 if (ptr_locked)
5003 XT_UNLOCK_MEMORY_PTR(ot->ot_rec_file, ot->ot_thread);
5004 return FAILED;5008 return FAILED;
5005}5009}
50065010

Subscribers

People subscribed via source and target branches