Skip to content

Commit

Permalink
add sharding, search, sorting, soft removal
Browse files Browse the repository at this point in the history
  • Loading branch information
tellnobody1 committed Sep 20, 2024
1 parent 7324c68 commit 594134c
Show file tree
Hide file tree
Showing 104 changed files with 2,683 additions and 4,409 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
name: test

on: [ push ]
on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v4.1.1
with:
clean: false
fetch-depth: 0 # with tags
submodules: 'recursive'
- uses: actions/setup-java@v1.4.3
- uses: actions/setup-java@v4.1.0
with:
java-version: 11
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: sbt +compile +test
java-version: 21
distribution: 'zulu'
- run: sbt test
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.DS_Store
target/
/tmp
/.bsp/
.bloop
.metals
.vscode
project/project
project/metals.sbt
/data/example-*/
/data/test-*/
target/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "proto"]
path = deps/proto
url = https://github.com/zero-deps/proto
url = git@github.com:zero-deps/proto.git
branch = main
2 changes: 1 addition & 1 deletion .sbtopts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-J-XX:MaxMetaspaceSize=512m
-J-XX:MaxMetaspaceSize=1g
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 zero-deps
Copyright (c) 2015–2024 zero-deps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
54 changes: 19 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
# Abstract scala type database
# Scala Abstract Type Database

![ci](https://github.com/zero-deps/kvs/workflows/ci/badge.svg)
![Production Ready](https://img.shields.io/badge/Project%20Stage-Production%20Ready%20(main)-brightgreen.svg)
![Development](https://img.shields.io/badge/Project%20Stage-Development%20(series/5.x)-yellowgreen.svg)

Abstract Scala storage framework with high-level API for handling linked lists of polymorphic data (feeds).
[![Documentation](https://img.shields.io/badge/documentation-pdf-yellow)](kvs.pdf)
[![Paper](https://img.shields.io/badge/paper-pdf-lightgrey)](https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf)

KVS is highly available distributed (AP) strong eventual consistent (SEC) and sequentially consistent (via cluster sharding) storage. It is used for data from sport and games events. In some configurations used as distributed network file system. Also can be a generic storage for application.
This open-source project presents an abstract storage framework in Scala, offering a high-level API tailored for managing linked lists of polymorphic data, referred to as 'feeds.' The system, known as KVS (Key-Value Storage), boasts attributes such as high availability, distributed architecture (AP), strong eventual consistency (SEC), and sequential consistency achieved through cluster sharding. Its primary application involves handling data from sports and gaming events, but it can also serve as a distributed network file system or a versatile general-purpose storage solution for various applications.

Designed with various backends in mind and to work in pure JVM environment. Implementation based on top of KAI (implementation of Amazon DynamoDB in Erlang) port with modification to use akka-cluster infrastructure.
The design philosophy behind KVS encompasses versatility, with support for multiple backend implementations and compatibility within a pure JVM environment. The implementation is grounded in the KAI framework (an Erlang-based Amazon DynamoDB implementation), adapted to utilize the pekko-cluster infrastructure.

Currently main backend is RocksDB to support embedded setup alongside application. Feed API (add/entries/remove) is built on top of Key-Value API (put/get/delete).
At its core, KVS relies on RocksDB as the primary backend, enabling seamless integration in embedded setups alongside applications. The central Feed API, facilitating operations like addition, entry retrieval, and removal, is constructed upon the foundation of the Key-Value API, which includes functions for putting, getting, and deleting data.

## Usage

Add project as a git module.
Add project as a git submodule.

## Backend
## Project Structure

* Ring
* RocksDB
* Memory
* FS
* SQL
* etc.
* `./feed`: Introduces the Feed over Ring concept
* `./search`: Offers Search over Ring functionality
* `./sort`: Implements a Sorted Set on Ring
* `./ring`: Establishes a Ring structure using Pekko Cluster
* `./sharding`: Addresses Sequential Consistency & Cluster Sharding aspects
* `./src`: Contains illustrative sample applications and comprehensive tests

## Test
## Test & Demo

```bash
sbt> test
sbt test
sbt run
```

## Resources

### Chain Replication

[Chain Replication in Theory and in Practice](http://www.snookles.com/scott/publications/erlang2010-slf.pdf)

[Chain Replication for Supporting High Throughput and Availability](http://www.cs.cornell.edu/home/rvr/papers/OSDI04.pdf)

[High-throughput chain replication for read-mostly workload](https://www.cs.princeton.edu/courses/archive/fall15/cos518/papers/craq.pdf)

[Leveraging Sharding in the Design of Scalable Replication Protocols](https://ymsir.com/papers/sharding-socc.pdf)

[Byzantine Chain Replication](http://www.cs.cornell.edu/home/rvr/newpapers/opodis2012.pdf)

### Consensus Algorithm

[RAFT](https://raft.github.io/raft.pdf)
[SWIM](https://www.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf)
96 changes: 66 additions & 30 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,53 +1,89 @@
val scalav = "3.2.2"
val zio = "2.0.10"
val akka = "2.6.20"
val rocks = "7.10.2"
val protoj = "3.22.2"
val lucene = "8.11.2"
val scalav = "3.3.3"
val zio = "2.0.21"
val pekko = "1.0.2"
val rocks = "8.11.3"
val protoj = "3.25.3"
val lucene = "9.10.0"

lazy val root = project.in(file(".") ).aggregate(kvs)
lazy val kvsroot = project.in(file(".")).settings(
scalaVersion := scalav
, libraryDependencies ++= Seq(
"dev.zio" %% "zio-test-sbt" % zio % Test
, "org.apache.pekko" %% "pekko-cluster-sharding" % pekko
)
, testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
, scalacOptions ++= scalacOptionsCommon
, Test / fork := true
, run / fork := true
, run / connectInput := true
).dependsOn(feed, search, sort).aggregate(ring, feed, search, sort)

lazy val kvs = project.in(file("kvs")).settings(
lazy val ring = project.in(file("ring")).settings(
scalaVersion := scalav
, Compile / scalaSource := baseDirectory.value / "src"
, libraryDependencies ++= Seq(
"com.typesafe.akka" % "akka-cluster-sharding_2.13" % akka
, "com.typesafe.akka" % "akka-slf4j_2.13" % akka
, "ch.qos.logback" % "logback-classic" % "1.4.5"
, "com.github.jnr" % "jnr-ffi" % "2.2.2"
, "org.apache.lucene" % "lucene-analyzers-common" % lucene
, "dev.zio" %% "zio" % zio
, "dev.zio" %% "zio-nio" % "2.0.0"
"org.apache.pekko" %% "pekko-cluster" % pekko
, "org.rocksdb" % "rocksdbjni" % rocks
, "org.scalatest" %% "scalatest" % "3.2.14" % Test
, "com.typesafe.akka" % "akka-testkit_2.13" % akka % Test
, "dev.zio" %% "zio" % zio
)
, scalacOptions ++= scalacOptions3
, scalacOptions ++= scalacOptionsCommon diff Seq("-language:strictEquality") :+ "-nowarn"
).dependsOn(proto)

lazy val proto = project.in(file("deps/proto/proto")).settings(
lazy val sharding = project.in(file("sharding")).settings(
scalaVersion := scalav
, crossScalaVersions := scalav :: Nil
, libraryDependencies += "com.google.protobuf" % "protobuf-java" % protoj
).dependsOn(protoops)
, Compile / scalaSource := baseDirectory.value / "src"
, libraryDependencies ++= Seq(
"org.apache.pekko" %% "pekko-cluster-sharding" % pekko
)
, scalacOptions ++= scalacOptionsCommon
).dependsOn(ring)

lazy val feed = project.in(file("feed")).settings(
scalaVersion := scalav
, Compile / scalaSource := baseDirectory.value / "src"
, libraryDependencies ++= Seq(
"dev.zio" %% "zio-streams" % zio
)
, scalacOptions ++= scalacOptionsCommon
).dependsOn(sharding)

lazy val search = project.in(file("search")).settings(
scalaVersion := scalav
, Compile / scalaSource := baseDirectory.value / "src"
, libraryDependencies ++= Seq(
"dev.zio" %% "zio-streams" % zio
, "org.apache.lucene" % "lucene-analysis-common" % lucene
)
, scalacOptions ++= scalacOptionsCommon
).dependsOn(sharding)

lazy val sort = project.in(file("sort")).settings(
scalaVersion := scalav
, Compile / scalaSource := baseDirectory.value / "src"
, libraryDependencies ++= Seq(
"dev.zio" %% "zio-streams" % zio
)
, scalacOptions ++= scalacOptionsCommon
).dependsOn(sharding)

lazy val protoops = project.in(file("deps/proto/ops")).settings(
lazy val proto = project.in(file("deps/proto/proto")).settings(
scalaVersion := scalav
, crossScalaVersions := scalav :: Nil
, libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java" % protoj
)
, scalacOptions ++= scalacOptionsCommon diff Seq("-language:strictEquality") :+ "-Xcheck-macros"
).dependsOn(protosyntax)

lazy val protosyntax = project.in(file("deps/proto/syntax")).settings(
scalaVersion := scalav
, crossScalaVersions := scalav :: Nil
, scalacOptions ++= scalacOptionsCommon diff Seq("-language:strictEquality")
)

val scalacOptions3 = Seq(
"-source:future", "-nowarn"
val scalacOptionsCommon = Seq(
"-Yexplicit-nulls"
, "-language:strictEquality"
, "-language:postfixOps"
, "-Yexplicit-nulls"
, "-encoding", "UTF-8"
)

turbo := true
useCoursier := true
Global / onChangedBuildSource := ReloadOnSourceChanges
2 changes: 1 addition & 1 deletion deps/proto
Submodule proto updated 56 files
+9 −17 .github/workflows/test.yml
+1 −6 .gitignore
+2 −1 .sbtopts
+5 −0 .sdkmanrc
+1 −1 LICENSE
+42 −12 README.md
+0 −214 bench/src/main/scala-2.13/data.scala
+0 −72 bench/src/main/scala-2.13/msg.scala
+95 −0 bench/src/main/scala-3/data.scala
+21 −0 bench/src/main/scala-3/msg.scala
+100 −54 build.sbt
+1 −1 project/build.properties
+10 −3 project/plugins.sbt
+303 −0 proto/src/main/scala-2.11/BuildCodec.scala
+158 −0 proto/src/main/scala-2.11/Common.scala
+30 −0 proto/src/main/scala-2.11/api.scala
+14 −0 proto/src/main/scala-2.11/codec.scala
+233 −0 proto/src/main/scala-2.11/macrosapi.scala
+1 −1 proto/src/main/scala-2.12/BuildCodec.scala
+4 −0 proto/src/main/scala-2.12/Common.scala
+1 −1 proto/src/main/scala-2.13/BuildCodec.scala
+4 −0 proto/src/main/scala-2.13/Common.scala
+9 −11 proto/src/main/scala-3/BuildCodec.scala
+4 −0 proto/src/main/scala-3/Common.scala
+17 −19 proto/src/main/scala-3/macrosapi.scala
+520 −0 proto/src/test/scala-2.11/testing.scala
+27 −27 proto/src/test/scala-2.13/testing.scala
+0 −0 purs/src/main/scala-2.13/ops.scala
+0 −11 purs/src/main/scala-3.0/io.scala
+0 −252 purs/src/main/scala-3.0/purs.scala
+82 −0 purs/src/main/scala-3/Common.scala
+308 −0 purs/src/main/scala-3/decoders.scala
+154 −0 purs/src/main/scala-3/encoders.scala
+13 −0 purs/src/main/scala-3/io.scala
+172 −0 purs/src/main/scala-3/main.scala
+224 −0 purs/src/main/scala-3/ops.scala
+85 −0 purs/src/main/scala-3/purs.scala
+6 −0 purs/src/main/scala-3/tpe.scala
+26 −0 purs/src/test/scala-3/default.test.scala
+25 −0 purs/src/test/scala-3/enum.test.scala
+28 −0 purs/src/test/scala-3/eq.test.scala
+135 −0 purs/src/test/scala-3/purs.test.scala
+26 −0 purs/src/test/scala-3/setmap.test.scala
+499 −463 purs/test/bin/compiled.js
+2,247 −420 purs/test/package-lock.json
+2 −3 purs/test/package.json
+2 −107 purs/test/packages.dhall
+13 −5 purs/test/spago.dhall
+9 −4 tex/src/main/scala-2.13/main.scala
+216 −0 tex/src/main/scala-2.13/ops.scala
+203 −2 tex/src/main/scala-2.13/tex.scala
+82 −0 tex/src/main/scala-3/Common.scala
+7 −0 tex/src/main/scala-3/ext.scala
+94 −0 tex/src/main/scala-3/main.scala
+224 −0 tex/src/main/scala-3/ops.scala
+326 −0 tex/src/main/scala-3/tex.scala
1 change: 0 additions & 1 deletion docs/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions docs/about.tex

This file was deleted.

18 changes: 0 additions & 18 deletions docs/info.tex

This file was deleted.

60 changes: 0 additions & 60 deletions docs/kvs.tex

This file was deleted.

Loading

0 comments on commit 594134c

Please sign in to comment.