ScalarDB Documentation
repository·master·Indexed 20 days ago
https://github.com/scalar-labs/scalardbA universal HTAP engine that enables ACID transactions and real-time analytics across multiple diverse databases. It features a Consensus Commit protocol for transactional consistency and a data loader CLI for importing and exporting data in CSV, JSON, and JSONL formats. Available for Java projects via Maven Central (e.g., version 3.19.0).
What's inside ScalarDB
- ScalarDB is a universal HTAP (Hybrid Transactional/Analytical Processing) engine. It is designed to provide ACID transactions and real-time analytics across diverse databases, reducing the complexity of managing multiple database systems simultaneously.
Overview of the Consensus Commit protocol
masterThe Consensus Commit protocol is used to ensure transactional consistency. Using this protocol requires a schema change to maintain metadata (
txId,old data,record state) and a dedicated coordinator table.Protocol Workflow
- Initialization: A write set $W$ and a coordinator $C$ are initialized.
- Prepare Phase:
- Create a new transaction ID (UUID).
- Mark every write in $W$ with the
txIdand set state toprepared. - Perform a Compare-And-Swap (CAS) on every
preparedwrite to store the old value. - If all CAS operations succeed, the transaction is
prepared. If any fail, abort and rollback.
- Commit Phase:
- CAS the transaction ID to the coordinator table.
- If this succeeds, the transaction is
committed(and the coordinator iscommitted). If it fails, rollback.
- Finalization: Update all writes in $W$ to
committed. This step can be performed lazily.
Failure Handling
- Client failure before Prepare (Step 3): Clear the transaction from memory.
- Client failure after Prepare (Step 3) but before Commit (Step 5): The coordinator has no status. A subsequent transaction will detect
preparedrecords without a coordinator status, trigger an abort, and roll back the previous transaction. - Client failure after Commit (Step 5): The next transaction will perform a 'rollforward' by committing the records on behalf of the failed transaction.
Quickstart guide for ScalarDB
masterTo begin using ScalarDB, follow the path relevant to your deployment model:
- ScalarDB Core: For basic application setup using Java.
- ScalarDB Cluster: For enterprise customers requiring cluster-based functionality via the Java API.
- Sample Applications: To see running instances of various sample applications, refer to the official ScalarDB sample list.
- Configuration: Consult the specific configuration guides for either ScalarDB Core or ScalarDB Cluster to tune your environment.
Install ScalarDB via Gradle or Maven
masterScalarDB is available on Maven Central. You can add it to your Java project using either Gradle or Maven dependency management.
Gradle Add the following to your
dependenciesblock:Maven Add the following to your
pom.xml:Note: Ensure you use the version compatible with your environment (e.g.,
3.19.0).dependencies { implementation 'com.scalar-labs:scalardb:3.19.0' }<dependency> <groupId>com.scalar-labs</groupId> <artifactId>scalardb</artifactId> <version>3.19.0</version> </dependency>How to run the TLC Model Checker for Consensus Commit
masterTo verify the Consensus Commit protocol using the TLC Model Checker, follow these steps for either the protocol specification (
CCSpec) or the implementation (CC).Running CCSpec (Protocol Specification)
- Open the spec file (
CCSpec.tla) and select TLC Model Checker -> New Model. - Behavior Spec: Select
Temporal formulaand enterSpec. - Model: Enter
R <- r1, r2, r3. SelectSet of model valuesandSymmetry set(this treats $r1, r2, r3$ as interchangeable to speed up checking). - Deadlock: Ensure
Deadlockis not selected. - Invariants: Enter
TypeOK. - Properties: Enter
Spec. - Execute: Click the green arrow to run. Monitor
States FoundandDistinct Statesto verify progress.
Running CC (Implementation Specification)
- Open the spec file (
CC.tla) and select TLC Model Checker -> New Model. - Behavior Spec: Select
Temporal formulaand enterSpec. - Model: Enter
R <- r1, r2, r3. SelectSet of model valuesandSymmetry set. - Deadlock: Ensure
Deadlockis not selected. - Invariants: Enter
TypeOK,CCS!TypeOK, andCCS!Consistent. - Properties: Enter
SpecandCCS!Spec. - Execute: Click the green arrow to run.
- Open the spec file (
Understand ScalarDB Import Modes (Storage vs. Transaction)
masterThe behavior of the import command changes based on the
ScalarDbModeselected:- STORAGE Mode: Maps to
TransactionMode.SINGLE_CRUD. This is typically used for high-throughput, non-transactional writes directly to the storage layer. - TRANSACTION Mode: Maps to
TransactionMode.CONSENSUS_COMMIT. This mode uses ScalarDB's distributed transaction capabilities to ensure atomicity and consistency. When using this mode, the CLI validates that the providedTransactionFactoryconfiguration supports starting and aborting transactions.
- STORAGE Mode: Maps to
Reference: `export` command options and flags
masterThe following options are available for the
exportcommand. Note that several options are deprecated in favor of newer versions; do not use both an old option and its replacement in the same command.Core Configuration
configFilePath: Path to the ScalarDB properties configuration file. If not provided, it defaults toDEFAULT_CONFIG_FILE_NAMEin the current directory.namespace: The ScalarDB namespace of the table.table: The name of the table to export.outputFormat: The desired file format. Supported values:CSV,JSON,JSONL.outputDirectory: The directory where the exported file will be saved. If not specified, it defaults to the current working directory.outputFileName: The name of the exported file. If not specified, a filename is generated using the patternexport.{namespace}.{table}.{timestamp}.{format}.
Scan and Filter Options
partitionKeyValue: A list of column-key-value pairs to define a specific partition key for the export.scanStartKeyValue: The starting key for the scan.scanEndKeyValue: The ending key for the scan.scanStartInclusive: Whether the scan should include thescanStartKeyValue.scanEndInclusive: Whether the scan should include thescanEndKeyValue.projectionColumns: A list of specific columns to include in the export.limit: The maximum number of rows to export.
Formatting and Performance
dataChunkSize: The size of data chunks used during export (must be a positive value).maxThreads: The maximum number of threads to use for the export. Defaults to the number of available processors.delimiter: The delimiter used forCSVformat.excludeHeaderRow: Whether to exclude the header row inCSVexports.prettyPrintJson: Whether to use pretty-printing forJSONexports.sortOrders: The sort orders to apply to the exported data.
# Example of how options might be structured in a CLI call export --namespace my_ns --table my_table --output-format CSV --config-file-path /path/to/scalar.properties --output-directory ./exportsDeprecated import options in ScalarDB data loader
masterAs of release 3.17.0, several options are deprecated and will be removed in release 4.0.0. If you are using these, you should migrate to the new flags immediately to ensure future compatibility.
- Use
--max-threadsinstead of--threads. - Use
--enable-log-successinstead of--log-success.
- Use
Deprecated export options and migration guidance
masterSeveral options in the export command are deprecated as of release 3.17.0 and will be removed in release 4.0.0. Use the following replacements:
Deprecated Option Replacement / Guidance --threadsUse --max-threadsinstead.--start-exclusiveUse --start-inclusive(note the inverted logic).--end-exclusiveUse --end-inclusive(note the inverted logic).--include-metadata,-mUse the configuration property scalar.db.consensus_commit.include_metadata.enabledto control transaction metadata inclusion.Reference: Cosmos DB schema operation modes
masterThe schema loader supports three primary modes for managing tables. These are mutually exclusive within the command execution logic.
--delete-all, -D Delete tables --repair-all Repair tables: repairs the table metadata of existing tables and repairs stored procedure attached to each table --alter, -A Alter tables: adds new columns and creates/deletes secondary indexes for existing tables by comparing provided schema to existing schemaReference: Cassandra command options
masterThe following options are available for the
--cassandracommand in thescalardb-schema-loaderCLI.Options: -h, --host Cassandra host IP (required) -P, --port Cassandra Port -u, --user Cassandra user (required) -p, --password Cassandra password (required) -n, --network-strategy Cassandra network strategy (SimpleStrategy or NetworkTopologyStrategy) -c, --compaction-strategy Cassandra compaction strategy (LCS, STCS or TWCS) -R, --replication-factor Cassandra replication factorReference: JdbcCommand options
masterThe following options are available when using the
--jdbccommand in thescalardb-schema-loaderCLI.-j, --jdbc-url JDBC URL (required) -u, --user JDBC user (required) -p, --password JDBC password (required)