sqlite_server2018_plus 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/sqlite_server2018_plus.rb +119 -0
- metadata +71 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6900438f7b755d08eedf31edf27cc0ee526c92f7512d7d1e6fcd8eabb5c36081
|
4
|
+
data.tar.gz: e0cc5c285f94952d175880b1836029c5841ea6eb5248837206c7e7ea291dfe4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e65ee264b49bd330702575717fa30c51b02514a9250c31c127c0cce309d08350d04029d678920ec2215c4136aa2cbce180a40d99eea187e8a0793557b3b35e2e
|
7
|
+
data.tar.gz: ea370c2daa39de8ecfcb564b22832e5482ce7ae336fc84903122b6d8c56ed449234dc8ecf21f70f7b218742af9b02921ca3b3962ea602b69ab93d5c231baefb1
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: sqlite_server2018_plus.rb
|
4
|
+
|
5
|
+
# description: Designed to provide fault tolerant access to a DRb SQLite server
|
6
|
+
# when 2 or more back-end nodes are running.
|
7
|
+
|
8
|
+
require 'drb'
|
9
|
+
require 'socket'
|
10
|
+
|
11
|
+
class SQLiteServer2018PlusException < Exception
|
12
|
+
end
|
13
|
+
|
14
|
+
class SQLiteServer2018
|
15
|
+
|
16
|
+
attr_accessor :nodes
|
17
|
+
|
18
|
+
def initialize(nodes, debug: debug)
|
19
|
+
|
20
|
+
@nodes, @debug = nodes, debug
|
21
|
+
|
22
|
+
|
23
|
+
if (nodes & Socket.ip_address_list.map(&:ip_address)).any? then
|
24
|
+
raise SQLiteServer2018PlusException,
|
25
|
+
'Cannot use host IP address in node list'
|
26
|
+
end
|
27
|
+
|
28
|
+
@failcount = 0
|
29
|
+
@db = fetch_server(nodes.first)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute(dbfile, *args, &blk)
|
34
|
+
|
35
|
+
puts 'inside SQLiteServer2018::execute args: ' + args.inspect if @debug
|
36
|
+
|
37
|
+
if block_given? then
|
38
|
+
a = db_op { @db.execute(dbfile, *args) }
|
39
|
+
a.each(&blk)
|
40
|
+
else
|
41
|
+
db_op { @db.execute dbfile, *args, &blk }
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def exists?(dbfile)
|
47
|
+
|
48
|
+
puts 'inside SQLiteServer2018::exists?' if @debug
|
49
|
+
db_op { @db.exists? dbfile }
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def load(dbfile)
|
54
|
+
|
55
|
+
puts 'inside SQLiteServer2018::load' if @debug
|
56
|
+
db_op { @db.load dbfile }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def query(*args, &blk)
|
61
|
+
|
62
|
+
puts 'inside SQLiteServer2018::query args: ' + args.inspect if @debug
|
63
|
+
db_op { @db.query *args, &blk }
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def db_op()
|
71
|
+
|
72
|
+
begin
|
73
|
+
r = yield()
|
74
|
+
@failcount = 0
|
75
|
+
r
|
76
|
+
rescue
|
77
|
+
puts 'warning: ' + ($!).inspect
|
78
|
+
|
79
|
+
if @debug then
|
80
|
+
puts '@nodes: ' + @nodes.inspect
|
81
|
+
puts '@failcount: ' + @failcount.inspect
|
82
|
+
end
|
83
|
+
|
84
|
+
@nodes.rotate!
|
85
|
+
@db = fetch_server(@nodes.first)
|
86
|
+
@failcount += 1
|
87
|
+
retry unless @failcount > @nodes.length
|
88
|
+
raise 'SQLiteServer2018Plus nodes exhausted'
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def fetch_server(host)
|
95
|
+
port = '57000'
|
96
|
+
DRbObject.new nil, "druby://#{host}:#{port}"
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class SQLiteServer2018Plus
|
102
|
+
|
103
|
+
|
104
|
+
def initialize(host: 'localhost', port: '57000', nodes: [], debug: false)
|
105
|
+
|
106
|
+
@host, @port, @nodes, @debug = host, port, nodes, debug
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def start()
|
111
|
+
|
112
|
+
DRb.start_service "druby://#{@host}:#{@port}",
|
113
|
+
SQLiteServer2018.new(@nodes, debug: @debug)
|
114
|
+
DRb.thread.join
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqlite_server2018_plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwODMxMTI0ODQ2WhcN
|
15
|
+
MTkwODMxMTI0ODQ2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC+iQhB
|
17
|
+
9U3O5NYFtISb/MQTonQ38h8X9b0pgOJunGDv4JahCD839BfV3GEg4aZh0fjl+nhf
|
18
|
+
nW5k3sRrJCuUkjk4pHbDDW0UuAFl2r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tWbut94fK6chN/yHZWok5r07UcdiEkYen7UKy2aUTUHDm7s2ZSAOEKAVJ8
|
34
|
+
0dVz12h8YVl/k52cLLQSHELjpfj745eFNw8OpOMI4fjKxddZRiKuTYPBIxrt1qjR
|
35
|
+
+dKNs1JqPjM4l+H0RuY7wuiq2vnC73wCJp9RbRu5V/LGpRr0LgL6ZnjtcFfsmX5O
|
36
|
+
V2nAiVKAs4Tra2rVUd8oAqsS
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
39
|
+
dependencies: []
|
40
|
+
description:
|
41
|
+
email: james@jamesrobertson.eu
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- lib/sqlite_server2018_plus.rb
|
47
|
+
homepage: https://github.com/jrobertson/sqlite_server2018_plus
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.7.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: sqlite_server2018_plus
|
71
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|