@@ -22,6 +22,7 @@ use futures::StreamExt;
2222use http:: Uri ;
2323use object_store:: aws:: AmazonS3Builder ;
2424use object_store:: limit:: LimitStore ;
25+ use serde:: { Deserialize , Serialize } ;
2526use std:: fs;
2627use std:: iter:: Iterator ;
2728use std:: sync:: Arc ;
@@ -46,6 +47,20 @@ const S3_URL_ENV_VAR: &str = "P_S3_URL";
4647// max concurrent request allowed for datafusion object store
4748const MAX_OBJECT_STORE_REQUESTS : usize = 1000 ;
4849
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+
4964lazy_static:: lazy_static! {
5065 #[ derive( Debug ) ]
5166 pub static ref S3_CONFIG : Arc <S3Config > = Arc :: new( S3Config :: parse( ) ) ;
@@ -195,14 +210,29 @@ impl S3 {
195210 Ok ( ( ) )
196211 }
197212
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
199217 let _resp = self
200218 . client
201219 . put_object ( )
202220 . bucket ( & S3_CONFIG . s3_bucket_name )
203221 . key ( format ! ( "{}/.schema" , stream_name) )
204222 . send ( )
205223 . 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 ?;
206236 // Prefix created on S3, now create the directory in
207237 // the local storage as well
208238 let _res = fs:: create_dir_all ( CONFIG . parseable . local_stream_data_path ( stream_name) ) ;
@@ -357,7 +387,9 @@ impl ObjectStorage for S3 {
357387 }
358388
359389 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 ?;
361393
362394 Ok ( ( ) )
363395 }
0 commit comments