Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2008, 06:53 PM
sturdevk sturdevk is offline
 
Join Date: Jan 2008
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vBulletin code question

I have a technical question:

how the vBulletin app prevents the overwriting records in the datastore table?

for example, two admins are both adding new forums at the same time, as I know, it involves to read forumcache string from datastore table;unserialize it to php object; update this php object; serialize this object back to forumcache string and update datastore table with new forumcache string.

During this process, what if one process read out the forumcache string from DB, another process also read out this string from DB before the first process update this string in DB, in this case, second process will overwrite the first process's update on forumcache string, is it?

if vBulletin code will prevent this case from happening, could anybody point out which part of code doing this prevention?

Thanks,
a PHP newib who starting php programming 1.5 month ago
Reply With Quote
  #2  
Old 12-03-2008, 02:19 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It is incredibly hard to find this happening - and thus, vBulletin does not have any timestamp checks or the like on that cache.
Reply With Quote
  #3  
Old 12-03-2008, 12:33 PM
sturdevk sturdevk is offline
 
Join Date: Jan 2008
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, Dismounted, I have another related question, when a user is trying to delete his post, I noticed that forumcache string and usergroupcache string both get saved to datastore table.
95 Query REPLACE INTO datastore
(title, data, unserialize)
VALUES
('usergroupcache', 'a:10:.................)

95 Query REPLACE INTO datastore
(title, data, unserialize)
VALUES
('forumcache', 'a:17:{.................)

then how can we deal with two users deleting their posts at the same time. it maybe a concurrent issue, is it?

Thanks,
Reply With Quote
  #4  
Old 12-03-2008, 05:15 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sturdevk View Post
Thanks, Dismounted, I have another related question, when a user is trying to delete his post, I noticed that forumcache string and usergroupcache string both get saved to datastore table.
95 Query REPLACE INTO datastore
(title, data, unserialize)
VALUES
('usergroupcache', 'a:10:.................)

95 Query REPLACE INTO datastore
(title, data, unserialize)
VALUES
('forumcache', 'a:17:{.................)

then how can we deal with two users deleting their posts at the same time. it maybe a concurrent issue, is it?

Thanks,
The tables are locked when begin written to. All other threads asking to write data to the table would have to wait on the thread currently updating the table. Basically a thread locks the table, writes to the table, then un-locks the table. Only one thread may update a table at a time (it has exclusive access).

In short that should never happen unless there was some odd bugs in MySQL.

Edit: Also just to add a tid-bit; no two requests will ever come in at exactly the same time. Without going into details I'll just say that networks (including the internet of course) just work that way. Sure two requests may come in within microseconds of each other but one will always be processed before the other.
Reply With Quote
  #5  
Old 12-04-2008, 02:37 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Brad View Post
The tables are locked when begin written to. All other threads asking to write data to the table would have to wait on the thread currently updating the table. Basically a thread locks the table, writes to the table, then un-locks the table. Only one thread may update a table at a time (it has exclusive access).

In short that should never happen unless there was some odd bugs in MySQL.

Edit: Also just to add a tid-bit; no two requests will ever come in at exactly the same time. Without going into details I'll just say that networks (including the internet of course) just work that way. Sure two requests may come in within microseconds of each other but one will always be processed before the other.
Like a queue. You might have two customer come at (nearly) the same time, but one will go through before the other.
Reply With Quote
  #6  
Old 12-04-2008, 02:10 PM
sturdevk sturdevk is offline
 
Join Date: Jan 2008
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, Brad and Dismounted for clear explaination.
I only have Java/J2EE programming background and just started php programming 2 month ago. I do have some doubts regarding how requests coming in. In Java world, each request will be served as a thread, and there will be concurrent issue java developer should deal with in the design. maybe PHP world is different. i,e, server can't serve two requests at the same time?

back to my question, here is another example:
code:
line 1: read forumcache string from datastore.
....................(change this string)
line 1000: write forumcache string back to datastore.

one process/thread that is serving request 1 is executing the code on line 200, then another processes/thread that is serving request 2 start executing code line 1, you can see in this case, the forumcache change on processes 2 will overwrite changes wrote by process 1.

so if I understand your reply correctly, this will never happen, because server can only serve one request at a time?

or the table is locked from line 1 until line 1000?

bear with me if I'm asking dumb question...
Reply With Quote
  #7  
Old 12-05-2008, 03:59 AM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This might be helpful to you; http://static.zend.com/topics/0200-T...ons-in-PHP.pdf

The table is locked during writes, not reads. So in your example the table would only be locked at line 1000 and would be unlocked as soon as that SQL query was processed.

The main thing to keep in mind about PHP and programming for the web in general is the fact that web servers are stateless. This is why the way data is read/written/used may seem odd to you at first. The methods are different because everything is generated at runtime and destroyed at the end of script execution.

A web server can handle more than one request at a time. What I was trying to get at is requests are put into a queue and processed in order based on time. Processes can also claim exclusive access to a resource (like session data or MySQL tables in the case of writes) and all other requests will be forced to wait before working with that resource in some cases (example; I can read data from a table you're writing to but I can't write to that table until you finish.) Also remember that we are talking about microseconds-milliseconds here.

Also you should keep in mind that what you're getting at is not a very big deal because all the client has to do is load another page on our forum to get the most recent copy of the cache (or any other data stored in the database).

Did that answer your question? I kinda feel like I'm dancing around it or not begin clear. I'm personally moving in the opposite direction you are..I started my programming voyage on the web and now I'm moving into C, C++ and a few assembly languages. I know as well as you do how confusing it can be learning a new programming language even if you have experience in another. You should pick up on PHP quickly though if you stick with it. Just try to roll with things and not get so hung up on the many ways PHP is not like Java.

Oh one more quick thing. If you're new to PHP and are learning it with vBulletin a word of advice; Don't assume vBulletin is how PHP applications should be coded. vBulletin has a few growing pains and the source really shows it. If you're interested in learning PHP in general and using it outside of vBulletin I recommend going over to Sitepoint (and there are many other good sites) and reading about PHP5 and the OOP features. Here is a link to Sitepoint's PHP tutorial section; http://www.sitepoint.com/subcat/php-tutorials

There are also many good books on PHP if you're like me and link things in print.

If you need any more help just let me know.

- Brad
Reply With Quote
  #8  
Old 12-05-2008, 07:39 PM
sturdevk sturdevk is offline
 
Join Date: Jan 2008
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey, Brad,
Thank you very much for long, detailed explanation and advice, it did help me a lot. I did think vBulletin is the model of PHP programming, so I pretty much dug deep and tried to customize it.
will check those sites for PHP reference.
Reply With Quote
  #9  
Old 12-05-2008, 07:51 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sturdevk View Post
Hey, Brad,
Thank you very much for long, detailed explanation and advice, it did help me a lot. I did think vBulletin is the model of PHP programming, so I pretty much dug deep and tried to customize it.
will check those sites for PHP reference.
No problem.

BTW I hope you didn't take my comment about vBulletin to mean it has "bad code" in the source. vBulletin just suffers from the same problem a lot of php applications have; It was originally put together when php was just becoming popular and because Jelsoft has a large customer base certain things in the source code have always been done a certain way to avoid breaking backwards compatibility and existing sites that use the software.

Version 4 will come out at some point and it's supposed to be a total re-write of the source. It will also be the first version of the source code that does not have support for php version 4. Meaning the new version of vBulletin will be able to take full advantage of the new OOP features in php 5 (php 4 had OOP features but it was far from true OOP).
Reply With Quote
  #10  
Old 12-06-2008, 02:20 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The developers have said the vBulletin 4 will follow the MVC (Model-View-Controller) pattern - so you might want to have a look at that.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:09 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04975 seconds
  • Memory Usage 2,259KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete