2023-11-06 monetdb-事务-insert-delta缓存-分析

摘要:

monetdb在事务处理时, 会将数据写入delta缓存中, 然后在commit时将数据写入wal文件, 随后由控制器决定何时将wal中的数据真正的写入BAT列文件中.

本文从delta缓存入手, 分析monetdb在事务处理中的细节.

SQL:

DML:

sql 复制代码
create table t1 (a int);

事务DDL:

sql 复制代码
START TRANSACTION;
sql 复制代码
insert into t1 values (4);
sql 复制代码
COMMIT;

trace日志:

mserver启动后第一次执行insert:

cpp 复制代码
ALGO     monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.transaction_begin
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.exportOperation

ALGO     monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.mvc
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.claim
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.append
IO_      gdk/gdk_bbp.c:3156                             getBBPdescriptor     load tmp_550
IO_      gdk/gdk_storage.c:637                          DESCload             DESCload: 05/550
IO_      gdk/gdk_storage.c:536                          GDKload              GDKload: name=05/550.tail, ext=, mode 1
IO_      gdk/gdk_storage.c:558                          GDKload              read(dst 0x7f01e8040cc0, n_expected 12, fd 9) = 12
ALGO     gdk/gdk_bat.c:1039                             BUNappendmulti       tmp_550#3@0[int]P appending 1 values
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.depend
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.affectedRows

ALGO     monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.transaction_commit
IO_      gdk/gdk_bbp.c:3156                             getBBPdescriptor     load tmp_551
IO_      gdk/gdk_storage.c:637                          DESCload             DESCload: 05/551
IO_      gdk/gdk_storage.c:536                          GDKload              GDKload: name=05/551.tail, ext=, mode 1
IO_      gdk/gdk_storage.c:558                          GDKload              read(dst 0x7f01e8037d30, n_expected 4, fd 9) = 4
ALGO     monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.exportOperation

mserver启动后第二次连续执行两次insert:

cpp 复制代码
monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.transaction_begin
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.exportOperation


monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.mvc
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.claim
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.append
gdk/gdk_bat.c:1039                             BUNappendmulti       tmp_550#4@0[int]P appending 1 values
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.depend
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.affectedRows

monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.mvc
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.claim
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.append
gdk/gdk_bat.c:1039                             BUNappendmulti       tmp_550#5@0[int]P appending 1 values
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.depend
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.affectedRows


monetdb5/mal/mal_interpreter.c:716             runMALsequence       calling querylog.define
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.transaction_commit
monetdb5/mal/mal_interpreter.c:687             runMALsequence       calling sql.exportOperation

核心处理:

BUNappendmulti

cpp 复制代码
#0  BUNappendmulti (b=0x1a366680, values=0x7f01e803c600, count=1, force=true) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/gdk/gdk_bat.c:1028
#1  0x00007f0283fb03d6 in delta_append_val (tr=0x7f01e8004540, batp=0x7f027e1f51e8, id=7590, offset=6, i=0x7f01e803c600, cnt=1, storage_type=0x0, tt=6)
    at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/storage/bat/bat_storage.c:2319
#2  0x00007f0283fb0688 in append_col_execute (tr=0x7f01e8004540, delta=0x7f027e1f51e8, id=7590, offset=6, offsets=0x0, incoming_data=0x7f01e803c600, cnt=1, tt=6, storage_type=0x0)
    at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/storage/bat/bat_storage.c:2354
#3  0x00007f0283fb0969 in append_col (tr=0x7f01e8004540, c=0x1a571380, offset=6, offsets=0x0, data=0x7f01e803c600, cnt=1, tpe=6)
    at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/storage/bat/bat_storage.c:2384
#4  0x00007f0283e38a3c in mvc_append_wrap (cntxt=0x237c610, mb=0x7f01e8035660, stk=0x7f01e803c4d0, pci=0x7f01e8045000)
    at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/backends/monet5/sql.c:1842
#5  0x00007f0297637047 in runMALsequence (cntxt=0x237c610, mb=0x7f01e8035660, startpc=1, stoppc=0, stk=0x7f01e803c4d0, env=0x0, pcicaller=0x0)
    at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_interpreter.c:688
#6  0x00007f02976357be in runMAL (cntxt=0x237c610, mb=0x7f01e8035660, mbcaller=0x0, env=0x0) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_interpreter.c:357
#7  0x00007f0283e5963b in SQLrun (c=0x237c610, m=0x7f01e80168d0) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/backends/monet5/sql_execute.c:259
#8  0x00007f0283e5af37 in SQLengineIntern (c=0x237c610, be=0x7f01e8036150) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/backends/monet5/sql_execute.c:709
#9  0x00007f0283e58505 in SQLengine (c=0x237c610) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/sql/backends/monet5/sql_scenario.c:1358
#10 0x00007f02976568c0 in runPhase (c=0x237c610, phase=4) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_scenario.c:453
#11 0x00007f0297656a2a in runScenarioBody (c=0x237c610, once=0) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_scenario.c:479
#12 0x00007f0297656c36 in runScenario (c=0x237c610, once=0) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_scenario.c:510
#13 0x00007f0297659048 in MSserveClient (c=0x237c610) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_session.c:589
#14 0x00007f02976588c1 in MSscheduleClient (command=0x7f01e8000b70 '\333' <repeats 199 times>, <incomplete sequence \333>..., challenge=0x7f027e1f5ce3 "HJBNRi7c", fin=0x7f01e8002b90, 
    fout=0x7f01f0003e20, protocol=PROTOCOL_9, blocksize=8190) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/mal/mal_session.c:445
#15 0x00007f029771e232 in doChallenge (data=0x7f01f0000b70) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/monetdb5/modules/mal/mal_mapi.c:222
#16 0x00007f0296fcf749 in THRstarter (a=0x7f01f0006310) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/gdk/gdk_utils.c:1668
#17 0x00007f029704cb43 in thread_starter (arg=0x7f01f0006380) at /root/work/monetdb-dev/trunk/monetdb-sep2022_sp3_release/gdk/gdk_system.c:862
#18 0x00007f029658d1ca in start_thread () from /lib64/libpthread.so.0
#19 0x00007f02961f9e73 in clone () from /lib64/libc.so.6
相关推荐
初晴~9 分钟前
【Redis分布式锁】高并发场景下秒杀业务的实现思路(集群模式)
java·数据库·redis·分布式·后端·spring·
盖世英雄酱5813614 分钟前
InnoDB 的页分裂和页合并
数据库·后端
YashanDB2 小时前
【YashanDB知识库】XMLAGG方法的兼容
数据库·yashandb·崖山数据库
独行soc2 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍11基于XML的SQL注入(XML-Based SQL Injection)
数据库·安全·web安全·漏洞挖掘·sql注入·hw·xml注入
风间琉璃""3 小时前
bugkctf 渗透测试1超详细版
数据库·web安全·网络安全·渗透测试·内网·安全工具
drebander3 小时前
SQL 实战-巧用 CASE WHEN 实现条件分组与统计
大数据·数据库·sql
IvorySQL3 小时前
IvorySQL 4.0 发布:全面支持 PostgreSQL 17
数据库·postgresql·开源数据库·国产数据库·ivorysql
18号房客3 小时前
高级sql技巧进阶教程
大数据·数据库·数据仓库·sql·mysql·时序数据库·数据库架构
Dawnㅤ3 小时前
使用sql实现将一张表的某些字段数据存到另一种表里
数据库·sql
张声录13 小时前
【ETCD】【实操篇(十二)】分布式系统中的“王者之争”:基于ETCD的Leader选举实战
数据库·etcd