• Stars
    star
    358
  • Rank 118,855 (Top 3 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go bindings for libdqlite

go-dqlite CI tests Coverage Status Go Report Card GoDoc

This repository provides the go-dqlite Go package, containing bindings for the dqlite C library and a pure-Go client for the dqlite wire protocol.

Usage

The best way to understand how to use the go-dqlite package is probably by looking at the source code of the demo program and use it as example.

In general your application will use code such as:

dir := "/path/to/data/directory"
address := "1.2.3.4:666" // Unique node address
cluster := []string{...} // Optional list of existing nodes, when starting a new node
app, err := app.New(dir, app.WithAddress(address), app.WithCluster(cluster))
if err != nil {
        // ...
}

db, err := app.Open(context.Background(), "my-database")
if err != nil {
        // ...
}

// db is a *sql.DB object
if _, err := db.Exec("CREATE TABLE my_table (n INT)"); err != nil
        // ...
}

Build

In order to use the go-dqlite package in your application, you'll need to have the dqlite C library installed on your system, along with its dependencies.

By default, go-dqlite's client module supports storing a cache of the cluster's state in a SQLite database, locally on each cluster member. (This is not to be confused with any SQLite databases that are managed by dqlite.) In order to do this, it imports https://github.com/mattn/go-sqlite3, and so you can use the libsqlite3 build tag to control whether go-sqlite3 links to a system libsqlite3 or builds its own. You can also disable support for SQLite node stores entirely with the nosqlite3 build tag (unique to go-dqlite). If you pass this tag, your application will not link directly to libsqlite3 (but it will still link it indirectly via libdqlite, unless you've dropped the sqlite3.c amalgamation into the dqlite build).

Documentation

The documentation for this package can be found on pkg.go.dev.

Demo

To see dqlite in action, either install the Debian package from the PPA:

sudo add-apt-repository -y ppa:dqlite/dev
sudo apt install dqlite-tools libdqlite-dev

or build the dqlite C library and its dependencies from source, as described here, and then run:

go install -tags libsqlite3 ./cmd/dqlite-demo

from the top-level directory of this repository.

This builds a demo dqlite application, which exposes a simple key/value store over an HTTP API.

Once the dqlite-demo binary is installed (normally under ~/go/bin or /usr/bin/), start three nodes of the demo application:

dqlite-demo --api 127.0.0.1:8001 --db 127.0.0.1:9001 &
dqlite-demo --api 127.0.0.1:8002 --db 127.0.0.1:9002 --join 127.0.0.1:9001 &
dqlite-demo --api 127.0.0.1:8003 --db 127.0.0.1:9003 --join 127.0.0.1:9001 &

The --api flag tells the demo program where to expose its HTTP API.

The --db flag tells the demo program to use the given address for internal database replication.

The --join flag is optional and should be used only for additional nodes after the first one. It informs them about the existing cluster, so they can automatically join it.

Now we can start using the cluster. Let's insert a key pair:

curl -X PUT -d my-value http://127.0.0.1:8001/my-key

and then retrieve it from the database:

curl http://127.0.0.1:8001/my-key

Currently the first node is the leader. If we stop it and then try to query the key again curl will fail, but we can simply change the endpoint to another node and things will work since an automatic failover has taken place:

kill -TERM %1; curl http://127.0.0.1:8002/my-key

Shell

A basic SQLite-like dqlite shell is available in the dqlite-tools package or can be built with:

go install -tags libsqlite3 ./cmd/dqlite
Usage:
  dqlite -s <servers> <database> [command] [flags]

Example usage in the case of the dqlite-demo example listed above:

dqlite -s 127.0.0.1:9001 demo

dqlite> SELECT * FROM model;
my-key|my-value

The shell supports normal SQL queries plus the special .cluster and .leader commands to inspect the cluster members and the current leader.

More Repositories

1

microk8s

MicroK8s is a small, fast, single-package Kubernetes for datacenters and the edge.
Python
8,492
star
2

multipass

Multipass orchestrates virtual Ubuntu instances
C++
7,204
star
3

lxd

Powerful system container and virtual machine manager
Go
4,335
star
4

dqlite

Embeddable, replicated and fault tolerant SQL engine.
C
3,472
star
5

cloud-init

Official upstream for the cloud-init: cloud instance initialization
Python
2,963
star
6

snapd

The snapd and snap tools enable systems to work with .snap files.
Go
1,894
star
7

snapcraft

Package, distribute, and update any app for Linux and IoT.
Python
1,178
star
8

raft

C implementation of the Raft consensus protocol
C
852
star
9

lightdm

Display Manager
C
825
star
10

vanilla-framework

From community websites to web applications, this CSS framework will help you achieve a consistent look and feel.
HTML
723
star
11

netplan

Declarative network configuration for various backends
Python
671
star
12

ubuntu-desktop-installer

Ubuntu Desktop Installer
Dart
537
star
13

subiquity

Ubuntu Server Installer, and backend for Ubuntu Desktop Installer
Python
481
star
14

maas

Official MAAS repository mirror (may be out of date). Development happens in Launchpad (https://git.launchpad.net/maas/).
Python
350
star
15

microcloud

Automated private cloud based on LXD, Ceph and OVN
Go
267
star
16

chisel

Go
263
star
17

lxd-ui

Easy and accessible container and virtual machine management. A browser interface for LXD
TypeScript
260
star
18

pylxd

Python module for LXD
Python
251
star
19

operator

Pure Python framework for writing Juju charms
Python
245
star
20

microceph

MicroCeph is snap-deployed Ceph with built-in clustering
Go
211
star
21

ubuntu.com

The official website for the Ubuntu operating system
HTML
189
star
22

packer-maas

Packer templates to create MAAS deployable images
Python
172
star
23

pebble

Take control of your internal daemons!
Go
139
star
24

snapcraft.io

The official website's repository for the Snap store
JavaScript
129
star
25

prometheus-openstack-exporter

OpenStack exporter for the prometheus monitoring system
Python
115
star
26

firmware-updater

An experimental firmware updater UI based on fwupd
Dart
109
star
27

ubuntu-core-desktop

Makefile
102
star
28

ubuntu-image

Official tool to build Ubuntu Images.
Go
100
star
29

bundle-kubeflow

Charmed Kubeflow
Python
98
star
30

cloud-utils

This package provides a useful set of utilities for interacting with a cloud.
Shell
91
star
31

dbus.dart

Native Dart client library to use DBus.
Dart
90
star
32

react-components

A set of components based on Vanilla Framework
TypeScript
88
star
33

sec-cvescan

Analyzes an Ubuntu system and checks for unpatched vulnerabilities.
Python
87
star
34

ubuntu-image-legacy

Legacy Python-based Ubuntu image building scripts. Please see Canonical/ubuntu-image instead. Report bugs at Launchpad.
Python
86
star
35

lxd-demo-server

The LXD demo server
JavaScript
75
star
36

Ubuntu-Sans-Mono-fonts

Python
71
star
37

tdx

Intel confidential computing - TDX
Python
69
star
38

open-documentation-academy

Learn open-source software documentation skills with Canonical
Shell
69
star
39

microk8s-community-addons

The add-ons shipped with MicroK8s
Python
67
star
40

charmcraft

Collaborate, build and publish charmed operators for Kubernetes, Linux and Windows.
Python
66
star
41

steam-snap

Steam as a snap
Python
66
star
42

ubuntu-desktop-provision

Ubuntu Desktop Provision
Dart
64
star
43

matter-pi-gpio-commander

Matter Raspberry Pi GPIO Commander - Turn your Pi into a Matter lighting device!
C++
63
star
44

python-libmaas

Unofficial python client library for MAAS
Python
62
star
45

terraform-provider-maas

Terraform MAAS provider
Go
60
star
46

design-vanilla-framework

Design components for Vanilla Framework.
60
star
47

autoinstall-desktop

Python
59
star
48

curtin

Official mirror of curtin project. Please direct merge proposals to https://code.launchpad.net/curtin
Python
58
star
49

Ubuntu-Sans-fonts

Python
56
star
50

etrace

Utility for tracing execution of apps
Go
55
star
51

multipass-blueprints

Blueprint definitions for [`multipass launch`](https://multipass.run)
54
star
52

ubuntu-pro-client

Ubuntu Pro Client for offerings from Canonical
Python
52
star
53

bluez.dart

Dart
51
star
54

jhack

Chock-full of Juju hackery.
Python
51
star
55

ubuntu-flutter-plugins

A collection of Flutter plugins and packages for Ubuntu applications.
Dart
48
star
56

landscape-client

The Landscape Client is the agent which communicates with the Landscape service.
Python
47
star
57

wizard_router

A classic linear wizard router for Flutter
Dart
47
star
58

desktop_notifications.dart

Native Dart client library to send Linux desktop notifications.
Dart
44
star
59

maas-ansible-playbook

An Ansible playbook for installing and configuring MAAS
Jinja
44
star
60

microk8s-core-addons

Core MicroK8s addons
Python
43
star
61

k8s-snap

Canonical Kubernetes is an opinionated and CNCF conformant Kubernetes operated by Snaps and Charms, which come together to bring simplified operations and an enhanced security posture on any infrastructure.
Go
42
star
62

nrpe_exporter

Prometheus NRPE exporter. This exporter exposes metrics on commands sent to a running NRPE daemon.
Go
42
star
63

candid

Identity Manager Service
Go
39
star
64

ubuntu-drivers-common

Python
38
star
65

workshops

Workshops
Dart
34
star
66

k8s-dqlite

Dqlite for Kubernetes
Go
34
star
67

rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
Python
34
star
68

chisel-releases

34
star
69

pi-gadget

Universal pi (pi2,pi3,pi4,cm3,cm4 and future) gadget snap for Ubuntu Core and classic systems.
Makefile
33
star
70

maas-ui

The UI for MAAS (metal-as-a-service)
TypeScript
32
star
71

ubuntu-cooker

Ubuntu WSL UWP Builder
PowerShell
31
star
72

pc-gadget

The gadget snap for Personal Computers using 64bit Intel or AMD processors
31
star
73

kubeflow-examples

Charmed Kubeflow examples
Jupyter Notebook
31
star
74

snapd.dart

Native Dart client to access snapd
Dart
31
star
75

hotsos

Software analysis toolkit. Define checks in high-level language and leverage library to perform analysis of common Cloud applications.
Python
31
star
76

autoinstall-generator

Utility to convert Debian Installer preseed to Subiquity answers
Python
31
star
77

checkbox

Checkbox
Python
30
star
78

nm.dart

Native Dart client library to access NetworkManager on Linux.
Dart
29
star
79

landscape-scripts

A collection of scripts to make Landscape more powerful
Shell
29
star
80

microovn

Snap based deployment of OVN
Go
26
star
81

colcon-in-container

Colcon extension to build a colcon workspace in a container
Python
25
star
82

sync-issues-github-jira

Automation to sync issues from Github (using Github actions) to Jira (via Jira webhooks)
25
star
83

models

Reference Models
Python
24
star
84

core-base

The main repository for ubuntu-core base snaps. It contains snaps from core22+.
Shell
24
star
85

charms.reactive

Framework for developing charms and relations using the reactive pattern
Python
22
star
86

probert

Prober tool - Hardware discovery library used in Subiquity
Python
22
star
87

apport

Apport intercepts Program crashes, collects debugging information about the crash and the operating system environment, and sends it to bug trackers in a standardized form. It also offers the user to report a bug about a package, with again collecting as much information about it as possible.
Python
22
star
88

go-tpm2

Native go library for interacting with TPM 2.0 devices
Go
22
star
89

iot-agent

IoT Device Management Agent
Go
21
star
90

prometheus-k8s-operator

This charmed operator automates the operational procedures of running Prometheus, an open-source metrics backend.
Python
21
star
91

dotrun

Python
21
star
92

microcluster

dqlite cluster management using go-dqlite
Go
21
star
93

maas-commissioning-scripts

A repository of example MAAS commissioning scripts
Shell
20
star
94

setup-lxd

A GitHub Action to install & configure LXD on a runner.
20
star
95

desktop-design

HTML
19
star
96

gomaasclient

Go MAAS client
Go
19
star
97

microk8s-addons-repo-template

Template repository for MIcroK8s addons
Python
19
star
98

imagecraft

Customize and build bootable Ubuntu images.
Python
18
star
99

pycloudlib

Python library to launch, interact and, snapshot cloud instances
Python
18
star
100

serial-vault

Go
18
star