diff --git a/Cargo.toml b/Cargo.toml index 10d27be..0a63f47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "rocky" version = "0.1.0" authors = ["dkos "] edition = "2018" -categories = ["http", "rocksdb"] +categories = ["http", "rocksdb", "storage"] description = "RocksDb as a service" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 8c07854..9cc1c96 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,72 @@ # Rocky -Rocky is a http service based on RocksDb with support for multiple databases and expiration. -Written in Rust on top of actix-web. +Rocky is a key/value storage service based on facebook [RocksDb](https://github.com/facebook/rocksdb/wiki) with support for multiple databases and record expiration. +## Rocky REST API +### Open db +You can open a new db with a ```POST``` request on ```SERVICE_URL:SERVICE_PORT/{db_name}``` -## Open db +```curl -X POST localhost:8080/database_1``` -## Close db +A successful request is indicated by a ```200 OK HTTP``` status code. +Each database is created with the same [configuration](#Configuration). + +### Close db +You can close an existing db with a ```DELETE``` request on ```SERVICE_URL:SERVICE_PORT/{db_name}``` + +```curl -X DELETE localhost:8080/database_1``` + +A successful request is indicated by a ```200 OK HTTP``` status code. + +### Store record +You can write data with a ```POST``` request on ```SERVICE_URL:SERVICE_PORT/{db_name}/{key}``` + +```curl -d 'payload can be anything' localhost:8080/database_1/record_1``` + +A successful request is indicated by a ```200 OK HTTP``` status code. -## Store record #### TTL support -## Read record -## Delete record +Rocky support time to live per record provided in milliseconds. +You can add ```ttl``` on record by providing a custom header + +```curl -d 'I\'ll expire soon' -H 'ttl: 5000' localhost:8080/database_1/expiring_record_1``` + +### Read record +You can read data with a ```GET``` request on ```SERVICE_URL:SERVICE_PORT/{db_name}/{key}``` + +```curl -v localhost:8080/database_1/record_1``` + +The response contains data associated with the database and and key provided in path: + +From the previous example this is our response +```payload can be anythingā¸ˇ ``` + +Data is always return with content type header ```content-type: application/octet-stream``` +A successful request is indicated by a ```200 OK HTTP``` status code. + +### Delete record +You can delete data with a ```DELETE``` request on ```SERVICE_URL:SERVICE_PORT/{db_name}/{key}``` + +```curl -X DELETE localhost:8080/database_1/record_1``` + +A successful request is indicated by a ```200 OK HTTP``` status code. + +### Metrics +Service metrics in [prometheus format](https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md) are available for scraping under ```SERVICE_URL:SERVICE_PORT/metrics``` + +## Configuration + +When running service external configuration and log path should be provided or Rocky will use defaults. +```--log_path``` path where log files should be written +```--config_path``` path where service should look for external database and service configuration. Rocky will look for db_config.toml + and service_config.toml files under this path if not found will create config files with defaults. + +For database performance tuning check the official [RocksDb tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide) +For service performance tuning check example service_config.toml and yes - ```workers``` is the only config parameter that matters, default is number of logical CPUs +Example configuration is provided under ```project_root/config``` + +## Licence +Rocky is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + diff --git a/src/main.rs b/src/main.rs index b059249..60351d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use actix_web::body::{Body, ResponseBody}; use actix_web::http::header::ContentType; use actix_web::middleware::errhandlers::{ErrorHandlerResponse, ErrorHandlers}; use actix_web::web::Bytes; -use actix_web::{delete, dev, get, http, post, put, HttpRequest, HttpResponse, ResponseError}; +use actix_web::{delete, dev, get, http, post, HttpRequest, HttpResponse, ResponseError}; use actix_web::{web, App, HttpServer}; use actix_web_prom::PrometheusMetrics; use log::LevelFilter; @@ -114,7 +114,7 @@ async fn close(db_name: web::Path, db_man: web::Data) -> Resp Ok(HttpResponse::Ok().finish()) } -#[put("/{db_name}/{key}")] +#[post("/{db_name}/{key}")] async fn store( p_val: web::Path, body: Bytes,