GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - benthor/clustersql: A clustering SQL Driver in Go

This repository was archived by the owner on Aug 9, 2022. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
cluster.go
cluster.go
 
 
cluster_test.go
cluster_test.go
 
 
config.toml
config.toml
 
 

Repository files navigation

[Archived repo] clustersql Build Status GoDoc

This project is archived, I myself am not using it any more.

Go Clustering SQL Driver - A clustering, implementation-agnostic "meta"-driver for any backend implementing "database/sql/driver".

It does (latency-based) load-balancing and error-recovery over all registered nodes.

It is assumed that database-state is transparently replicated over all nodes by some database-side clustering solution. This driver ONLY handles the client side of such a cluster.

This package simply multiplexes the driver.Open() function of sql/driver to every attached node. The function is called on each node, returning the first successfully opened connection. (Any connections opening subsequently will be closed.) If opening does not succeed for any node, the latest error gets returned. Any other errors will be masked by default. However, any given latest error for any attached node will remain exposed through expvar, as well as some basic counters and timestamps.

To make use of this kind of clustering, use this package with any backend driver implementing "database/sql/driver" like so:

import "database/sql"
import "github.com/go-sql-driver/mysql"
import "github.com/benthor/clustersql"

There is currently no way around instanciating the backend driver explicitly

mysqlDriver := mysql.MySQLDriver{}

You can perform backend-driver specific settings such as

err := mysql.SetLogger(mylogger)

Create a new clustering driver with the backend driver

clusterDriver := clustersql.NewDriver(mysqlDriver)

Add nodes, including driver-specific name format, in this case Go-MySQL DSN. Here, we add three nodes belonging to a galera cluster

clusterDriver.AddNode("galera1", "user:password@tcp(dbhost1:3306)/db")
clusterDriver.AddNode("galera2", "user:password@tcp(dbhost2:3306)/db")
clusterDriver.AddNode("galera3", "user:password@tcp(dbhost3:3306)/db")

Make the clusterDriver available to the go sql interface under an arbitrary name

sql.Register("myCluster", clusterDriver)

Open the registered clusterDriver with an arbitrary DSN string (not used)

db, err := sql.Open("myCluster", "whatever")

Continue to use the sql interface as documented at http://golang.org/pkg/database/sql/

Before using this in production, you should configure your cluster details in config.toml and run

go test -v .

Note however, that non-failure of the above is no guarantee for a correctly set-up cluster.

About

A clustering SQL Driver in Go

Resources

Readme
BSD-2-Clause license
Activity

Stars

20 stars

Watchers

1 watching

Forks

5 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.