Skip to content

Commit

Permalink
feat(su): rocksdb impl changes #987
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Oct 15, 2024
1 parent c3e67ec commit df82ae6
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 172 deletions.
6 changes: 3 additions & 3 deletions servers/su/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions servers/su/DockerfileMigLocal
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Stage 1: Build the dynamic binary
FROM rust:1.75.0 as mig-local-builder

# Set the working directory in the container
WORKDIR /usr/src/mig_local

# Install required dependencies for building
RUN apt-get update && apt-get install -y \
llvm-dev \
libclang-dev \
clang \
librocksdb-dev

# Copy the manifests
COPY Cargo.toml Cargo.lock ./

# This step is to cache your dependencies
RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
cargo build --release && \
rm -f target/release/deps/mig_local*

# Now copy the actual source code and build the application
COPY src ./src
COPY migrations ./migrations
RUN cargo build --release --bin mig_local

# The final output binary will be in /usr/src/mig/target/release/mig
27 changes: 27 additions & 0 deletions servers/su/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ This is an spec compliant `ao` Scheduler Unit, implemented as a Rust actix web s
- [Running the binary, su MODE](#running-the-binary-su-mode)
- [Running a router in front of multiple scheduler units](#running-a-router-in-front-of-multiple-scheduler-units)
- [Running the binary, router MODE](#running-the-binary-router-mode)
- [Migrations](#migrations)
- [Migrating data to disk for an existing su instance](#migrating-data-to-disk-for-an-existing-su-instance)
- [Migrating data to fully local data store](#migrating-data-to-fully-local-data-store)

<!-- tocstop -->

Expand Down Expand Up @@ -153,6 +155,9 @@ docker build -t su-runner .
docker run --env-file .env.router -v ./.wallet.json:/app/.wallet.json -v ./schedulers.json:/app/.schedulers.json su-runner router 9000
```

## Migrations

Over time the su database has evolved. It started as only Postgres then went to Postgres + RocksDB for performance enhancement. It now has a purely RocksDB implementation. For existing su's that already have data, you can follow the below to migration processes to bring it up to date to the latest implementation.

### Migrating data to disk for an existing su instance
If a su has been running using postgres for sometime there may be performance issues. Writing to and reading files from disk has been added. In order to switch this on set the environment variables
Expand Down Expand Up @@ -185,6 +190,28 @@ docker create --name temp-container-mig mig-binary
docker cp temp-container-mig:/usr/src/mig/target/release/mig .
```

### Migrating data to fully local data store
If a su has been running using postgres + rocksdb using the above migration, it can then be migrated to using purely RocksDB in a totally local data store. Use the following environment variables to configure this. Set `USE_LOCAL_STORE` to false while running the migration then once it is complete set it to true.

- `USE_LOCAL_STORE` If set to true, the su will use a purely rocksdb data storage implementation.
- `SU_FILE_DB_DIR` a directory for a RocksDB instance that will hold the full binary files that are the bundles, messages, and assignments.
- `SU_INDEX_DB_DIR` a directory for a RocksDB instance that will hold an index of Processes and Messages for ordering and querying.

Then the `mig_local` binary can be used to migrate data in segments from the existing source. Note that you must have already run the above `mig` binary before running `mig_local` will work. It cannot migrate from a purely postgres implementation. So to get to this point if the su was running on only postgres, first follow the above steps using the `mig` binary. And then follow the `mig_local` steps.

Migrate all Messages and Processes to RocksDB
```sh
./mig_local
```

Building the mig_local binary, delete all su images and containers if you have previously run this, then run
```sh
docker system prune -a
docker build --target mig-local-builder -t mig-local-binary -f DockerfileMigLocal .
docker create --name temp-container-mig-local mig-local-binary
docker cp temp-container-mig-local:/usr/src/mig_local/target/release/mig_local .
```

# System Requirements for SU + SU-R cluster

The SU + SU-R runs as a cluster of nodes. The SU-R acts as a redirector to a set of SU's. In order to run the cluster you need at least 2 nodes. 1 SU and one SU-R (a SU running in router mode). In order for the SU-R to initialize properly when it boots up, it has to be started up with a configured set of SU's in the SCHEDULER_LIST_PATH environment variable.
Expand Down
Binary file added servers/su/mig_local
Binary file not shown.
8 changes: 8 additions & 0 deletions servers/su/src/bin/mig_local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::io;

use su::domain::migrate_to_local;

#[tokio::main]
async fn main() -> io::Result<()> {
migrate_to_local().await
}
Loading

0 comments on commit df82ae6

Please sign in to comment.