+
Skip to content

warncke/logsrd

Repository files navigation

logsrd

A Synchronously replicated distributed log server.

Proof of Concept

This is a proof of concept implementation only. It is not intended for production use!!!

Description

logsrd implements a system for high-availability log replication based entirely on synchronous replication without the use of quorum based consistency. For a more detailed write up on the approach see Synchronous Replication with High Availability — A New Approach

Running the Server

Initializing data dir

mkdir data
mkdir data/logs
node utils/create-data-dirs ./data/logs

Build

npm run build

Run single instance with defaults

node build/logsrd

ENV options

ENV var Default Description
HOST 127.0.0.1 IP address to bind to
PORT 700 Port to bind to
DATA_DIR ./data Directory for storing data
SERVER_SECRET secret Secret token for authenticating replication
HOSTS Command seperated list of HOST:PORT for all servers in cluster

HTTP API

Authentication

Logs define their own access control.

For operations that require a token an Authorization: Bearer TOKEN header must be set.

Post /log

Create a new log.

POST body must be JSON conforming to the LogConfig schema.

logId must be empty. This value is generated by the server.

POST /log/:logId

Append an entry to log.

POST body may be either binary or JSON depending on log type.

Optional Query Params

  • lastEntryNum=ENTRY_NUMBER

Do conditional append only if there have been no appends after ENTRY_NUMBER.

GET /log/:logId/head

Get most recent entry to log.

This may return either a log entry or the most recent log config if that is the most recent entry. Mixing config entries with other entries is a rather poor design so this will probably be changed

Optional Query Parms

  • meta=true

Return log entry as JSON object that includes entryNum, crc, and entry

This currently only works for JSON type logs

GET /log/:logId/entries

Get list of log entries.

Optional Query Parms

  • offset=ENTRY_NUM

Start list at ENTRY_NUM

  • limit=NUMBER

Limit number of entries returned (Max 100).

  • entryNums=ENTRY_NUM,ENTRY_NUM,...

Return list of specific entries

  • meta=true

Return log entry as JSON object that includes entryNum, crc, and entry

This currently only works for JSON type logs

GET /log/:logId/config

Get current log config

PATCH /log/:logId/config

Set included properties to existing log config and store as new config.

GET /version

Get version of logsrd.

WebSocket API

/client

After making a /client websocket connection commands are sent as text.

Commands

sub:logId:token

Subscribe to logId using token that allows read access to log if it is private.

Once subscribed all new log entries will be sent to socket as binary.

unsub:logId

Unsubscribe from log

Responses

Commands will be replied to with a text response that is original command and either ok or err.

sub:logId:ok
sub:logId:err:err_message
unsub:logId:ok

Log Config Schema

logId

  • Type: String
  • Default: ""
  • Description: Unique identifier for the log
  • Required: Yes

type

  • Type: String
  • Enum:
    • binary
    • json
  • Default: "json"
  • Description: Specifies the log data format
  • Required: Yes

master

  • Type: String
  • Default: ""
  • Description: Primary/master log reference
  • Required: Yes

replicas

  • Type: Array
  • Items:
    • Type: String
  • Nullable: Yes
  • Description: List of replica log references

asyncReplicas

  • Type: Array
  • Items:
    • Type: String
  • Nullable: Yes
  • Description: List of asynchronous replica log references

access

  • Type: String
  • Enum:
    • public
    • private
    • readOnly
    • writeOnly
  • Default: "private"
  • Description: Access control level for the log
  • Required: Yes

authType

  • Type: String
  • Enum:
    • token
    • jwt
  • Default: "token"
  • Description: Authentication method
  • Required: Yes

accessToken

  • Type: String
  • Nullable: Yes
  • Description: General access token

adminToken

  • Type: String
  • Nullable: Yes
  • Description: Administrative access token

readToken

  • Type: String
  • Nullable: Yes
  • Description: Read-only access token

writeToken

  • Type: String
  • Nullable: Yes
  • Description: Write-only access token

superToken

  • Type: String
  • Nullable: Yes
  • Description: Superuser access token

jwtProperties

  • Type: Array
  • Items:
    • Type: String
  • Nullable: Yes
  • Description: List of JWT properties when authType is "jwt"

jwtSecret

  • Type: String
  • Nullable: Yes
  • Description: Secret key for JWT authentication

stopped

  • Type: Boolean
  • Default: false
  • Description: Indicates if the log is stopped
  • Required: Yes

configLogAddress

  • Type: String
  • Nullable: Yes
  • Description: Address for configuration log

Access Control

Operations

There are 3 types of operations that can be performed on logs.

Read

Read data from log.

Write

Write data to log.

Admin

Read/Write the config for log.

Access Control

Logs have four access control modes:

Public

Allow unauthenticated read/write access to log but not admin.

Private

Do not allow any unauthenticated access to log.

Read Only

Allow unauthenticated read to log.

Write Only

Allow unauthenticated write to log.

Authentication Type

Logs can use either token or jwt authentication.

Tokens

accessToken

Allows full read|write|admin access to log unless adminToken or superToken is set on log, in which case it only provides read|write access.

readToken

Allows read access to log.

writeToken

Allows write access to log.

adminToken

Allows admin access (but not read|write) to log.

superToken

Allows full read|write|admin access to log.

JWT Tokens

jwtSecret

If jwt authentication is used then auth token must be HS256 and signed with jwtSecret.

Token Properties

allow

Signed JWT Token must include allow property which contains one or more of admin|read|write privileges that are allowed by token.

jwtProperties

Comma separated list of additional properties in the JWT Token which should be copied to the log entry when doing an append.

This is useful for client side applications where the authentication service wants to include user specific information (e.g. userId) in a log entry that is sent from client.

About

A Synchronously replicated distributed log server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载