Skip to content

Commit

Permalink
feat: Docker、cli and web server
Browse files Browse the repository at this point in the history
  • Loading branch information
Leibnizhu committed Feb 26, 2024
1 parent 4ea4352 commit 58ed275
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 25 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM openjdk:17-jdk-slim
ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8
RUN sed -i -E 's/(security|deb)\.debian\.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& apt-get clean && apt-get update \
&& apt-get -y install tini

COPY bin/* /etc/tinylsm/
COPY target/scala-3.3.1/TinyLsmAssembly.jar /etc/tinylsm/TinyLsmAssembly.jar

RUN ln -s /etc/tinylsm/tinylsm-cli /usr/bin/tinylsm-cli

WORKDIR /etc/tinylsm
ENTRYPOINT ["tini", "--"]
CMD ["bash", "/etc/tinylsm/tinylsm"]
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
# TinyLSM

Tiny LSM in scala

Requirement:
## Requirement

- JDK 11 or later

## Configuration

Configuration lookup order:

1. JVM system properties, e.g., `-Dkey.subkey=value`
2. Operation system environment e.g., `export TINY_LSM_KEY_SUBKEY=value`
3. `.env` file in classpath, using operation system environment key
4. config file specified by JVM system properties `config.file` or operation system environment `TINY_LSM_CONFIG_FILE`,
using JVM system properties key

| environment key | system properties name | meaning | default value |
|--------------------------|------------------------|------------------------------------------------------------------------------|---------------------------|
| TINY_LSM_PORT | port | | 9527 |
| TINY_LSM_LISTEN | listen | | 0.0.0.0 |
| TINY_LSM_BLOCK_SIZE | block.size | Block size in bytes | 4096 |
| TINY_LSM_TARGET_SST_SIZE | block.size | SST size in bytes, also the approximate memtable capacity limit | 2 << 20 (2MB) |
| TINY_LSM_MEMTABLE_NUM | memtable.num | Maximum number of memtables in memory, flush to L0 when exceeding this limit | 50 |
| TINY_LSM_ENABLE_WAL | enable.wal | | true |
| TINY_LSM_SERIALIZABLE | serializable | | false |
| TINY_LSM_DATA_DIR | data.dir | | /etc/tinylsm/data |
| TINY_LSM_CONFIG_FILE | config.file | | /etc/tinylsm/tinylsm.conf |

[Reference](https://skyzh.github.io/mini-lsm/00-preface.html)
6 changes: 6 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
SCRIPT_DIR=$(cd $(dirname $0);pwd)
cd $SCRIPT_DIR/..

sbt assembly
docker build . -f Dockerfile -t ${DOCKER_IMAGE_TAG:-tiny-lsm:0.0.1} --network=host
4 changes: 4 additions & 0 deletions bin/tinylsm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
SCRIPT_DIR=$(cd $(dirname $0);pwd)

java -cp .:TinyLsmAssembly.jar io.github.leibnizhu.tinylsm.TinyLsmWebServer
4 changes: 4 additions & 0 deletions bin/tinylsm-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
SCRIPT_DIR=$(cd $(dirname $0);pwd)

java -cp .:TinyLsmAssembly.jar io.github.leibnizhu.tinylsm.TinyLsmCli $@
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ version := "0.1"

libraryDependencies ++= Seq(
"com.lihaoyi" %% "cask" % "0.9.2" % "compile",
"com.lihaoyi" %% "requests" % "0.8.0"% "compile",
"com.github.blemale" %% "scaffeine" % "5.2.1" % "compile",
"org.jboss.slf4j" % "slf4j-jboss-logging" % "1.2.1.Final" % "compile",
"org.jline" % "jline" % "3.25.1" % "compile",
"org.scalatest" %% "scalatest" % "3.2.9" % Test,
"org.mockito" % "mockito-core" % "4.11.0" % Test
)
Expand Down
31 changes: 26 additions & 5 deletions src/main/scala/io/github/leibnizhu/tinylsm/LsmStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ private[tinylsm] class LsmStorageInner(
* sst的范围是否包含用户指定的scan范围
*
* @param userBegin scan指定的左边界
* @param userEnd scan指定的右边界
* @param sstBegin sst的左边,第一个key
* @param sstEnd sst的右边,最后一个key
* @param userEnd scan指定的右边界
* @param sstBegin sst的左边,第一个key
* @param sstEnd sst的右边,最后一个key
* @return sst是否满足scan范围
*/
private def rangeOverlap(userBegin: Bound, userEnd: Bound,
Expand Down Expand Up @@ -358,12 +358,33 @@ case class LsmStorageOptions
blockSize: Int,
// SST大小,单位是 bytes, 同时也是MemTable容量限制的近似值
targetSstSize: Int,
// MemTable在内存中的最大占用空间, 到达这个大小后会 flush 到 L0
// MemTable在内存中的最多个数, 超过这么多MemTable后会 flush 到 L0
numMemTableLimit: Int,
// Compaction配置
compactionOptions: CompactionOptions,
// 是否启用WAL
enableWal: Boolean,
// 是否可序列化
serializable: Boolean
)
)

object LsmStorageOptions {
def defaultOption(): LsmStorageOptions = LsmStorageOptions(
4096,
2 << 20,
50,
NoCompaction(),
false,
false)

def fromConfig(): LsmStorageOptions =
LsmStorageOptions(
Config.BlockSize.getInt,
Config.TargetSstSize.getInt,
Config.MemTableLimitNum.getInt,
// TODO
NoCompaction(),
Config.EnableWal.getBoolean,
Config.Serializable.getBoolean
)
}
Loading

0 comments on commit 58ed275

Please sign in to comment.