Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Nov 1999
Posts: 132
Member
Member
Offline
Joined: Nov 1999
Posts: 132
We're about to launch a forum based on UBBT, importing several hundred thousand posts into UBBT (from from wwwboard). We wrote the following SQL queries to make sure that the database was internally consistent after our import, but we were also wondering how often similar corruptions may creep into a large UBBT site in normal operation. The UBBT code doesn't include protections to ensure that all of the internal dependencies it relies upon are enforced, which means that you may occasionally have race conditions or other situations which would cause certain corruptions. These would generally be pretty benign, but may cause message loss or other such problems.

We're curious to see if anyone running a UBBT installation would care to run the following SQL queries to see if they have any such problems. None of the queries should select any rows if the database is consistent (we think; these things may not, in fact, be testing real invariants):

1. Find any posts with missing parents or threads:
SELECT t1.B_Number, t1.B_Parent, t3.B_Number as ParentNum, t1.B_Main,
t2.B_Number as MainNum, t1.B_Board FROM w3t_Posts AS t1
LEFT JOIN w3t_Posts AS t2 ON t1.B_Main = t2.B_Number
LEFT JOIN w3t_Posts AS t3 ON t1.B_Parent = t3.B_Number
WHERE t2.B_Number IS NULL OR (t1.B_Parent != 0 AND t3.B_Number IS NULL)

2. Find any posts belonging to nonexistant boards:
SELECT B_Board, B_Number FROM w3t_Posts LEFT JOIN w3t_Boards
ON w3t_Posts.B_Board = w3t_Boards.Bo_Keyword WHERE
w3t_Boards.Bo_Keyword IS NULL

3. Find any threads with an inaccurate reply count:
SELECT t1.B_Number, t1.B_Main, t1.B_Replies, COUNT(*) AS ThreadTotal
FROM w3t_Posts AS t1 JOIN w3t_Posts as t2 ON t1.B_Number = t2.B_Main
GROUP BY t2.B_Main HAVING ThreadTotal != (t1.B_Replies + 1)

4. Find any posts posted by nonexistent users:
SELECT B_Number, B_PosterId FROM w3t_Posts LEFT JOIN w3t_Users
ON B_PosterId = U_Number WHERE U_Number IS NULL

5. Find any boards with invalid info for last poster/main/post (this one is particularly sticky in 6.2.1, because you can break the invariant using the UBB Admin UI by deleting the last user to post in any board, and it'll then fail to display that board on the main index page):
SELECT Bo_Keyword, Bo_LastNumber, t2.B_Number AS LastPostNumber,
Bo_lastMain, t3.B_Number AS LastPostThread, Bo_Posterid,
U_Number As LastPoster FROM w3t_Boards AS t1 LEFT JOIN
w3t_Posts AS t2 ON t1.Bo_LastNumber = t2.B_Number LEFT JOIN
w3t_Posts AS t3 ON t1.Bo_lastMain = t3.B_Number LEFT JOIN
w3t_Users AS t4 ON t1.Bo_Posterid = t4.U_Number WHERE
t1.Bo_LastNumber != 0 AND t1.Bo_lastMain != 0 AND
t1.Bo_Posterid != 0 AND (t2.B_Number IS NULL OR
t3.B_Number IS NULL or t4.U_Number IS NULL)

6. Find any posts which have inconsistent thread parent information:
SELECT B_Number, B_Parent, B_Main FROM w3t_Posts WHERE (B_Parent = 0
AND B_Number != B_Main) OR (B_Parent != 0 AND B_Number = B_Main);

7. Find boards where the count of posts in that board is incorrect:
SELECT Bo_Keyword, Bo_Total, COUNT(*) AS ActualPosts FROM w3t_Boards
JOIN w3t_Posts ON B_Board = Bo_Keyword GROUP BY Bo_Keyword HAVING
Bo_Total != ActualPosts

8. Find boards where the count of threads in that board is incorrect:
SELECT Bo_Keyword, Bo_Threads, COUNT(*) AS ActualThreads FROM
w3t_Boards JOIN w3t_Posts ON B_Board = Bo_Keyword WHERE
B_Number = B_Main GROUP BY Bo_Keyword HAVING
ActualThreads != Bo_Threads

Any of these should be executable from the mysql command-line prompt; if you're worried that some of them might generate pages of output, you can try them at first with a LIMIT 10 restriction on the end. We're using version 6.2.1; I don't know when or whether any of these database fields have changed before or after that version.

Of course, there are a large number of other nominal invariants that could be tested.

We're curious as to how often such inconsistencies slip in. All can be repaired in one way or another, either by recalculating values, or deleting or reattaching posts, and we'd like to make a plan for whether we'll have to do that and if so, how often. #7 and 8 are particularly interesting for us right now, because they fail on our database, and we're trying to track down whether it's a problem with our code or normal UBB operation.

Sponsored Links
Entire Thread
Subject Posted By Posted
UBBT Database Corruption Sniffing Scheme Jim Osby 11/10/2003 8:57 AM
Re: UBBT Database Corruption Sniffing Scheme JoshPet 11/10/2003 9:39 AM
Re: UBBT Database Corruption Sniffing Scheme Astaran 11/10/2003 11:38 AM
Re: UBBT Database Corruption Sniffing Scheme Maze 11/10/2003 1:03 PM
Re: UBBT Database Corruption Sniffing Scheme AllenAyres 11/11/2003 12:03 AM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/11/2003 2:28 AM
Re: UBBT Database Corruption Sniffing Scheme Maze 11/11/2003 12:45 PM
Re: UBBT Database Corruption Sniffing Scheme Tim Dierks 11/12/2003 5:06 AM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/12/2003 6:05 PM
Re: UBBT Database Corruption Sniffing Scheme Jim Osby 11/13/2003 9:24 AM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/13/2003 9:47 PM
Re: UBBT Database Corruption Sniffing Scheme Rick 11/17/2003 7:59 PM
Re: UBBT Database Corruption Sniffing Scheme scroungr 11/17/2003 8:16 PM
Re: UBBT Database Corruption Sniffing Scheme slayer60 11/17/2003 8:38 PM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/18/2003 12:17 AM
Re: UBBT Database Corruption Sniffing Scheme scroungr 11/18/2003 1:16 AM
Re: UBBT Database Corruption Sniffing Scheme Rick 11/18/2003 2:04 AM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/18/2003 4:38 AM
Re: UBBT Database Corruption Sniffing Scheme scroungr 11/18/2003 6:44 AM
Re: UBBT Database Corruption Sniffing Scheme omegatron 11/18/2003 6:53 AM
Re: UBBT Database Corruption Sniffing Scheme scroungr 11/18/2003 3:44 PM
Re: UBBT Database Corruption Sniffing Scheme slayer60 11/18/2003 6:47 PM
Re: UBBT Database Corruption Sniffing Scheme slayer60 11/18/2003 11:20 PM
Re: UBBT Database Corruption Sniffing Scheme Rick 11/19/2003 6:32 AM
Re: UBBT Database Corruption Sniffing Scheme Tim Dierks 11/24/2003 10:28 PM
Re: UBBT Database Corruption Sniffing Scheme AllenAyres 11/25/2003 7:17 AM
Re: UBBT Database Corruption Sniffing Scheme Astaran 11/25/2003 4:01 PM

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Gizmo
Gizmo
Portland, OR, USA
Posts: 5,833
Joined: January 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240506)