Giter VIP home page Giter VIP logo

mydb's Introduction

MYDB

MYDB 是一个 Java 实现的简单的数据库,部分原理参照自 MySQL、PostgreSQL 和 SQLite。实现了以下功能:

  • 数据的可靠性和数据恢复
  • 两段锁协议(2PL)实现可串行化调度
  • MVCC
  • 两种事务隔离级别(读提交和可重复读)
  • 死锁处理
  • 简单的表和字段管理
  • 简陋的 SQL 解析(因为懒得写词法分析和自动机,就弄得比较简陋)
  • 基于 socket 的 server 和 client

运行方式

注意首先需要在 pom.xml 中调整编译版本,如果导入 IDE,请更改项目的编译版本以适应你的 JDK

首先执行以下命令编译源码:

mvn compile

接着执行以下命令以 /tmp/mydb 作为路径创建数据库:

mvn exec:java -Dexec.mainClass="top.guoziyang.mydb.backend.Launcher" -Dexec.args="-create /tmp/mydb"

随后通过以下命令以默认参数启动数据库服务:

mvn exec:java -Dexec.mainClass="top.guoziyang.mydb.backend.Launcher" -Dexec.args="-open /tmp/mydb"

这时数据库服务就已经启动在本机的 9999 端口。重新启动一个终端,执行以下命令启动客户端连接数据库:

mvn exec:java -Dexec.mainClass="top.guoziyang.mydb.client.Launcher"

会启动一个交互式命令行,就可以在这里输入类 SQL 语法,回车会发送语句到服务,并输出执行的结果。

一个执行示例:

mydb's People

Contributors

cn-guoziyang avatar fravenx avatar pianoplayeer avatar yeyuan1107 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mydb's Issues

大神能指点下怎么启动项目吗

The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\DC0426\IdeaProjects\MYDB-master). Please verify you invoked Maven from the correct directory.
额,大神这项目怎么启动来着。。。。。。小白试了你的方法不行。。。。。。。。

请教一下vm层下LockTable的selectNewXID方法

xid获取到uid后,为什么没有更新x2u呢?

// 从等待队列中选择一个xid来占用uid
private void selectNewXID(long uid) {
    u2x.remove(uid);
    List<Long> l = wait.get(uid);
    if(l == null) return;
    assert l.size() > 0;
    while(l.size() > 0) {
        long xid = l.remove(0);
        if(!waitLock.containsKey(xid)) {
            continue;
        } else {
            u2x.put(uid, xid);
            Lock lo = waitLock.remove(xid);
            waitU.remove(xid);
            lo.unlock();
            break;
        }
    }
    if(l.size() == 0) wait.remove(uid);
}

请问您有遇到过这个报错嘛?

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project MyDB: An exception occured while executing the Java class. top.guoziyang.mydb.backend.Launcher -> [Help 1]

博客中 mydb1 勘误

begin() 方法会开始一个事务,更具体的,首先设置 xidCounter+1 事务的状态为 committed,随后 xidCounter 自增,并更新文件头。

committed状态应该是active状态吧

您好,请问我在创建数据库的时候为什么会找不到Lancher类呀

[INFO]
[INFO] --- exec-maven-plugin:3.1.0:java (default-cli) @ MyDB ---
[WARNING]
java.lang.ClassNotFoundException: "top.guoziyang.mydb.backend.Launcher"
at org.codehaus.mojo.exec.URLClassLoaderBuilder$ExecJavaClassLoader.loadClass (URLClassLoaderBuilder.java:198)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:271)
at java.lang.Thread.run (Thread.java:834)

缓存的close()方法好像有bug

protected void close() {
        lock.lock();
        try {
            Set<Long> keys = cache.keySet();
            for (long key : keys) {
                release(key);
                references.remove(key);
                cache.remove(key);
            }
        } finally {
            lock.unlock();
        }
}

release()方法在key的引用降到0时才会进行回源,如果key的ref没有到0不就没有回源吗,并没有在关闭的时候把缓存中所有资源回源

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.