@@ -44,7 +44,7 @@ pub use object_storage::{ObjectStorage, ObjectStorageProvider};
44
44
pub use s3:: { S3Config , S3 } ;
45
45
pub use store_metadata:: StorageMetadata ;
46
46
47
- use self :: store_metadata:: { put_staging_metadata, startup_check , EnvChange } ;
47
+ use self :: store_metadata:: { put_staging_metadata, EnvChange } ;
48
48
49
49
/// local sync interval to move data.records to /tmp dir of that stream.
50
50
/// 60 sec is a reasonable value.
@@ -124,7 +124,15 @@ impl ObjectStoreFormat {
124
124
}
125
125
126
126
pub async fn resolve_parseable_metadata ( ) -> Result < ( ) , ObjectStorageError > {
127
- let check = startup_check ( ) . await ?;
127
+ let staging_metadata = store_metadata:: get_staging_metadata ( ) ?;
128
+ let storage = CONFIG . storage ( ) . get_object_store ( ) ;
129
+ let remote_metadata = storage. get_metadata ( ) . await ?;
130
+
131
+ let check = store_metadata:: check_metadata_conflict (
132
+ staging_metadata. as_ref ( ) ,
133
+ remote_metadata. as_ref ( ) ,
134
+ ) ;
135
+
128
136
const MISMATCH : & str = "Could not start the server because metadata file found in staging directory does not match one in the storage" ;
129
137
let err: Option < & str > = match check {
130
138
EnvChange :: None => None ,
@@ -134,11 +142,15 @@ pub async fn resolve_parseable_metadata() -> Result<(), ObjectStorageError> {
134
142
Some ( "Could not start the server because metadata not found in storage" )
135
143
}
136
144
EnvChange :: NewStaging => {
137
- Some ( "Could not start the server becuase metadata not found in staging" )
145
+ put_staging_metadata ( remote_metadata. as_ref ( ) . expect ( "remote metadata exists" ) ) ?;
146
+
147
+ // allow new staging directories
148
+ return Ok ( ( ) ) ;
138
149
}
139
150
EnvChange :: CreateBoth => {
140
- create_staging_metadata ( ) ?;
141
- create_remote_metadata ( ) . await ?;
151
+ let metadata = StorageMetadata :: new ( ) ;
152
+ create_remote_metadata ( & metadata) . await ?;
153
+ create_staging_metadata ( & metadata) ?;
142
154
None
143
155
}
144
156
} ;
@@ -156,15 +168,14 @@ pub async fn resolve_parseable_metadata() -> Result<(), ObjectStorageError> {
156
168
}
157
169
}
158
170
159
- async fn create_remote_metadata ( ) -> Result < ( ) , ObjectStorageError > {
171
+ async fn create_remote_metadata ( metadata : & StorageMetadata ) -> Result < ( ) , ObjectStorageError > {
160
172
let client = CONFIG . storage ( ) . get_object_store ( ) ;
161
- client. put_metadata ( & StorageMetadata :: new ( ) ) . await
173
+ client. put_metadata ( metadata ) . await
162
174
}
163
175
164
- fn create_staging_metadata ( ) -> std:: io:: Result < ( ) > {
176
+ fn create_staging_metadata ( metadata : & StorageMetadata ) -> std:: io:: Result < ( ) > {
165
177
create_dir_all ( CONFIG . staging_dir ( ) ) ?;
166
- let metadata = StorageMetadata :: new ( ) ;
167
- put_staging_metadata ( & metadata)
178
+ put_staging_metadata ( metadata)
168
179
}
169
180
170
181
lazy_static ! {
0 commit comments