{"id":21948113,"url":"https://github.com/evolution-gaming/cassandra-sync","last_synced_at":"2025-04-23T00:12:38.284Z","repository":{"id":36037119,"uuid":"157565379","full_name":"evolution-gaming/cassandra-sync","owner":"evolution-gaming","description":"Synchronization mechanism via locks stored in cassandra","archived":false,"fork":false,"pushed_at":"2025-04-14T08:11:56.000Z","size":124,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-23T00:12:30.876Z","etag":null,"topics":["cassandra","lock","mutex","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evolution-gaming.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-14T14:59:54.000Z","updated_at":"2025-04-14T08:10:00.000Z","dependencies_parsed_at":"2023-01-16T12:11:09.534Z","dependency_job_id":"853e99e0-d83c-4f11-9edb-9dbfb6ed5560","html_url":"https://github.com/evolution-gaming/cassandra-sync","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Fcassandra-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Fcassandra-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Fcassandra-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evolution-gaming%2Fcassandra-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evolution-gaming","download_url":"https://codeload.github.com/evolution-gaming/cassandra-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250343956,"owners_count":21415041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","lock","mutex","scala"],"created_at":"2024-11-29T05:12:02.064Z","updated_at":"2025-04-23T00:12:38.257Z","avatar_url":"https://github.com/evolution-gaming.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cassandra-sync\n[![Build Status](https://github.com/evolution-gaming/cassandra-sync/workflows/CI/badge.svg)](https://github.com/evolution-gaming/cassandra-sync/actions?query=workflow%3ACI)\n[![Coverage Status](https://coveralls.io/repos/evolution-gaming/cassandra-sync/badge.svg)](https://coveralls.io/r/evolution-gaming/cassandra-sync)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a804ed95dc044adb83f56411d7bacffc)](https://app.codacy.com/gh/evolution-gaming/cassandra-sync/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Version](https://img.shields.io/badge/version-click-blue)](https://evolution.jfrog.io/artifactory/api/search/latestVersion?g=com.evolutiongaming\u0026a=cassandra-sync_2.13\u0026repos=public)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellowgreen.svg)](https://opensource.org/licenses/MIT)\n\nThis tiny library provides mechanism of `synchronization` via locks stored in Cassandra table.\nThis `synchronization` is especially useful for preventing concurrent schema changes.\nSad that concurrent schema changes [is not supported](https://issues.apache.org/jira/browse/CASSANDRA-10699) by Cassandra on it's own.\n\n## Concept \n\nBasically this is a mutex implementation via records stored in cassandra.\nWe insert record in order to acquire the lock and remove record when done.\nWe also provide expiry duration per lock in case we failed to remove record.\nThere is nice [statement](https://stackoverflow.com/a/34558/301517) which ideally describes the concept.\n\n## Usage\n\n```scala\ndef example(session: CassandraSession[IO]) = {\n  for {\n    cassandraSync \u003c- CassandraSync.of(session, keyspace = \"app\")\n    result        \u003c- cassandraSync(\"id\", expiry = 3.seconds, timeout = 10.seconds) {\n      // put your code here \n      // the lock in cassandra per id will ensure that your code runs strictly sequentially\n    }\n  } yield result\n}\n```\n\n## Schema \u0026 queries\n\nSo you still need to create table to store locks there and better don't let app to do that, especially concurrently from different nodes.\nAt [Evolution Gaming](https://www.evolutiongaming.com) this table is created along with keyspace creation by ops department.\n\n```cql\nCREATE TABLE IF NOT EXISTS keyspace.locks(\n  id TEXT PRIMARY KEY,\n  expiry_ms BIGINT,\n  timestamp TIMESTAMP,\n  metadata TEXT);\n\n-- Acquire lock\nINSERT INTO keyspace.locks (id, expiry_ms, timestamp, metadata) VALUES (?, ?, ?, ?)\n  IF NOT EXISTS USING TTL ?;\n\n-- Release lock\n-- This DELETE should also be a LWT op as mixing LWT and normal ops is prohibited\nDELETE FROM keyspace.locks WHERE id = ? IF EXISTS;\n```\n\n## Setup\n\n```scala\naddSbtPlugin(\"com.evolution\" % \"sbt-artifactory-plugin\" % \"0.0.2\")\n\nlibraryDependencies += \"com.evolutiongaming\" %% \"cassandra-sync\" % latestVersion\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolution-gaming%2Fcassandra-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevolution-gaming%2Fcassandra-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevolution-gaming%2Fcassandra-sync/lists"}