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

发布版本 v0.1_alpha #20

Merged
merged 18 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
testFile
test_gen_files
xid.log
metadata.db

# IntelliJ IDEA
.idea
*.iws
*.iml
*.ipr
build/
.gradle

*.srctrl*
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: java
jdk: oraclejdk11
dist: trusty
group: edge

script:
- ./gradlew build --scan -s
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# RumBase Java

Java构建的高性能SQL关系型数据库。
| master | dev |
| ------ | --- |
| [![Build Status](https://www.travis-ci.com/kaaass/rumbase_java.svg?token=7d6V7UKwzfD6augATNKx&branch=master)](https://www.travis-ci.com/kaaass/rumbase_java) | [![Build Status](https://www.travis-ci.com/kaaass/rumbase_java.svg?token=7d6V7UKwzfD6augATNKx&branch=dev)](https://www.travis-ci.com/kaaass/rumbase_java) |

Java构建的SQL关系型数据库。

本项目为吉林大学2018级数据库系统课程&系统软件综合实践(荣誉课)课程设计。

## 构建

1. 在 Release 页面下载源码或 clone 项目
2. 在项目目录执行 `./gradlew build`

## 分工

| **模块** | **内容** | **负责人** | **包** |
| ----------------------- | -------------------- | ---------- | ------------ |
| Server Module | 服务器、会话管理 | @KAAAsS | server |
| Query Parse Module | SQL 语句解析 | @KAAAsS | parse |
| Query Execution Module | 查询执行、优化 | | query |
| Table Management Module | 系统内数据库、表管理 | | table |
| Indexing Module | 索引结构,使用 B+ 树 | | index |
| Query Execution Module | 查询执行、优化 | @KveinAxel | query |
| Table Management Module | 系统内数据库、表管理 | @KveinAxel | table |
| Indexing Module | 索引结构,使用 B+ 树 | @DoctorWei1314 | index |
| Record Module | 记录管理,实现 MVCC | @KAAAsS | record |
| Transaction Module | 实现事务的管理与 2PL | | transaction |
| Data Item Module | 数据项管理 | | dataitem |
| Recovery Log Module | 日志与恢复管理 | | recovery |
| Page Caching Module | 缓冲与页管理 | | page |
| Transaction Module | 实现事务的管理与 2PL | @criki | transaction |
| Data Item Module | 数据项管理 | @kaito | dataitem |
| Recovery Log Module | 日志与恢复管理 | @kaito | recovery |
| Page Caching Module | 缓冲与页管理 | @XuanLaoYee | page |
32 changes: 32 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ plugins {
id 'java'
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

group 'net.kaaass'
version '1.0-SNAPSHOT'

Expand All @@ -10,5 +14,33 @@ repositories {
}

dependencies {
// java-binary-block-parser
compile 'com.igormaznitsa:jbbp:2.0.2'
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
// Slf4j
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30'
// JSQLParser
compile 'com.github.jsqlparser:jsqlparser:4.0'
// JUnit
testCompile group: 'junit', name: 'junit', version: '4.12'
}

// Agree --scan ToS
if (hasProperty('buildScan')) {
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
}

test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}
28 changes: 28 additions & 0 deletions src/main/java/net/kaaass/rumbase/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.kaaass.rumbase;

import lombok.extern.slf4j.Slf4j;
import net.kaaass.rumbase.server.Server;

/**
* 入口类
*
* @author kaaass
*/
@Slf4j
public class Main {

public static void main(String[] args) {
log.info("Rumbase DBMS");
// 启动
log.info("Start preparing...");
Server.getInstance().prepare();
// 注册程序退出事件
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("Shutdown...");
Server.getInstance().shutdown();
}, "Shutdown-thread"));
// 运行
log.info("Starting server...");
Server.getInstance().run();
}
}
84 changes: 84 additions & 0 deletions src/main/java/net/kaaass/rumbase/dataitem/IItemStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.kaaass.rumbase.dataitem;

import net.kaaass.rumbase.dataitem.exception.PageCorruptedException;
import net.kaaass.rumbase.dataitem.exception.UUIDException;
import net.kaaass.rumbase.transaction.TransactionContext;

import java.util.List;

/**
* 数据项管理接口
*
* @author kaito
*/
public interface IItemStorage {
/**
* 插入数据项
*
* @param item 数据项
* @return 返回数据项的UUID
*/
long insertItem(TransactionContext txContext, byte[] item);

/**
* 插入一个有UUID的数据项,唯一使用的地方是日志恢复时使用
* <p>
* 如果数据项已经存在,就将数据更新在已存在的数据项所在空间上;
* 如果数据项不存在,则以此UUID插入数据项
* </p>
*
* @param item 数据项
* @param uuid 编号
*/
void insertItemWithUuid(TransactionContext txContext, byte[] item, long uuid);

/**
* 通过UUID查询数据项
*
* @param uuid 编号
* @return 数据项
* @throws UUIDException UUID找不到的异常
*/
byte[] queryItemByUuid(long uuid) throws UUIDException;


/**
* 列出页中所有的记录
*
* @param pageId 页号
* @return list的一堆数据项
*/
List<byte[]> listItemByPageId(int pageId);

/**
* 根据UUID更新数据项
*
* @param uuid 编号
* @param item 数据项
* @throws UUIDException 没有找到对应UUID的异常
*/
void updateItemByUuid(TransactionContext txContext, long uuid, byte[] item) throws UUIDException, PageCorruptedException;

/**
* 获得数据项存储的元数据(可以用于头)
*
* @return 元数据
*/
byte[] getMetadata();

/**
* 设置数据项存储的元数据(可以用于头)
*
* @param metadata 头信息
*/
void setMetadata(TransactionContext txContext, byte[] metadata) throws PageCorruptedException;

/**
* 清理多余的数据项,空间清理时使用。
*
* @param uuids 数据项UUID的编号列表
*/
void removeItems(List<Long> uuids);
}


59 changes: 59 additions & 0 deletions src/main/java/net/kaaass/rumbase/dataitem/ItemManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.kaaass.rumbase.dataitem;


import net.kaaass.rumbase.page.exception.FileException;
import net.kaaass.rumbase.page.exception.PageException;
import net.kaaass.rumbase.transaction.TransactionContext;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* 数据项管理类
*
* @author kaito
*/

public class ItemManager {

static Map<String, IItemStorage> maps = new HashMap<>();

/**
* 通过文件名解析得到数据项管理器
*
* @param fileName 文件名
* @return 数据项管理器,用于管理数据项
*/
public static IItemStorage fromFile(String fileName) throws FileException, IOException, PageException {
if (maps.containsKey(fileName)) {
return maps.get(fileName);
} else {
IItemStorage iItemStorage = ItemStorage.ofFile(fileName);
maps.put(fileName, iItemStorage);
return iItemStorage;
}
}

/**
* 新建一个数据库,并且将上层提供的头信息写入。
*
* @param fileName 文件名
* @param metadata 上层提供的表头信息
* @param txContext 对应的事务名
* @return 数据项管理器
* @throws FileException 想新建的文件已经存在的异常
*/
public static IItemStorage createFile(TransactionContext txContext, String fileName, byte[] metadata) throws FileException, IOException, PageException {
// 如果文件已经存在,那么就抛出文件已存在异常
if (maps.containsKey(fileName)) {
throw new FileException(1);
} else {
// 若文件不存在,则创建文件。
IItemStorage iItemStorage = ItemStorage.ofNewFile(txContext, fileName, metadata);
maps.put(fileName, iItemStorage);
return iItemStorage;
}

}
}
Loading