slatedb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Cargo.toml +9 -0
- data/LICENSE +176 -0
- data/README.md +404 -0
- data/ext/slatedb/Cargo.toml +22 -0
- data/ext/slatedb/extconf.rb +6 -0
- data/ext/slatedb/src/admin.rs +273 -0
- data/ext/slatedb/src/database.rs +457 -0
- data/ext/slatedb/src/errors.rs +144 -0
- data/ext/slatedb/src/iterator.rs +118 -0
- data/ext/slatedb/src/lib.rs +50 -0
- data/ext/slatedb/src/reader.rs +233 -0
- data/ext/slatedb/src/runtime.rs +78 -0
- data/ext/slatedb/src/snapshot.rs +197 -0
- data/ext/slatedb/src/transaction.rs +298 -0
- data/ext/slatedb/src/utils.rs +18 -0
- data/ext/slatedb/src/write_batch.rs +98 -0
- data/lib/slatedb/admin.rb +122 -0
- data/lib/slatedb/database.rb +310 -0
- data/lib/slatedb/iterator.rb +31 -0
- data/lib/slatedb/reader.rb +105 -0
- data/lib/slatedb/snapshot.rb +54 -0
- data/lib/slatedb/transaction.rb +78 -0
- data/lib/slatedb/version.rb +5 -0
- data/lib/slatedb/write_batch.rb +38 -0
- data/lib/slatedb.rb +20 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 06b42247a14342b9550a9a10641900546ea79fd52001f4b98798e028f7f03cd4
|
|
4
|
+
data.tar.gz: f83cd6b19a0f4dea849e628068c8d3e4af338b0efe320870cc8ddd5e3d55fb8c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6946b78b9f03073aee23c604443fa38fbe728c2298cba21b621d632c2d1e93d909fb900571eb976d638ac93c4e1efdfa372eb5fefd90d3e3db250f02cf3343b4
|
|
7
|
+
data.tar.gz: f161ed22a27ef14b899ec557bfdb4dadf39cc928f35e771a6e5025cc5840210109f05ea080349b7d57dc27b278c816c8e2bd842d1854937800ee772139c68a0f
|
data/Cargo.toml
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
data/README.md
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
# SlateDB Ruby
|
|
2
|
+
|
|
3
|
+
Ruby bindings for [SlateDB](https://slatedb.io), a cloud-native embedded key-value store built on object storage.
|
|
4
|
+
|
|
5
|
+
[](https://buildkite.com/catkins-test/slatedb-rb)
|
|
6
|
+
|
|
7
|
+
## Thread Safety
|
|
8
|
+
|
|
9
|
+
**SlateDB is fully thread-safe and optimized for concurrent access.**
|
|
10
|
+
|
|
11
|
+
- The `Database` class can be safely shared across multiple Ruby threads
|
|
12
|
+
- All operations (get, put, delete, scan, transactions) are thread-safe
|
|
13
|
+
- The Ruby bindings release the Global VM Lock (GVL) during I/O operations, allowing other Ruby threads to run concurrently
|
|
14
|
+
- Perfect for use with multi-threaded Ruby applications like Puma, Sidekiq, and concurrent test suites
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
db = SlateDb::Database.open("/tmp/mydb")
|
|
18
|
+
|
|
19
|
+
# Safe to use from multiple threads
|
|
20
|
+
threads = 10.times.map do |i|
|
|
21
|
+
Thread.new do
|
|
22
|
+
db.put("key-#{i}", "value-#{i}")
|
|
23
|
+
db.get("key-#{i}")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
threads.each(&:join)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Implementation details:**
|
|
31
|
+
- The underlying SlateDB library uses `Arc` (atomic reference counting) and `RwLock` for internal state management
|
|
32
|
+
- I/O operations release the Ruby GVL using `rb_thread_call_without_gvl`, preventing blocking other threads
|
|
33
|
+
- A shared Tokio multi-threaded runtime handles all async operations efficiently
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
Add this line to your application's Gemfile:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
gem 'slatedb'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
And then execute:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
bundle install
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or install it yourself as:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
gem install slatedb
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### Basic Operations
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
require 'slatedb'
|
|
61
|
+
|
|
62
|
+
# Open a database with in-memory storage (for testing)
|
|
63
|
+
db = SlateDb::Database.open("/tmp/mydb")
|
|
64
|
+
|
|
65
|
+
# Store a value
|
|
66
|
+
db.put("hello", "world")
|
|
67
|
+
|
|
68
|
+
# Retrieve a value
|
|
69
|
+
value = db.get("hello") # => "world"
|
|
70
|
+
|
|
71
|
+
# Delete a value
|
|
72
|
+
db.delete("hello")
|
|
73
|
+
|
|
74
|
+
# Close the database
|
|
75
|
+
db.close
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Block Form (Recommended)
|
|
79
|
+
|
|
80
|
+
The block form automatically closes the database when the block exits:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
SlateDb::Database.open("/tmp/mydb") do |db|
|
|
84
|
+
db.put("key", "value")
|
|
85
|
+
db.get("key") # => "value"
|
|
86
|
+
end # automatically closed
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Persistent Storage
|
|
90
|
+
|
|
91
|
+
For persistent storage, provide an object store URL:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
# Local filesystem
|
|
95
|
+
SlateDb::Database.open("/tmp/mydb", url: "file:///tmp/mydb") do |db|
|
|
96
|
+
db.put("key", "value")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# S3 (requires AWS credentials)
|
|
100
|
+
SlateDb::Database.open("mydb", url: "s3://mybucket/path") do |db|
|
|
101
|
+
db.put("key", "value")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Azure Blob Storage
|
|
105
|
+
SlateDb::Database.open("mydb", url: "az://container/path") do |db|
|
|
106
|
+
db.put("key", "value")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Google Cloud Storage
|
|
110
|
+
SlateDb::Database.open("mydb", url: "gs://bucket/path") do |db|
|
|
111
|
+
db.put("key", "value")
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Cloud Storage Credentials
|
|
116
|
+
|
|
117
|
+
SlateDB uses the [object_store](https://docs.rs/object_store) crate, which automatically discovers credentials from standard environment variables and configuration files:
|
|
118
|
+
|
|
119
|
+
**AWS S3:**
|
|
120
|
+
- Environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_REGION`
|
|
121
|
+
- Credential files: `~/.aws/credentials`, `~/.aws/config`
|
|
122
|
+
- IAM roles (when running on EC2/ECS/EKS)
|
|
123
|
+
- Web identity tokens (for IRSA on EKS)
|
|
124
|
+
|
|
125
|
+
**Azure Blob Storage:**
|
|
126
|
+
- Environment variables: `AZURE_STORAGE_ACCOUNT_NAME`, `AZURE_STORAGE_ACCOUNT_KEY`, `AZURE_STORAGE_SAS_TOKEN`
|
|
127
|
+
- Azure CLI credentials: `az login`
|
|
128
|
+
- Managed Identity (when running on Azure)
|
|
129
|
+
|
|
130
|
+
**Google Cloud Storage:**
|
|
131
|
+
- Environment variables: `GOOGLE_SERVICE_ACCOUNT`, `GOOGLE_SERVICE_ACCOUNT_PATH`, `GOOGLE_SERVICE_ACCOUNT_KEY`
|
|
132
|
+
- Application Default Credentials: `gcloud auth application-default login`
|
|
133
|
+
- Service account key file: `GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json`
|
|
134
|
+
|
|
135
|
+
Example with explicit AWS credentials:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
# Set credentials via environment
|
|
139
|
+
ENV['AWS_ACCESS_KEY_ID'] = 'your-access-key'
|
|
140
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = 'your-secret-key'
|
|
141
|
+
ENV['AWS_REGION'] = 'us-east-1'
|
|
142
|
+
|
|
143
|
+
SlateDb::Database.open("mydb", url: "s3://mybucket/path") do |db|
|
|
144
|
+
db.put("key", "value")
|
|
145
|
+
end
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Options
|
|
149
|
+
|
|
150
|
+
#### Put Options
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
# Set TTL (time-to-live) in milliseconds
|
|
154
|
+
db.put("key", "value", ttl: 60_000) # expires in 60 seconds
|
|
155
|
+
|
|
156
|
+
# Don't wait for durability
|
|
157
|
+
db.put("key", "value", await_durable: false)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Get Options
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
# Filter by durability level
|
|
164
|
+
db.get("key", durability_filter: "memory")
|
|
165
|
+
db.get("key", durability_filter: "remote")
|
|
166
|
+
|
|
167
|
+
# Include uncommitted data
|
|
168
|
+
db.get("key", dirty: true)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Delete Options
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
# Don't wait for durability
|
|
175
|
+
db.delete("key", await_durable: false)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Scanning
|
|
179
|
+
|
|
180
|
+
Iterate over key ranges using the `scan` method:
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
# Scan all keys from "a" onwards
|
|
184
|
+
db.scan("a").each do |key, value|
|
|
185
|
+
puts "#{key}: #{value}"
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Scan a specific range [start, end)
|
|
189
|
+
db.scan("a", "z").each do |key, value|
|
|
190
|
+
puts "#{key}: #{value}"
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Use Enumerable methods
|
|
194
|
+
keys = db.scan("user:").map { |k, v| k }
|
|
195
|
+
users = db.scan("user:").select { |k, v| v.include?("active") }
|
|
196
|
+
|
|
197
|
+
# Convert to array
|
|
198
|
+
all_entries = db.scan("").to_a
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Write Batches
|
|
202
|
+
|
|
203
|
+
Perform multiple writes atomically:
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
# Create a batch manually
|
|
207
|
+
batch = SlateDb::WriteBatch.new
|
|
208
|
+
batch.put("key1", "value1")
|
|
209
|
+
batch.put("key2", "value2", ttl: 60_000)
|
|
210
|
+
batch.delete("old_key")
|
|
211
|
+
db.write(batch)
|
|
212
|
+
|
|
213
|
+
# Or use the block helper
|
|
214
|
+
db.batch do |b|
|
|
215
|
+
b.put("key1", "value1")
|
|
216
|
+
b.put("key2", "value2")
|
|
217
|
+
b.delete("old_key")
|
|
218
|
+
end
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Transactions
|
|
222
|
+
|
|
223
|
+
ACID transactions with snapshot or serializable isolation:
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
# Block form (recommended) - auto-commits on success, rolls back on exception
|
|
227
|
+
db.transaction do |txn|
|
|
228
|
+
balance = txn.get("balance").to_i
|
|
229
|
+
txn.put("balance", (balance - 100).to_s)
|
|
230
|
+
txn.put("withdrawal", "100")
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# With serializable isolation for strict consistency
|
|
234
|
+
db.transaction(isolation: :serializable) do |txn|
|
|
235
|
+
counter = txn.get("counter").to_i
|
|
236
|
+
txn.put("counter", (counter + 1).to_s)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Manual transaction management
|
|
240
|
+
txn = db.begin_transaction(isolation: :snapshot)
|
|
241
|
+
txn.put("key", "value")
|
|
242
|
+
txn.commit # or txn.rollback
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Transaction operations:
|
|
246
|
+
|
|
247
|
+
```ruby
|
|
248
|
+
db.transaction do |txn|
|
|
249
|
+
# Read
|
|
250
|
+
value = txn.get("key")
|
|
251
|
+
|
|
252
|
+
# Write
|
|
253
|
+
txn.put("key", "value")
|
|
254
|
+
txn.put("expiring", "data", ttl: 30_000)
|
|
255
|
+
|
|
256
|
+
# Delete
|
|
257
|
+
txn.delete("old_key")
|
|
258
|
+
|
|
259
|
+
# Scan
|
|
260
|
+
txn.scan("prefix:").each do |k, v|
|
|
261
|
+
puts "#{k}: #{v}"
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Snapshots
|
|
267
|
+
|
|
268
|
+
Point-in-time consistent reads:
|
|
269
|
+
|
|
270
|
+
```ruby
|
|
271
|
+
# Block form (recommended)
|
|
272
|
+
db.snapshot do |snap|
|
|
273
|
+
# All reads see the same consistent state
|
|
274
|
+
value1 = snap.get("key1")
|
|
275
|
+
value2 = snap.get("key2")
|
|
276
|
+
|
|
277
|
+
snap.scan("prefix:").each do |k, v|
|
|
278
|
+
puts "#{k}: #{v}"
|
|
279
|
+
end
|
|
280
|
+
end # automatically closed
|
|
281
|
+
|
|
282
|
+
# Manual management
|
|
283
|
+
snap = db.snapshot
|
|
284
|
+
value = snap.get("key")
|
|
285
|
+
snap.close
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Reader (Read-Only Access)
|
|
289
|
+
|
|
290
|
+
Open a database in read-only mode, useful for replicas:
|
|
291
|
+
|
|
292
|
+
```ruby
|
|
293
|
+
# Basic read-only access
|
|
294
|
+
SlateDb::Reader.open("/tmp/mydb", url: "s3://bucket/path") do |reader|
|
|
295
|
+
value = reader.get("key")
|
|
296
|
+
|
|
297
|
+
reader.scan("prefix:").each do |k, v|
|
|
298
|
+
puts "#{k}: #{v}"
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Open at a specific checkpoint
|
|
303
|
+
SlateDb::Reader.open("/tmp/mydb",
|
|
304
|
+
url: "s3://bucket/path",
|
|
305
|
+
checkpoint_id: "uuid-here") do |reader|
|
|
306
|
+
reader.get("key")
|
|
307
|
+
end
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Admin Operations
|
|
311
|
+
|
|
312
|
+
Administrative operations for database management:
|
|
313
|
+
|
|
314
|
+
```ruby
|
|
315
|
+
admin = SlateDb::Admin.new("/tmp/mydb", url: "s3://bucket/path")
|
|
316
|
+
|
|
317
|
+
# Manifests
|
|
318
|
+
json = admin.read_manifest # Latest manifest as JSON
|
|
319
|
+
json = admin.read_manifest(123) # Specific manifest by ID
|
|
320
|
+
json = admin.list_manifests # List all manifests
|
|
321
|
+
json = admin.list_manifests(start: 1, end_id: 10) # Range query
|
|
322
|
+
|
|
323
|
+
# Checkpoints
|
|
324
|
+
result = admin.create_checkpoint(name: "backup-2024")
|
|
325
|
+
# => { id: "uuid-string", manifest_id: 7 }
|
|
326
|
+
|
|
327
|
+
checkpoints = admin.list_checkpoints
|
|
328
|
+
checkpoints = admin.list_checkpoints(name: "backup") # Filter by name
|
|
329
|
+
|
|
330
|
+
admin.refresh_checkpoint("uuid", lifetime: 3600_000) # Extend lifetime
|
|
331
|
+
admin.delete_checkpoint("uuid")
|
|
332
|
+
|
|
333
|
+
# Garbage Collection
|
|
334
|
+
admin.run_gc # Run with default settings
|
|
335
|
+
admin.run_gc(min_age: 3600_000) # Set min age for all directories (1 hour)
|
|
336
|
+
admin.run_gc(manifest_min_age: 86400_000) # Custom age for manifest (1 day)
|
|
337
|
+
admin.run_gc(wal_min_age: 60_000) # Custom age for WAL (1 minute)
|
|
338
|
+
admin.run_gc(compacted_min_age: 60_000) # Custom age for compacted (1 minute)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Flushing
|
|
342
|
+
|
|
343
|
+
Ensure all writes are persisted:
|
|
344
|
+
|
|
345
|
+
```ruby
|
|
346
|
+
db.put("key", "value")
|
|
347
|
+
db.flush
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Error Handling
|
|
351
|
+
|
|
352
|
+
SlateDB defines several exception classes:
|
|
353
|
+
|
|
354
|
+
```ruby
|
|
355
|
+
begin
|
|
356
|
+
db.put("", "value") # empty key
|
|
357
|
+
rescue SlateDb::InvalidArgumentError => e
|
|
358
|
+
puts "Invalid argument: #{e.message}"
|
|
359
|
+
rescue SlateDb::TransactionError => e
|
|
360
|
+
puts "Transaction conflict: #{e.message}"
|
|
361
|
+
rescue SlateDb::Error => e
|
|
362
|
+
puts "SlateDB error: #{e.message}"
|
|
363
|
+
end
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Exception hierarchy:
|
|
367
|
+
|
|
368
|
+
- `SlateDb::Error` - Base class (inherits from `StandardError`)
|
|
369
|
+
- `SlateDb::TransactionError` - Transaction conflicts
|
|
370
|
+
- `SlateDb::ClosedError` - Database has been closed
|
|
371
|
+
- `SlateDb::UnavailableError` - Storage/network unavailable
|
|
372
|
+
- `SlateDb::InvalidArgumentError` - Invalid arguments
|
|
373
|
+
- `SlateDb::DataError` - Data corruption or format errors
|
|
374
|
+
- `SlateDb::InternalError` - Internal errors
|
|
375
|
+
|
|
376
|
+
## Requirements
|
|
377
|
+
|
|
378
|
+
- Ruby 3.1+
|
|
379
|
+
- Rust toolchain (for building from source)
|
|
380
|
+
|
|
381
|
+
## Development
|
|
382
|
+
|
|
383
|
+
After checking out the repo, run:
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
bundle install
|
|
387
|
+
bundle exec rake compile
|
|
388
|
+
bundle exec rake spec
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
To run specific tests:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
bundle exec rspec spec/database_spec.rb
|
|
395
|
+
bundle exec rspec spec/transaction_spec.rb
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Contributing
|
|
399
|
+
|
|
400
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/catkins/slatedb-rb.
|
|
401
|
+
|
|
402
|
+
## License
|
|
403
|
+
|
|
404
|
+
Apache-2.0
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "slatedb"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
publish = false
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
description = "Ruby bindings for SlateDB"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "slatedb"
|
|
11
|
+
crate-type = ["cdylib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
slatedb = "0.9"
|
|
15
|
+
magnus = { version = "0.8", features = ["rb-sys"] }
|
|
16
|
+
rb-sys = { version = "0.9", features = ["stable-api-compiled-fallback"] }
|
|
17
|
+
tokio = { version = "1", features = ["rt-multi-thread", "sync"] }
|
|
18
|
+
bytes = "1"
|
|
19
|
+
object_store = "0.12"
|
|
20
|
+
once_cell = "1"
|
|
21
|
+
log = "0.4"
|
|
22
|
+
uuid = "1"
|