frankgh commented on code in PR #91:
URL: https://github.com/apache/cassandra-sidecar/pull/91#discussion_r1564730006
##########
src/main/java/org/apache/cassandra/sidecar/routes/FileStreamHandler.java:
##########
@@ -74,40 +103,114 @@ protected String extractParamsOrThrow(RoutingContext
context)
return context.get(FILE_PATH_CONTEXT_KEY);
}
+ @Override
+ protected void processFailure(Throwable cause,
+ RoutingContext context,
+ String host,
+ SocketAddress remoteAddress,
+ String localFile)
+ {
+ IOException fileNotFoundException = ThrowableUtils.getCause(cause,
NoSuchFileException.class);
+
+ if (fileNotFoundException == null)
+ {
+ // FileNotFoundException comes from the stream method
+ fileNotFoundException = ThrowableUtils.getCause(cause,
FileNotFoundException.class);
+ }
+
+ if (fileNotFoundException != null)
+ {
+ logger.error("The requested file '{}' does not exist", localFile);
+ context.fail(wrapHttpException(NOT_FOUND, "The requested file does
not exist"));
+ return;
+ }
+
+ super.processFailure(cause, context, host, remoteAddress, localFile);
+ }
+
/**
- * Ensures that the file exists and is a non-empty regular file
+ * Retrieves the Future for the validation operation. If the cache was
initialized, it will retrieve the
+ * Future from the cache.
*
* @param fs The underlying filesystem
* @param localFile The path the file in the filesystem
- * @param exists Whether the file exists or not
* @return a succeeded future with the {@link FileProps}, or a failed
future if the file does not exist;
* is not a regular file; or if the file is empty
*/
- private Future<FileProps> ensureValidFile(FileSystem fs, String localFile,
Boolean exists)
+ protected Future<FileProps> ensureValidFile(FileSystem fs, String
localFile)
{
- if (!exists)
+ if (filePropsCache != null)
{
- logger.error("The requested file '{}' does not exist", localFile);
- return Future.failedFuture(wrapHttpException(NOT_FOUND, "The
requested file does not exist"));
+ FileProps fileProps = filePropsCache.getIfPresent(localFile);
+
+ if (fileProps != null)
+ {
+ return Future.succeededFuture(fileProps);
+ }
+
+ return ensureValidFileNonCached(fs).apply(localFile)
Review Comment:
Removed this cache
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]