Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

ctrlcctrlv opened this issue May 12, 2015 · 3 comments
Assignees
Milestone

Comments

@ctrlcctrlv
Copy link
Contributor

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
Copy link
Contributor

jaw-sh commented May 12, 2015

;;

@jaw-sh jaw-sh added this to the Prepare for Public milestone May 12, 2015
@jaw-sh jaw-sh changed the title KX style schema KX style second SQL-encapsulated increment column for board id May 14, 2015
jaw-sh pushed a commit that referenced this issue May 29, 2015
@jaw-sh
Copy link
Contributor

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 as completed May 31, 2015
@ctrlcctrlv
Copy link
Contributor Author

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
Projects
None yet
Development

No branches or pull requests

2 participants