Yu's Blog

do something!

CMU15-445/645


src/common.

channel.h

  • 实际上是一个线程安全队列.

rid.h

  • Record Identifier = page_id_ << 32 | slot_num_

rwlatch.h

  • 读写锁(std::shared_mutex)

src/type.

abstract_pool.h

  • 抽象内存池接口

type_id.h

  • type枚举
    1
    enum TypeId { INVALID = 0, BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, VARCHAR, TIMESTAMP };

type.h

  • 类型基类.
  • 定义了类型比较,运算,序列化,转换类型等虚接口.

boolean_type.h

  • 实例化boolean类型比较,运算,序列化,转换类型等接口.

numeraic_type.h

  • number value的基类,可以是整数和小数.必须提供运算操作.

integer_parent_type.h

  • 为整数提供具有鲁棒性的四则运算.

tinyint_type.h,smallint_type.h,bigint_type.hinteger_type.h

  • integer_parent_type的子类,为整数提供了比较,运算,序列化,转换类型等接口.

timestamp_type.h

  • 为timestamp类型提供比较等接口.

decimal_type.h

  • 为小数提供类型比较,运算,序列化,转换类型等接口.

value.h

  • 实际管理数据内容的地方.
  • 存储着type和数据内容.
  • value比较,运算,序列化,转换类型等操作都是调用type提供的虚接口.
    1
    Type::GetInstance(type_id_)->

value_factory.h

  • value工厂类,方便构造value.

src/catalog.

column.h

  • 记录column的name,type,fixed_length,variable_length,offset.

schema.h

  • 存储着std::vector columns. 记录数据库tuple的元信息.

catalog.h

  • 处理表创建、表查找、索引创建和索引查找.

src/storage.

table/tuple.h

  • 存储RID rid_{},std::vector data_.
  • 定义了tuple的存储格式,前面部分存储inline数据,然后存储uninline数据.
  • 可以通过schema和column_idx得到数据.

table/table_heap.h

  • BufferPoolManager *bpm_,page_id_t first_page_id_,page_id_t last_page_id_.
  • 通过BufferPoolManager操作table,提供了一系列操作table中tuple的接口.

table/table_iterator.h

  • table中page的迭代器.

disk/disk_manager.h

  • 封装了写文件操作.
  • file_name_,log_name_.
  • 通过page_id计算offset,然后往文件读写内容.

disk/disk_scheduler.h

  • 内部保存DiskManager.
  • Channel<std::optional> request_queue_,使用channel依次处理请求.

page/page.h

  • 数据库存储的基本单元.提供了对真实数据页的一层包装.
  • data_,page_id_,pin_count_,is_dirty_,rwlatch_.

page/page_guard.h

  • 为page提供RAII.

page/table_page.h

  • 一个page是怎么存储tuple的.

page/extendible_htable_header_page.h

  • page_id_t directory_page_ids_[512],uint32_t max_depth_;
  • 固定大小,可以认为是第一层hash,有一个常量max_depth_.

page/extendible_htable_directory_page.h

  • uint32_t max_depth_,uint32_t global_depth_,uint8_t local_depths_[512],page_id_t bucket_page_ids_[512];
  • 不固定大小,可以认为是第二层hash,有一个变量depth.

page/extendible_htable_bucket_page.h

  • uint32_t size_,uint32_t max_size_,MappingType array_[HTableBucketArraySize(sizeof(MappingType))];
  • 保存实际value的地方.

index/index.h

  • std::unique_ptr metadata_;
  • IndexMetadata
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    /** The name of the index */
    std::string name_;
    /** The name of the table on which the index is created */
    std::string table_name_;
    /** The mapping relation between key schema and tuple schema */
    const std::vector<uint32_t> key_attrs_;
    /** The schema of the indexed key */
    std::shared_ptr<Schema> key_schema_;
    /** Is primary key? */
    bool is_primary_key_;
  • 索引的抽象基类.

index/extendible_hash_table_index.h

  • class ExtendibleHashTableIndex : public Index;
  • 根据extendible_hash_table构建的索引表.

src/buffer.

lru_k_replacer.h

  • 实现了lru_k替换算法.

buffer_pool_manager.h

  • 缓存池.通过pool_size,disk_manager(file_name_),replacer_k初始化.

src/container.

disk/hash/disk_extendible_hash_table.h

  • std::string index_name_;BufferPoolManager *bpm_;KC cmp_;HashFunction hash_fn_;uint32_t header_max_depth_;uint32_t directory_max_depth_;uint32_t bucket_max_size_;page_id_t header_page_id_;
  • 结合BufferPoolManager,extendible_htable_header_page,extendible_htable_directory_page,extendible_htable_bucket_page,建立一个可动态扩展/收缩的HashTable,对外提供增、删、查的的服务接口.

execution

executors/abstract_executor.h

  • 执行器的抽象基类.

终端使用代理

  • 使用clash等搭建代理后,终端不经设置并不会通过代理,而无论是Windows还是Linux,方法都是加入http_proxy,https_proxy或all_proxy环境变量。

windows

临时设置

1
2
3
set http_proxy=http://127.0.0.1:7890  # =后的值可以加双引号,也可以不加
set https_proxy=http://127.0.0.1:7890 # 注意这里是设置https的代理,但是我们的代理还是http
set all_proxy=http://127.0.0.1:7890 # 这是一次性设置两个,可以不设置这个

永久设置

  • 终端启用代理的方法是那三个环境变量,因此永久设置就是手动去设置添加环境变量。

linux

临时设置

1
2
3
export http_proxy=http://127.0.0.1:7890  # =后的值可以加双引号,也可以不加
export https_proxy=http://127.0.0.1:7890 # 注意这里是设置https的代理,但是我们的代理还是http
export all_proxy=http://127.0.0.1:7890 # 这是一次性设置两个,可以不设置这个

永久设置

  • 同样的,永久设置也是是将其写入环境变量,在Linux中是将上述内容添加到/.bashrc或/.profile的末尾。

git

  • 如果只是git需要使用代理,可以在git设置代理,原理相同:
    1
    2
    git config --global http.proxy 'socks5://127.0.0.1:1080' 
    git config --global https.proxy 'socks5://127.0.0.1:1080'
  • 如果不想git全局使用代理,那只需要在需要代理的仓库输入去掉–global的命令即可:
    1
    2
    git config http.proxy 'socks5://127.0.0.1:1080' 
    git config https.proxy 'socks5://127.0.0.1:1080'
  • 若要取消git的代理设置:
    1
    2
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    1
    2
    git config --unset http.proxy
    git config --unset https.proxy

wsl使用windows代理

首先,允许局域网连接代理。

1
2
3
host_ip=$(ip route | awk '/default/ {print $3}')
export http_proxy="http://$host_ip:7890"
export https_proxy="http://$host_ip:7890"

Install

install nodejs

1
2
3
4
5
sudo apt install nodejs npm
node -v #查看node版本
npm -v #查看npm版本
sudo npm install -g cnpm --registry=http://registry.npm.taobao.org #安装淘宝的cnpm 管理器
cnpm -v #查看cnpm版本

install hexo

1
2
sudo cnpm install -g hexo-cli #安装hexo框架
hexo -v #查看hexo版本

create blog

1
2
3
git clone --recurse-submodules https://gitee.com/name/blog # 下载blog文件 (直接从自己仓库拉)
cnpm install # 安装 node modules
cnpm install hexo-hide-posts # 安装隐藏文章的插件

Usage

new file

1
hexo new "file name"

layout

1
2
3
4
5
6
# Hexo提供了三种默认布局:post(文章)、draft(草稿)、page(页面)
hexo new [layout] <title>
# 指定布局类型为page
hexo new page "我的页面"
# 不指定布局类型
hexo new "我的文章"

front-matter

  • 用—包围起来并置于文件头部的内容称为Front-matter,用于指定MD文件的变量
1
2
3
4
5
6
7
8
9
categories:
- 个人博客
- Hexo博客
tags:
- Hexo
- 博客

# 它的标签就是:Hexo、博客
# 它的分类就是:个人博客 > Hexo博客(”Hexo博客“是“个人博客”的子分类)
1
2
3
4
5
6
7
categories:
- [日常, 生活]
- [日常, 随想]
- [日记]

# 它属于三个分类:日常 > 生活,日常 > 随想,日记
# 其中生活、随想为日常的子分类,日常和日记为同级分类

commands

1
2
3
4
5
6
7
hexo clean # 清除缓存文件db.json和已生成的静态文件public
hexo generate/hexo g # Hexo会解析Markdown以及相关文件来生成网页
hexo server/hexo s # 启动服务器
hexo deploy/hexo d # 用于将网站更新到服务器上,需要将博客托管到服务器才能用此命令

hexo clean && hexo g && hexo s # 网站更新到服务器:清除缓存>生成静态文件>启动服务,测试没问题后再执行部署命令
hexo d