File tree 4 files changed +47
-1
lines changed
4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ pub struct DatabaseConfig {
18
18
pub heartbeat_url : Option < Url > ,
19
19
#[ serde( default ) ]
20
20
pub bottomless_db_id : Option < String > ,
21
+ #[ serde( default ) ]
22
+ pub allow_attach : bool ,
21
23
}
22
24
23
25
const fn default_max_size ( ) -> u64 {
@@ -33,6 +35,7 @@ impl Default for DatabaseConfig {
33
35
max_db_pages : default_max_size ( ) ,
34
36
heartbeat_url : None ,
35
37
bottomless_db_id : None ,
38
+ allow_attach : Default :: default ( ) ,
36
39
}
37
40
}
38
41
}
Original file line number Diff line number Diff line change @@ -693,7 +693,7 @@ impl<W: Wal> Connection<W> {
693
693
StmtKind :: Read | StmtKind :: TxnBegin | StmtKind :: Other => config. block_reads ,
694
694
StmtKind :: Write => config. block_reads || config. block_writes ,
695
695
StmtKind :: TxnEnd | StmtKind :: Release | StmtKind :: Savepoint => false ,
696
- StmtKind :: Attach | StmtKind :: Detach => false ,
696
+ StmtKind :: Attach | StmtKind :: Detach => !config . allow_attach ,
697
697
} ;
698
698
if blocked {
699
699
return Err ( Error :: Blocked ( config. block_reason . clone ( ) ) ) ;
Original file line number Diff line number Diff line change @@ -177,6 +177,7 @@ async fn handle_get_config<M: MakeNamespace, C: Connector>(
177
177
block_reason : config. block_reason . clone ( ) ,
178
178
max_db_size : Some ( max_db_size) ,
179
179
heartbeat_url : config. heartbeat_url . clone ( ) . map ( |u| u. into ( ) ) ,
180
+ allow_attach : config. allow_attach ,
180
181
} ;
181
182
182
183
Ok ( Json ( resp) )
@@ -219,6 +220,8 @@ struct HttpDatabaseConfig {
219
220
max_db_size : Option < bytesize:: ByteSize > ,
220
221
#[ serde( default ) ]
221
222
heartbeat_url : Option < String > ,
223
+ #[ serde( default ) ]
224
+ allow_attach : bool ,
222
225
}
223
226
224
227
async fn handle_post_config < M : MakeNamespace , C > (
@@ -234,6 +237,7 @@ async fn handle_post_config<M: MakeNamespace, C>(
234
237
config. block_reads = req. block_reads ;
235
238
config. block_writes = req. block_writes ;
236
239
config. block_reason = req. block_reason ;
240
+ config. allow_attach = req. allow_attach ;
237
241
if let Some ( size) = req. max_db_size {
238
242
config. max_db_pages = size. as_u64 ( ) / LIBSQL_PAGE_SIZE ;
239
243
}
Original file line number Diff line number Diff line change @@ -81,6 +81,45 @@ fn meta_store() {
81
81
foo_conn. execute ( "select 1" , ( ) ) . await . unwrap ( ) ;
82
82
}
83
83
84
+ // STEP 4: try attaching a database
85
+ {
86
+ let foo = Database :: open_remote_with_connector (
87
+ "http://foo.primary:8080" ,
88
+ "" ,
89
+ TurmoilConnector ,
90
+ ) ?;
91
+ let foo_conn = foo. connect ( ) ?;
92
+
93
+ foo_conn. execute ( "attach foo as foo" , ( ) ) . await . unwrap_err ( ) ;
94
+ }
95
+
96
+ // STEP 5: update config to allow attaching databases
97
+ client
98
+ . post (
99
+ "http://primary:9090/v1/namespaces/foo/config" ,
100
+ json ! ( {
101
+ "block_reads" : false ,
102
+ "block_writes" : false ,
103
+ "allow_attach" : true ,
104
+ } ) ,
105
+ )
106
+ . await ?;
107
+
108
+ {
109
+ let foo = Database :: open_remote_with_connector (
110
+ "http://foo.primary:8080" ,
111
+ "" ,
112
+ TurmoilConnector ,
113
+ ) ?;
114
+ let foo_conn = foo. connect ( ) ?;
115
+
116
+ foo_conn. execute ( "attach foo as foo" , ( ) ) . await . unwrap ( ) ;
117
+ foo_conn
118
+ . execute ( "select * from foo.sqlite_master" , ( ) )
119
+ . await
120
+ . unwrap ( ) ;
121
+ }
122
+
84
123
Ok ( ( ) )
85
124
} ) ;
86
125
You can’t perform that action at this time.
0 commit comments