@@ -22,6 +22,7 @@ use futures::StreamExt;
22
22
use http:: Uri ;
23
23
use object_store:: aws:: AmazonS3Builder ;
24
24
use object_store:: limit:: LimitStore ;
25
+ use serde:: { Deserialize , Serialize } ;
25
26
use std:: fs;
26
27
use std:: iter:: Iterator ;
27
28
use std:: sync:: Arc ;
@@ -46,6 +47,20 @@ const S3_URL_ENV_VAR: &str = "P_S3_URL";
46
47
// max concurrent request allowed for datafusion object store
47
48
const MAX_OBJECT_STORE_REQUESTS : usize = 1000 ;
48
49
50
+ #[ derive( Default , Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
51
+ pub struct ObjectStoreFormat {
52
+ #[ serde( rename = "objectstore-format" ) ]
53
+ pub version : String ,
54
+ }
55
+
56
+ impl ObjectStoreFormat {
57
+ pub fn new ( ) -> Self {
58
+ Self {
59
+ version : "v1" . to_string ( ) ,
60
+ }
61
+ }
62
+ }
63
+
49
64
lazy_static:: lazy_static! {
50
65
#[ derive( Debug ) ]
51
66
pub static ref S3_CONFIG : Arc <S3Config > = Arc :: new( S3Config :: parse( ) ) ;
@@ -195,14 +210,29 @@ impl S3 {
195
210
Ok ( ( ) )
196
211
}
197
212
198
- async fn _create_stream ( & self , stream_name : & str ) -> Result < ( ) , AwsSdkError > {
213
+ async fn _create_stream ( & self , stream_name : & str , format : Vec < u8 > ) -> Result < ( ) , AwsSdkError > {
214
+ // create ./schema empty file in the stream-name prefix
215
+ // this indicates that the stream has been created
216
+ // but doesn't have any content yet
199
217
let _resp = self
200
218
. client
201
219
. put_object ( )
202
220
. bucket ( & S3_CONFIG . s3_bucket_name )
203
221
. key ( format ! ( "{}/.schema" , stream_name) )
204
222
. send ( )
205
223
. await ?;
224
+ // create .parseable.json file in the stream-name prefix.
225
+ // This indicates the format version for this stream.
226
+ // This is helpful in case we may change the backend format
227
+ // in the future
228
+ let _resp = self
229
+ . client
230
+ . put_object ( )
231
+ . bucket ( & S3_CONFIG . s3_bucket_name )
232
+ . key ( format ! ( "{}/.parseable.json" , stream_name) )
233
+ . body ( format. into ( ) )
234
+ . send ( )
235
+ . await ?;
206
236
// Prefix created on S3, now create the directory in
207
237
// the local storage as well
208
238
let _res = fs:: create_dir_all ( CONFIG . parseable . local_stream_data_path ( stream_name) ) ;
@@ -357,7 +387,9 @@ impl ObjectStorage for S3 {
357
387
}
358
388
359
389
async fn create_stream ( & self , stream_name : & str ) -> Result < ( ) , ObjectStorageError > {
360
- self . _create_stream ( stream_name) . await ?;
390
+ let format = ObjectStoreFormat :: new ( ) ;
391
+ let body = serde_json:: to_vec ( & format) ?;
392
+ self . _create_stream ( stream_name, body) . await ?;
361
393
362
394
Ok ( ( ) )
363
395
}
0 commit comments