Skip to content

Commit 77a7241

Browse files
committed
fix bug if user id is not provided and query caching is enabled
Request hung up if the user_id was not provided in the header, of the query request and query caching was enabled.
1 parent fd6422d commit 77a7241

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

server/src/handlers/airplane.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl FlightService for AirServiceImpl {
242242
.await
243243
.map_err(|err| Status::internal(err.to_string()))?;
244244

245-
put_results_in_cache(
245+
if let Err(err) = put_results_in_cache(
246246
cache_results,
247247
user_id,
248248
query_cache_manager,
@@ -252,7 +252,9 @@ impl FlightService for AirServiceImpl {
252252
query.end.to_rfc3339(),
253253
ticket.query,
254254
)
255-
.await;
255+
.await {
256+
log::error!("{}", err);
257+
};
256258

257259
/*
258260
* INFO: No returning the schema with the data.

server/src/handlers/http/query.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<impl Respon
131131
let time = Instant::now();
132132
let (records, fields) = query.execute(table_name.clone()).await?;
133133
// deal with cache saving
134-
put_results_in_cache(
134+
if let Err(err) = put_results_in_cache(
135135
cache_results,
136136
user_id,
137137
query_cache_manager,
@@ -141,7 +141,9 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<impl Respon
141141
query.end.to_rfc3339(),
142142
query_request.query,
143143
)
144-
.await;
144+
.await {
145+
log::error!("{}", err);
146+
};
145147

146148
let response = QueryResponse {
147149
records,
@@ -185,16 +187,18 @@ pub async fn put_results_in_cache(
185187
start: String,
186188
end: String,
187189
query: String,
188-
) {
190+
) -> Result<(), QueryError> {
189191
match (cache_results, query_cache_manager) {
190192
(Some(_), None) => {
191193
log::warn!(
192194
"Instructed to cache query results but Query Caching is not Enabled in Server"
193195
);
196+
197+
Ok(())
194198
}
195199
// do cache
196200
(Some(_), Some(query_cache_manager)) => {
197-
let user_id = user_id.expect("User Id was provided");
201+
let user_id = user_id.ok_or(CacheError::Other("User Id not provided"))?;
198202

199203
if let Err(err) = query_cache_manager
200204
.create_parquet_cache(stream, records, user_id, start, end, query)
@@ -209,8 +213,12 @@ pub async fn put_results_in_cache(
209213
log::error!("Error Clearing Unwanted files from cache dir");
210214
}
211215
}
216+
// fallthrough
217+
Ok(())
218+
}
219+
(None, _) => {
220+
Ok(())
212221
}
213-
(None, _) => {}
214222
}
215223
}
216224

server/src/localcache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,6 @@ pub enum CacheError {
263263
MetadataError(#[from] MetadataError),
264264
#[error("Error: Cache File Does Not Exist")]
265265
DoesNotExist,
266+
#[error("Error: {0}")]
267+
Other(&'static str),
266268
}

server/src/querycache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl QueryCacheManager {
151151
&format!(
152152
"{}.{}.parquet",
153153
hostname_unchecked(),
154-
Utc::now().to_rfc3339()
154+
Utc::now().timestamp().to_string()
155155
),
156156
])
157157
}

0 commit comments

Comments
 (0)