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

bug: truncate table failed #759

Closed
3 tasks done
hustjieke opened this issue Oct 19, 2022 · 2 comments
Closed
3 tasks done

bug: truncate table failed #759

hustjieke opened this issue Oct 19, 2022 · 2 comments
Assignees
Labels
A-bug Something isn't working C-stonedb-8.0 associated with stonedb 8.0

Comments

@hustjieke
Copy link
Collaborator

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

Execute truncate table t with no effect, the data didn't be truncated.

Expected behavior

No response

How To Reproduce

talbe schema :
create table t2(a int key, b int) engine = tianmu;
insert into t2 values ....

mysql> truncate table t2;
Query OK, 0 rows affected (39.39 sec)

mysql> select * from t2;
+---+------+
| a | b    |
+---+------+
| 1 |    1 |
| 2 |    3 |
| 3 |    4 |
| 5 |    5 |
| 6 |    6 |
| 8 |    8 |
| 7 |    7 |
| 9 |    9 |
+---+------+
8 rows in set (0.72 sec)

Environment

  1. ubuntu
  2. stonedb-8.0-dev

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!
@hustjieke hustjieke added A-bug Something isn't working C-stonedb-8.0 associated with stonedb 8.0 labels Oct 19, 2022
@hustjieke hustjieke added this to the stonedb_8.0_v1.0.0 milestone Oct 19, 2022
@hustjieke hustjieke self-assigned this Oct 19, 2022
@hustjieke hustjieke moved this to In Progress in StoneDB for MySQL 8.0 Oct 19, 2022
@hustjieke hustjieke changed the title bug: bug: truncate table failed Oct 20, 2022
@hustjieke
Copy link
Collaborator Author

hustjieke commented Oct 20, 2022

When mysql has done locked table in function external_lock(), it continuely doing unlock_external(), this make m_modified_tables been clear in advance on tianmu transaction.

  1. doing external_lock in handler_truncate_base in line 569:
  2. then do unlock_external in line 592
   563           /*                                                                                                                                                                               │
│   564             The engine does not support truncate-by-recreate.                                                                                                                              │
│   565             Attempt to use the handler truncate method.                                                                                                                                    │
│   566             MYSQL_AUDIT_TABLE_ACCESS_READ audit event is generated when opening                                                                                                            │
│   567             tables using open_tables function.                                                                                                                                             │
│   568           */                                                                                                                                                                               │
│b+ 569           const Truncate_result tr = handler_truncate_base(thd, table_ref, table_def);                                                                                                     │
│   570           switch (tr) {                                                                                                                                                                    │
│   571               /*                                                                                                                                                                           │
│   572                 All effects of a TRUNCATE TABLE operation are committed even if                                                                                                            │
│   573                 truncation fails in the case of non transactional tables. Thus, the                                                                                                        │
│   574                 query must be written to the binary log for such tables.                                                                                                                   │
│   575                 The exceptions are failure to open table or unimplemented truncate                                                                                                         │
│   576                 method.                                                                                                                                                                    │
│   577               */                                                                                                                                                                           │
│   578             case Truncate_result::OK:                                                                                                                                                      │
│   579               m_error = false;                                                                                                                                                             │
│   580               [[fallthrough]];                                                                                                                                                             │
│   581             case Truncate_result::FAILED_BUT_BINLOG:                                                                                                                                       │
│   582               binlog_stmt = true;                                                                                                                                                          │
│   583               binlog_is_trans = table_ref->table->file->has_transactions();                                                                                                                │
│   584               [[fallthrough]];                                                                                                                                                             │
│   585             case Truncate_result::FAILED_SKIP_BINLOG:                                                                                                                                      │
│   586               /*                                                                                                                                                                           │
│   587                 Call to handler_truncate() might have updated table definition                                                                                                             │
│   588                 in the data-dictionary, let us remove TABLE_SHARE from the TDC.                                                                                                            │
│   589                 This needs to be done even in case of failure so InnoDB SE                                                                                                                 │
│   590                 properly invalidates its internal cache.                                                                                                                                   │
│   591               */                                                                                                                                                                           │
│   592               close_all_tables_for_name(thd, table_ref->table->s, false, nullptr);                                                                                                         │
│  >593               break;  

btrace in gdb when doingunlock_external :

#0  Tianmu::core::Transaction::RemoveTable (this=0x7efd300b22a0, share=std::shared_ptr<Tianmu::core::TableShare> (use count 2, weak count 0) = {...})
    at /github/stonedb/storage/tianmu/core/transaction.cpp:56
#1  0x0000557458f00501 in Tianmu::handler::ha_tianmu::external_lock (this=0x7efd3000c770, thd=0x7efd30001060, lock_type=2) at /github/stonedb/storage/tianmu/handler/ha_tianmu.cpp:274
#2  0x00005574570c3bc7 in handler::ha_external_lock (this=0x7efd3000c770, thd=0x7efd30001060, lock_type=2) at /github/stonedb/sql/handler.cc:7793
#3  0x000055745731281e in unlock_external (thd=0x7efd30001060, table=0x7efd3009f3d8, count=1) at /github/stonedb/sql/lock.cc:618
#4  0x0000557457311e5c in mysql_unlock_tables (thd=0x7efd30001060, sql_lock=0x7efd3009f3b0) at /github/stonedb/sql/lock.cc:414
#5  0x0000557457311f02 in mysql_unlock_some_tables (thd=0x7efd30001060, table=0x7f026c21df08, count=1) at /github/stonedb/sql/lock.cc:427
#6  0x0000557457312225 in mysql_lock_remove (thd=0x7efd30001060, locked=0x7efd300a07f0, table=0x7efd309911a0) at /github/stonedb/sql/lock.cc:503
#7  0x0000557456b9841e in close_all_tables_for_name (thd=0x7efd30001060, key=0x7f026c21dfe0 "test", key_length=8, db=0x7f026c21dfe0 "test", table_name=0x7f026c21dfe5 "t2",
    remove_from_locked_tables=false, skip_table=0x0) at /github/stonedb/sql/sql_base.cc:1463
#8  0x0000557456b98563 in close_all_tables_for_name (thd=0x7efd30001060, share=0x7efd300b4350, remove_from_locked_tables=false, skip_table=0x0) at /github/stonedb/sql/sql_base.cc:1489
#9  0x000055745744c571 in Sql_cmd_truncate_table::truncate_base (this=0x7efd300a6530, thd=0x7efd30001060, table_ref=0x7efd300a6568) at /github/stonedb/sql/sql_truncate.cc:592
#10 0x000055745744cf8f in Sql_cmd_truncate_table::execute (this=0x7efd300a6530, thd=0x7efd30001060) at /github/stonedb/sql/sql_truncate.cc:740
#11 0x0000557456cb4185 in mysql_execute_command (thd=0x7efd30001060, first_level=true) at /github/stonedb/sql/sql_parse.cc:4604
#12 0x0000557456cb6470 in dispatch_sql_command (thd=0x7efd30001060, parser_state=0x7f026c21fb90) at /github/stonedb/sql/sql_parse.cc:5239
#13 0x0000557456cabeef in dispatch_command (thd=0x7efd30001060, com_data=0x7f026c2204e0, command=COM_QUERY) at /github/stonedb/sql/sql_parse.cc:1959
#14 0x0000557456ca9f66 in do_command (thd=0x7efd30001060) at /github/stonedb/sql/sql_parse.cc:1362

hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Oct 25, 2022
[summary]
1. Fix close_all_tables_for_name() before the txn is commited.
2. In file sql_trunction.cc and function end_transaction(), will call CommitTx() twice, In CommitTx()
   skip for the first time, called in trans_commit_stmt(), thd->server_status = SERVER_STATUS_IN_TRANS and all = false
   then called in trans_commit_implicit(), thd->server_status will be set "~SERVER_STATUS_IN_TRANS", and all = true
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Oct 26, 2022
[summary]
1. Fix close_all_tables_for_name() before the txn is commited.
2. In file sql_trunction.cc and function end_transaction(), will call CommitTx() twice, In CommitTx()
   skip for the first time, called in trans_commit_stmt(), thd->server_status = SERVER_STATUS_IN_TRANS and all = false
   then called in trans_commit_implicit(), thd->server_status will be set "~SERVER_STATUS_IN_TRANS", and all = true
mergify bot pushed a commit that referenced this issue Oct 26, 2022
[summary]
1. Fix close_all_tables_for_name() before the txn is commited.
2. In file sql_trunction.cc and function end_transaction(), will call CommitTx() twice, In CommitTx()
   skip for the first time, called in trans_commit_stmt(), thd->server_status = SERVER_STATUS_IN_TRANS and all = false
   then called in trans_commit_implicit(), thd->server_status will be set "~SERVER_STATUS_IN_TRANS", and all = true
@hustjieke
Copy link
Collaborator Author

This problom only exists in 8.0, 5.7 is ok.

Repository owner moved this from In Progress to Done in StoneDB for MySQL 8.0 Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working C-stonedb-8.0 associated with stonedb 8.0
Projects
Development

No branches or pull requests

1 participant