package
0.0.0-20241105204840-47fcb773a808
Repository: https://github.com/surahman/mcq-platform.git
Documentation: pkg.go.dev

# README

Apache Cassandra

Configuration loading is designed for containerization in mind. The container engine and orchestrator can mount volumes (secret or regular) as well as set the environment variables as outlined below.

You may set configurations through both files and environment variables. Please note that environment variables will override the settings in the configuration files. The configuration files are all expected to be in YAML format.


Table of contents


File Location(s)

The configuration loader will search for the configurations in the following order:

LocationDetails
/etc/MCQPlatform.conf/The etc directory is the canonical location for configurations.
$HOME/.MCQPlatform/Configurations can be located in the user's home directory.
./configs/The config folder in the root directory where the application is located.
Environment variablesFinally, the configurations will be loaded from environment variables and override configuration files

Configuration File

The expected file name is CassandraConfig.yaml. All the configuration items below are required.

NameEnvironment Variable KeyTypeDescription
AuthenticationCASSANDRA_AUTHENTICATIONParent key for authentication information.
↳ username.USERNAMEstringUsername for Cassandra session login.
↳ password.PASSWORDstringPassword for Cassandra session login.
KeyspaceCASSANDRA_KEYSPACEParent key for Keyspace configuration.
↳ name.NAMEstringKeyspace name.
↳ replication_class.REPLICATION_CLASSstringData replication strategy.
↳ replication_factor.REPLICATION_FACTORintData replication factor.
ConnectionCASSANDRA_CONNECTIONParent key for connection configuration.
↳ consistency.CONSISTENCYstringKeyspace name.
↳ cluster_ip.CLUSTER_IPstring arrayAn array of cluster IPs to bootstrap the connection. May optionally contain the port numbers.
↳ proto_version.PROTO_VERSIONintConnection protocol version.
↳ timeout.TIMEOUTintConnection timeout in seconds.
↳ max_connection_attempts.MAX_CONNECTION_ATTEMPTSintThe maximum number of initial connection attempts to Cassandra before failing.

:warning: Consistency :warning:

It is highly advised that the consistency level be set to Quorum. Quorum provides a good balance between read and write performance thereby providing an appropriate balance between consistency and availability. Setting the level to All can negatively impact read and write performance.

A balance between consistency and availability is vital to mitigate data inconsistencies with user account credentials.

Example Configuration File

authentication:
  username: admin
  password: root
keyspace:
  name: mcq_platform
  replication_class: SimpleStrategy
  replication_factor: 3
connection:
  consistency: quorum
  cluster_ip: [127.0.0.1]
  proto_version: 4
  timeout: 10
  max_connection_attempts: 5

Example Environment Variables

export CASSANDRA_AUTHENTICATION.USERNAME=admin
export CASSANDRA_AUTHENTICATION.PASSWORD=root

Design Documentation

The technology selection case study and table schema design documentation can be found here.

# Functions

CreateQuizQuery will create a quiz record in the quizzes table.
CreateResponseQuery will insert a response record into the responses table.
CreateUserQuery will insert a user record into the users table.
DeleteQuizQuery will mark a quiz record as deleted in the quizzes table.
DeleteUserQuery will mark a user record as deleted in the users table.
GetQuizzedUUIDMapping returns a map containing a Quiz title to UUID mapping.
GetTestQuizzes is a map of test quiz data.
GetTestResponses is a map of test response data.
GetTestUsers will generate a number of dummy users for testing.
HealthcheckQuery will run a query on the cluster to check if it responds.
NewCassandra will create a new Cassandra configuration by loading it.
NewError will generate a new Cassandra error.
PublishQuizQuery will mark a quiz record as published in the quizzes table.
ReadQuizQuery will read a quiz record from the quizzes table.
ReadResponseQuery will read a response record from the responses table.
ReadResponseStatisticsPageQuery will read response records pages from the responses table corresponding to a Quiz ID.
ReadResponseStatisticsQuery will read all response records from the responses table corresponding to a Quiz ID.
ReadUserQuery will read a user record from the users table.
UpdateQuizQuery will update a quiz record in the quizzes table.

# Structs

Error is the internal Cassandra error that uses the builder pattern to assign error codes.

# Interfaces

Cassandra is the interface through which the cluster can be accessed.