Skip to content

Conversation

@n2em
Copy link
Contributor

@n2em n2em commented Nov 14, 2025

bug fix for #469

@n2em n2em force-pushed the bugfix/restore/token-too-long branch from 6008f71 to 9250cc1 Compare November 14, 2025 14:00
@deitch
Copy link
Collaborator

deitch commented Nov 16, 2025

I guess #469 was not totally fixed?

What is the root cause? Looking at the code here, it looks to me like you just recreated what scanner does? So why does this work?

@n2em
Copy link
Contributor Author

n2em commented Nov 16, 2025

The core issue lead to this bug is the const value of defaultMaxAllowedPacket, it just hard code to 4194304, if the line of SQL statements exceed this limitation, the bufio.Scanner will throw exception: token too long. In our case, the dump file size is about 7GB, and the max records in single table is about 50M, it just broken when restore with version 1.3.0, with this commit , the restore works fine.

@n2em
Copy link
Contributor Author

n2em commented Nov 17, 2025

We can simply reproduce the issue by restore the database by below SQL.

create database test_restore;
use test_restore;
create table test_large(
	id int not null primary key,
    content mediumtext null
);
insert into test_large values(1,  REPEAT('A', 4194304)); 

Once restore the backup, the restore got error.

 $ ./mysql-backup restore db_backup_2025-11-17T02:27:02Z.tgz
INFO[0000] beginning restore                             run=e911423c-32d8-4196-b305-a1917a4bb172
Error: error restoring: failed to restore database: failed to restore database: bufio.Scanner: token too long
FATA[0035] error restoring: failed to restore database: failed to restore database: bufio.Scanner: token too long

@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

So something about bufio.Scanner hits a limit? That reproduction is good, I am going to dig a little, see if I can figure out what it is about bufio.Scanner.

@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

Thanks for the reproduction use case; it is very helpful.

@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

Right. Scanner has a max size, which you can increase via s.Buffer(). Reader, on the other hand, does not appear to have such a limit, which is strange. Either way, I can see why what you did here makes sense.

@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

I think it needs a rebase.

@n2em n2em force-pushed the bugfix/restore/token-too-long branch from 9250cc1 to f60c182 Compare November 18, 2025 02:32
@n2em
Copy link
Contributor Author

n2em commented Nov 18, 2025

rebase has done.

deitch
deitch previously approved these changes Nov 18, 2025
@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

Let CI do its magic.

@deitch
Copy link
Collaborator

deitch commented Nov 18, 2025

linting error

@n2em
Copy link
Contributor Author

n2em commented Nov 18, 2025

I should remove the unused const field. I will commit a update.

n2em added 2 commits November 18, 2025 11:01
…large dump files

Signed-off-by: chenen <itfunx@hotmail.com>
Signed-off-by: chenen <itfunx@hotmail.com>
@n2em n2em force-pushed the bugfix/restore/token-too-long branch from 6a1eb12 to fd1bca4 Compare November 18, 2025 03:01
@deitch deitch merged commit 304fbed into databacker:master Nov 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants