Skip to content

KX style second SQL-encapsulated increment column for board id #22

Closed
ctrlcctrlv opened this Issue May 12, 2015 · 3 comments

2 participants

@ctrlcctrlv

Much to @jaw-sh's disapopintment, it is a definite requirement to have a board_id that autoincrements along with a global ID that auto increments.

Kusaba X, one of the original chan engine and the one that Tinyboard rewrote provides us with this schema:

CREATE TABLE `PREFIX_posts` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `boardid` smallint(5) unsigned NOT NULL,
  -- snip
  PRIMARY KEY  (`boardid`,`id`),
  -- snip
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Psql supports it as well. SQLite does with a CREATE TRIGGER. Unfortuantely, in MySQL in only one engine InnoDB this is impossible.

Looping forever like (psuedocode):

while ($error && $error->isDuplicateIdError) try_again();

hits the database far too often and is assuredly bad practice. In very active threads this could potentially loop ten times with a busy DB. I've done tests before of this on live software for a project and it was a disaster, but it 'worked' and I got paid. Let's try to do better than just get paid and do a good job as well.

We cannot just use global IDs and we cannot just use IDs based on position in the thread (>>1, >>2 etc) due to familiarity reasons. We need to keep this hack from KX, without just devolving into a million post tables like Tinyboard/vichan/infinity stable. I will write a migration for it.

@jaw-sh
jaw-sh commented May 12, 2015

;;

@jaw-sh jaw-sh added the enhancement label May 12, 2015
@jaw-sh jaw-sh added this to the Prepare for Public milestone May 12, 2015
@ctrlcctrlv ctrlcctrlv was assigned by jaw-sh May 12, 2015
@jaw-sh jaw-sh changed the title from KX style schema to KX style second SQL-encapsulated increment column for board id May 14, 2015
@jaw-sh jaw-sh added a commit that referenced this issue May 29, 2015
@jaw-sh jaw-sh #22 Fixed reply_last problem. #49 Reduced capcode queries and fixed p…
…ermission caching.
1d091e8
@jaw-sh
jaw-sh commented May 31, 2015

Concurrency testing indicates that the database is now able to properly deal with many posts at one time using transactions.

@jaw-sh jaw-sh closed this May 31, 2015
@ctrlcctrlv

Yup, I wrote a quick flooder by disabling CAPTCHA and CSRF token and then bombing it with posts from one hundred threads. I got up to 30 posts/second and no rejections/errors. Nice one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.