Skip to content
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This project is under the MIT license.
| --- | --- |
| REPL for testing | Yes |
| Append Only Log Structured Storage | Yes |
| Log Rotation | No |
| Log Rotation | Yes |
| CRC Validation | Yes |
| Startup KeyDir rebuilding | Yes |
| Log Compaction | No |
Expand All @@ -34,7 +34,7 @@ Note that at runtime the entire keyspace is maintained in memory so enough memor

The data on disk is organized into files with a capped size that is configurable using the environment variables listed below. Files are rotated as they reach this size.

The previously stored and compacted files are named `<timestamp>`, where `<timestamp>` is the string representation of seconds since epoch. The file currently being written is named `0`.
The previously stored and compacted files are named `<timestamp>`, where `<timestamp>` is the string representation of milliseconds since epoch. The file currently being written is named with the most recent timestamp value.

## Binary Entry File Format

Expand Down Expand Up @@ -134,15 +134,15 @@ The following environment variables provide configuration values for the databas

#### Optional Environment Variables

`RUSTCASK_MAX_FILE_SIZE_MB` - The maximum file size cap, in MB. Defaults to 4 MB if not present.
`RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES` - The number of bytes after which to rotate the active file. Defaults to 4 MiB if not present.

## Running the Application

First, configure a local `.env` file to contain the following environment variables:

```
RUSTCASK_FILE_PATH=<absolute path to file storage for database data>
RUSTCASK_MAX_FILE_SIZE_MB=<integer file size, in MB>
RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES=<integer file size, in bytes>
RUST_LOG=<log level>
```

Expand Down
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
};
use tracing_subscriber::EnvFilter;

const DEFAULT_RUSTCASK_MAX_FILE_SIZE_MB: &str = "4";
const DEFAULT_RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES: u64 = 4194304;

#[derive(Debug)]
enum ReplError {
Expand All @@ -45,7 +45,7 @@ fn main() -> Result<(), ReplError> {
#[cfg(feature = "mock")]
let db = MockDatabase::open();
#[cfg(not(feature = "mock"))]
let db = RustcaskDatabase::open(settings.file_path).map_err(|e| ReplError::DatabaseError(e))?;
let db = RustcaskDatabase::open(settings.file_path, settings.rotate_active_file_after_bytes).map_err(|e| ReplError::DatabaseError(e))?;

cmd_loop(db)
}
Expand All @@ -64,12 +64,11 @@ fn load_settings() -> Result<Settings, ReplError> {
)));
}

let max_file_size_env_value = env::var("RUSTCASK_MAX_FILE_SIZE_MB")
.unwrap_or(DEFAULT_RUSTCASK_MAX_FILE_SIZE_MB.into())
.parse::<u8>()
.expect("RUSTCASK_MAX_FILE_SIZE_MB did not parse into a u8");
let rotate_active_file_after_bytes_env_value = env::var("RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES")
.map_or(Ok(DEFAULT_RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES), |v| v.parse::<u64>())
.expect("RUSTCASK_ROTATE_ACTIVE_FILE_AFTER_BYTES did not parse into a u64");

Ok(Settings::new(file_path, max_file_size_env_value))
Ok(Settings::new(file_path, rotate_active_file_after_bytes_env_value))
}

#[tracing::instrument(skip(db))]
Expand Down
Loading